Relative Path Traversal
Summary
This is CWE-23, MITRE's name for the classic, textbook form of path traversal: relative path elements, . and .., are used to walk out of an intended directory and into somewhere else on the filesystem. It's the most common shape the broader path-traversal category takes, and the one most people picture when they hear the term: a file parameter that's meant to stay within one folder, but where enough ../ sequences let the request resolve to any file the running process can read. The distinction from other members of the same CWE family (the dir/filename variant, absolute path traversal, backslash variants) is purely about the exact character pattern, not a different vulnerability mechanism; they're all the same underlying bug expressed through slightly different payload shapes, cataloged separately mostly because some historical filtering logic treated them differently.
Top Affected Components / Targets
- File-download, file-preview, and static-asset-serving endpoints that accept a filename or path parameter
- Template or theme-loading parameters that resolve to a file on disk
- Log-viewing or file-management features in admin panels
Common Attack Vectors
- Submit a parameter value containing repeated
../sequences targeting a well-known file whose content is easy to recognize (/etc/passwdon Linux,win.inion Windows) and check whether that content appears in the response - Vary the number of
../repetitions, since the required depth depends on how deeply nested the application's base directory is, and an insufficient number of repetitions will simply fail to reach the target
Common Payloads
../../../etc/passwd../../../../../windows/win.ini- URL-encoded variants (
%2e%2e%2f) where a filter strips the literal../string but not its encoded form
Detection Strategy
For any parameter that plausibly maps to a file path, submit a range of ../ depths targeting a well-known system file and check the response for that file's recognizable content, not just a changed status code or response length. Where the plain-text payload is rejected, retry with URL-encoded and double-encoded variants, since filters that string-match the literal ../ sequence are a common, incomplete defense that a decoded equivalent bypasses cleanly.
Tip: Testing tools that run these checks in parallel across every discovered endpoint can cut the time required substantially compared to fully manual testing, as long as they confirm findings with more than one signal to keep the false-positive rate down.
False-Positive Notes
A different response for a traversal payload versus a normal request isn't enough on its own; confirmation requires the response to contain content genuinely consistent with the targeted system file, not just an error message that happens to differ from the baseline.
How to Test
Manual Testing Methodology
Here is a systematic approach to identifying Relative Path Traversal vulnerabilities in a target application.
Before testing, map all input vectors that could be affected. Identify parameters, headers, cookies, and request bodies that interact with the vulnerable component. A proxy such as Burp Suite or OWASP ZAP, paired with normal browsing of the target, is usually enough to build this list.
Send a legitimate request and record the normal response: status code, content length, response time, and any identifying tokens. This baseline matters because it's what you'll compare later responses against once payloads are involved.
Inject test payloads into each identified input vector one at a time. Start with benign detection payloads before escalating to anything that could actually trigger the vulnerability. For Relative Path Traversal specifically, submit ../ sequences of increasing depth (../etc/passwd, ../../etc/passwd, and so on) alongside URL-encoded (%2e%2e%2f), double-encoded, and null-byte variants against every file-path parameter, and try both forward- and back-slash separators since one is sometimes filtered while the other isn't.
Compare the response against your baseline, looking specifically for the actual contents of a known system file (/etc/passwd, win.ini) appearing in the response, or a distinct error message (a different exception type or path echoed back) between a valid relative path and a traversal attempt.
Once a potential vulnerability is detected, confirm it with at least a few independent test cases to rule out coincidence. Document the exact request and response as proof. For Relative Path Traversal, a confirmed finding typically means showing that attacker-controlled input changes the application's behavior in a way that matters for security, not just that a payload was reflected somewhere harmless.
Real-World Impact
Real-World Impact
Path traversal lets attackers read, and sometimes write, files outside the directory an application intended to expose, usually by slipping ../ sequences into a file path parameter. Successful exploitation can expose source code, configuration files containing database credentials and API keys, and system files like /etc/passwd. In write scenarios, it can lead directly to code execution through a planted web shell.
In containerized environments, path traversal can escape an application's own file namespace to read secrets, environment variables, and mounted volumes belonging to other services entirely. In cloud deployments, it can expose provider-specific metadata files too.
This bug class becomes especially dangerous when combined with file inclusion. Reading a file is an information disclosure on its own, but if that file gets executed, the finding becomes remote code execution.
Prevention & Remediation
Prevention and Secure Coding
Preventing Relative Path Traversal takes a defense-in-depth approach — no single control below is sufficient alone, but together they close off both the primary path and the most common bypasses.
Canonicalize and verify containment. Resolve the requested path to its canonical absolute form and check that it still falls inside an allowlisted base directory before touching the filesystem — check this after resolving symlinks and encoded sequences, not before.
Map to an internal ID, not a raw path. Where feasible, have user input select from a server-side allowlist or database record (an internal file ID) rather than being used as any part of a filesystem path directly.
Reject traversal sequences outright. Reject requests containing ../, .., URL-encoded variants (%2e%2e%2f), and null bytes rather than trying to strip them — stripping is a common source of filter-bypass bugs when done with a single non-recursive replace.
Least-privilege filesystem access. Run the file-serving process under an account with read access to only the directories it legitimately needs, so a traversal that gets past the application-layer check still hits an OS-level permission wall.
Disable directory listing and dangerous parsers. Serve static content through a web server configuration that has autoindexing disabled and doesn't execute uploaded files as scripts.