Weakness · High
CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
What it is
The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.
- Severity (our rating)
- High
- Likelihood of exploit
- High
- Introduced during
- Implementation
- Exploited in the wild
- 81 known exploited CVEs
In more detail
Many file operations are intended to take place within a restricted directory. By using special elements such as ".." and "/" separators, attackers can escape outside of the restricted location to access files or directories that are elsewhere on the system. One of the most common special elements is the "../" sequence, which in most modern operating systems is interpreted as the parent directory of the current location. This is referred to as relative path traversal. Path traversal also covers the use of absolute pathnames such as "/usr/local/bin" to access unexpected files. This is referred to as absolute path traversal.
What an attacker can do
- Execute Unauthorized Code or Commands (Integrity, Confidentiality, Availability)
- Modify Files or Directories (Integrity)
- Read Files or Directories (Confidentiality)
- DoS: Crash, Exit, or Restart (Availability)
How to prevent it
Implementation
- Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue." Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright. When validating filenames, use stringent allowlists that limit the character set to be used. If feasible, only allow a single "." character in the filename to avoid weaknesses such as CWE-23, and exclude directory separators such as "/" to avoid CWE-36. Use a list of allowable file extensions, which will help to avoid CWE-434. Do not rely exclusively on a filtering mechanism that removes potentially dangerous characters. This is equivalent to a denylist, which may be incomplete (CWE-184). For example, filtering "/" is insufficient protection if the filesystem also supports the use of "\" as a directory separator. Another possible error could occur when the filtering is applied in a way that still produces dangerous data (CWE-182). For example, if "../" sequences are removed from the ".../...//" string in a sequential fashion, two instances of "../" would be removed from the original string, but the remaining characters would still form the "../" string.
- Inputs should be decoded and canonicalized to the application's current internal representation before being validated (CWE-180). Make sure that the application does not decode the same input twice (CWE-174). Such errors could be used to bypass allowlist validation schemes by introducing dangerous inputs after they have been checked. Use a built-in path canonicalization function (such as realpath() in C) that produces the canonical version of the pathname, which effectively removes ".." sequences and symbolic links (CWE-23, CWE-59). This includes: realpath() in C getCanonicalPath() in Java GetFullPath() in ASP.NET realpath() or abs_path() in Perl realpath() in PHP
- Ensure that error messages only contain minimal details that are useful to the intended audience and no one else. The messages need to strike the balance between being too cryptic (which can confuse users) or being too detailed (which may reveal more than intended). The messages should not reveal the methods that were used to determine the error. Attackers can use detailed information to refine or optimize their original attack, thereby increasing their chances of success. If errors must be captured in some detail, record them in log messages, but consider what could occur if the log messages can be viewed by attackers. Highly sensitive information such as passwords should never be saved to log files. Avoid inconsistent messaging that might accidentally tip off an attacker about internal state, such as whether a user account exists or not. In the context of path traversal, error messages which disclose path information can help attackers craft the appropriate attack strings to move through the file system hierarchy.
Architecture and Design
- For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server.
- Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid.
- Run your code using the lowest privileges that are required to accomplish the necessary tasks. If possible, create isolated accounts with limited privileges that are only used for a single task. That way, a successful attack will not immediately give the attacker access to the rest of the software or its environment. For example, database applications rarely need to run as the database administrator, especially in day-to-day operations.
- When the set of acceptable objects, such as filenames or URLs, is limited or known, create a mapping from a set of fixed input values (such as numeric IDs) to the actual filenames or URLs, and reject all other inputs. For example, ID 1 could map to "inbox.txt" and ID 2 could map to "profile.txt". Features such as the ESAPI AccessReferenceMap provide this capability.
- Run the code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which files can be accessed in a particular directory or which commands can be executed by the software. OS-level examples include the Unix chroot jail, AppArmor, and SELinux. In general, managed code may provide some protection. For example, java.io.FilePermission in the Java SecurityManager allows the software to specify restrictions on file operations. This may not be a feasible solution, and it only limits the impact to the operating system; the rest of the application may still be subject to compromise. Be careful to avoid CWE-243 and other weaknesses related to jails.
- Store library, include, and utility files outside of the web document root, if possible. Otherwise, store them in a separate directory and use the web server's access control capabilities to prevent attackers from directly requesting them. One common practice is to define a fixed constant in each calling program, then check for the existence of the constant in the library/include file; if the constant does not exist, then the file was directly requested, and it can exit immediately. This significantly reduces the chance of an attacker being able to bypass any protection mechanisms that are in the base program but not in the include files. It will also reduce the attack surface.
Operation
- Use an application firewall that can detect attacks against this weakness. It can be beneficial in cases in which the code cannot be fixed (because it is controlled by a third party), as an emergency prevention measure while more comprehensive software assurance measures are applied, or to provide defense in depth.
- When using PHP, configure the application so that it does not use register_globals. During implementation, develop the application so that it does not rely on this feature, but be wary of implementing a register_globals emulation that is subject to weaknesses such as CWE-95, CWE-621, and similar issues.
While the code is being fixed, a WAF in blocking mode stops path traversal attempts at the edge.
How to find it
- Automated Static Analysis. Automated techniques can find areas where path traversal weaknesses exist. However, tuning or customization may be required to remove or de-prioritize path-traversal problems that are only exploitable by the product's administrator - or other privileged users - and thus potentially valid behavior or, at worst, a bug instead of a vulnerability.
- Manual Static Analysis. Manual white box techniques may be able to provide sufficient code coverage and reduction of false positives if all file access operations can be assessed within limited time constraints.
- Automated Static Analysis - Binary or Bytecode. According to SOAR, the following detection techniques may be useful: Highly cost effective: Bytecode Weakness Analysis - including disassembler + source code weakness analysis Cost effective for partial coverage: Binary Weakness Analysis - including disassembler + source code weakness analysis
- Manual Static Analysis - Binary or Bytecode. According to SOAR, the following detection techniques may be useful: Cost effective for partial coverage: Binary / Bytecode disassembler - then use manual analysis for vulnerabilities & anomalies
- Dynamic Analysis with Automated Results Interpretation. According to SOAR, the following detection techniques may be useful: Highly cost effective: Web Application Scanner Web Services Scanner Database Scanners
- Dynamic Analysis with Manual Results Interpretation. According to SOAR, the following detection techniques may be useful: Highly cost effective: Fuzz Tester Framework-based Fuzzer
- Manual Static Analysis - Source Code. According to SOAR, the following detection techniques may be useful: Highly cost effective: Manual Source Code Review (not inspections) Cost effective for partial coverage: Focused Manual Spotcheck - Focused manual analysis of source
- Automated Static Analysis - Source Code. According to SOAR, the following detection techniques may be useful: Highly cost effective: Source code Weakness Analyzer Context-configured Source Code Weakness Analyzer
- Architecture or Design Review. According to SOAR, the following detection techniques may be useful: Highly cost effective: Formal Methods / Correct-By-Construction Cost effective for partial coverage: Inspection (IEEE 1028 standard) (can apply to requirements, design, source code, etc.)
Exploited in the wild: 81 CVEs
Vulnerabilities caused by CWE-22 that attackers have used, from CISA's Known Exploited Vulnerabilities catalog, newest first.
- CVE-2021-3199ONLYOFFICE Docs Server Path Traversal Vulnerability · added October 8, 2026
- CVE-2026-104286Fortinet FortiMail Path Traversal Vulnerability · added October 1, 2026
- CVE-2026-93616Check Point Multiple Products Path Traversal Vulnerability · added September 22, 2026
- CVE-2026-66384JFrog Artifactory Improper Limitation of a Pathname to a Restricted Directory Vulnerability · added August 27, 2026
- CVE-2026-59310 ransomwareBroadcom VMware vCenter Path Traversal Vulnerability · added August 18, 2026
- CVE-2026-48282Adobe ColdFusion Path Traversal Vulnerability · added July 7, 2026
- CVE-2026-34909Ubiquiti UniFi OS Path Traversal Vulnerability · added June 23, 2026
- CVE-2026-20262Cisco Catalyst SD-WAN Manager Directory or Path Traversal Vulnerability · added June 15, 2026
- CVE-2024-1708 ransomwareConnectWise ScreenConnect Path Traversal Vulnerability · added April 28, 2026
- CVE-2024-57728 ransomwareSimpleHelp Path Traversal Vulnerability · added April 24, 2026
- CVE-2024-7399Samsung MagicINFO 9 Server Path Traversal Vulnerability · added April 24, 2026
- CVE-2025-2749Kentico Xperience Path Traversal Vulnerability · added April 20, 2026
- CVE-2025-8110Gogs Path Traversal Vulnerability · added January 12, 2026
- CVE-2025-6218RARLAB WinRAR Path Traversal Vulnerability · added December 9, 2025
- CVE-2021-43798Grafana Path Traversal Vulnerability · added October 9, 2025
- CVE-2019-5418Rails Ruby on Rails Path Traversal Vulnerability · added July 7, 2025
- CVE-2024-0769 D-Link DIR-859 Router Path Traversal Vulnerability · added June 25, 2025
- CVE-2025-4632Samsung MagicINFO 9 Server Path Traversal Vulnerability · added May 22, 2025
- CVE-2025-27920Srimax Output Messenger Directory Traversal Vulnerability · added May 19, 2025
- CVE-2023-38950ZKTeco BioTime Path Traversal Vulnerability · added May 19, 2025
- CVE-2025-34028Commvault Command Center Path Traversal Vulnerability · added May 2, 2025
- CVE-2017-12637SAP NetWeaver Directory Traversal Vulnerability · added March 19, 2025
- CVE-2024-4885Progress WhatsUp Gold Path Traversal Vulnerability · added March 3, 2025
- CVE-2024-57727 ransomwareSimpleHelp Path Traversal Vulnerability · added February 13, 2025
- CVE-2024-55550 ransomwareMitel MiCollab Path Traversal Vulnerability · added January 7, 2025
- CVE-2024-41713 ransomwareMitel MiCollab Path Traversal Vulnerability · added January 7, 2025
- CVE-2024-11667 ransomwareZyxel Multiple Firewalls Path Traversal Vulnerability · added December 3, 2024
- CVE-2021-26086Atlassian Jira Server and Data Center Path Traversal Vulnerability · added November 12, 2024
- CVE-2019-16278Nostromo nhttpd Directory Traversal Vulnerability · added November 7, 2024
- CVE-2024-8963Ivanti Cloud Services Appliance (CSA) Path Traversal Vulnerability · added September 19, 2024
- CVE-2024-7262Kingsoft WPS Office Path Traversal Vulnerability · added September 3, 2024
- CVE-2021-20124Draytek VigorConnect Path Traversal Vulnerability · added September 3, 2024
- CVE-2021-20123Draytek VigorConnect Path Traversal Vulnerability · added September 3, 2024
- CVE-2024-32113Apache OFBiz Path Traversal Vulnerability · added August 7, 2024
- CVE-2024-28995SolarWinds Serv-U Path Traversal Vulnerability · added July 17, 2024
- CVE-2023-47246 ransomwareSysAid Server Path Traversal Vulnerability · added November 13, 2023
- CVE-2023-32315Ignite Realtime Openfire Path Traversal Vulnerability · added August 24, 2023
- CVE-2023-35081Ivanti Endpoint Manager Mobile (EPMM) Path Traversal Vulnerability · added July 31, 2023
- CVE-2022-41328Fortinet FortiOS Path Traversal Vulnerability · added March 14, 2023
- CVE-2018-18809TIBCO JasperReports Library Directory Traversal Vulnerability · added December 29, 2022
- CVE-2018-5430TIBCO JasperReports Server Information Disclosure Vulnerability · added December 29, 2022
- CVE-2022-26500 ransomwareVeeam Backup & Replication Remote Code Execution Vulnerability · added December 13, 2022
- CVE-2022-41352 ransomwareSynacor Zimbra Collaboration Suite (ZCS) Arbitrary File Upload Vulnerability · added October 20, 2022
- CVE-2022-26352 ransomwaredotCMS Unrestricted Upload of File Vulnerability · added August 25, 2022
- CVE-2020-36193PEAR Archive_Tar Improper Link Resolution Vulnerability · added August 25, 2022
- CVE-2022-27925 ransomwareSynacor Zimbra Collaboration Suite (ZCS) Arbitrary File Upload Vulnerability · added August 11, 2022
- CVE-2022-30333 ransomwareRARLAB UnRAR Directory Traversal Vulnerability · added August 9, 2022
- CVE-2019-7195 ransomwareQNAP Photo Station Path Traversal Vulnerability · added June 8, 2022
- CVE-2019-7194 ransomwareQNAP Photo Station Path Traversal Vulnerability · added June 8, 2022
- CVE-2015-0016Microsoft Windows TS WebProxy Directory Traversal Vulnerability · added May 25, 2022
- CVE-2022-29464 ransomwareWSO2 Multiple Products Unrestrictive Upload of File Vulnerability · added April 25, 2022
- CVE-2014-0780InduSoft Web Studio NTWebServer Directory Traversal Vulnerability · added April 15, 2022
- CVE-2019-7483SonicWall SMA100 Directory Traversal Vulnerability · added March 28, 2022
- CVE-2020-1631Juniper Junos OS Path Traversal Vulnerability · added March 25, 2022
- CVE-2016-0752Ruby on Rails Directory Traversal Vulnerability · added March 25, 2022
- CVE-2015-4068Arcserve Unified Data Protection (UDP) Directory Traversal Vulnerability · added March 25, 2022
- CVE-2015-3035TP-Link Multiple Archer Devices Directory Traversal Vulnerability · added March 25, 2022
- CVE-2015-0666Cisco Prime Data Center Network Manager (DCNM) Directory Traversal Vulnerability · added March 25, 2022
- CVE-2014-0130Ruby on Rails Directory Traversal Vulnerability · added March 25, 2022
- CVE-2010-2861 ransomwareAdobe ColdFusion Directory Traversal Vulnerability · added March 25, 2022
- CVE-2020-14864Oracle Business Intelligence Enterprise Edition Path Transversal · added January 18, 2022
- CVE-2018-14847MikroTik Router OS Directory Traversal Vulnerability · added December 1, 2021
- CVE-2021-42013 ransomwareApache HTTP Server Path Traversal Vulnerability · added November 3, 2021
- CVE-2021-41773 ransomwareApache HTTP Server Path Traversal Vulnerability · added November 3, 2021
- CVE-2021-40444 ransomwareMicrosoft MSHTML Remote Code Execution Vulnerability · added November 3, 2021
- CVE-2021-36741Trend Micro Multiple Products Improper Input Validation Vulnerability · added November 3, 2021
- CVE-2021-20090Arcadyan Buffalo Firmware Path Traversal Vulnerability · added November 3, 2021
- CVE-2021-20023 ransomwareSonicWall Email Security Path Traversal Vulnerability · added November 3, 2021
- CVE-2020-11738WordPress Snap Creek Duplicator Plugin File Download Vulnerability · added November 3, 2021
- CVE-2020-11652SaltStack Salt Path Traversal Vulnerability · added November 3, 2021
- CVE-2020-5902 ransomwareF5 BIG-IP Traffic Management User Interface (TMUI) Remote Code Execution Vulnerability · added November 3, 2021
- CVE-2020-4430IBM Data Risk Manager Directory Traversal Vulnerability · added November 3, 2021
- CVE-2019-20085TVT NVMS-1000 Directory Traversal Vulnerability · added November 3, 2021
- CVE-2019-19781 ransomwareCitrix ADC, Gateway, and SD-WAN WANOP Appliance Code Execution Vulnerability · added November 3, 2021
- CVE-2019-18187Trend Micro OfficeScan Directory Traversal Vulnerability · added November 3, 2021
- CVE-2019-11510 ransomwareIvanti Pulse Connect Secure Arbitrary File Read Vulnerability · added November 3, 2021
- CVE-2019-3398Atlassian Confluence Server and Data Center Path Traversal Vulnerability · added November 3, 2021
- CVE-2019-3396 ransomwareAtlassian Confluence Server and Data Center Server-Side Template Injection Vulnerability · added November 3, 2021
- CVE-2018-13379 ransomwareFortinet FortiOS SSL VPN Path Traversal Vulnerability · added November 3, 2021
- CVE-2018-2380 ransomwareSAP Customer Relationship Management (CRM) Path Traversal Vulnerability · added November 3, 2021
- CVE-2016-3976SAP NetWeaver Directory Traversal Vulnerability · added November 3, 2021
The Dome
Block it at the edge while you fix it
The Dome's WAF runs the OWASP Core Rule Set in blocking mode and stops path traversal attempts before they reach your application.
See the DomeT Academy
Stop writing it in the first place
Learn to build software and systems without weaknesses like this one, with practice on real hosts in your browser, every objective checked on the machine.
Start freeSource: MITRE Common Weakness Enumeration, CWE version 4.19.1. CWE is a trademark of The MITRE Corporation.