Directory traversal – also called path traversal – is a web vulnerability that lets an attacker access arbitrary files on a server file system outside the web application’s intended directory, such as the document root or an approved upload folder.Â
Directory (path) traversal is possible when an application uses untrusted input to build or select a path on the server file system. Successful attacks can expose sensitive data like configuration files, credentials, logs, or source code, and the information gained is often used to enable follow-on attacks. While traversal is frequently associated with reading files, in some scenarios it can, when combined with other weaknesses or unsafe server behavior, contribute to more severe outcomes, up to and including remote code execution.
Directory traversal is a boundary-breaking bug. The application intends to allow access only to a specific directory (for example, a folder of user-uploaded images), but a crafted path causes the application to “escape” that directory and read from elsewhere on the filesystem. The usual starting point for traversal is the web root directory.
Websites and applications run on a web server that serves content from a location called the web document root or web root folder. The document root usually contains subdirectories for each hosted application.
Common default paths:
/var/www/C:\inetpub\wwwrootDevelopers often write application code that accesses files under the web root or within an application subdirectory. A common example is storing user-uploaded images under a directory such as /var/www/my_app/images/ and then allowing other users to request an image by filename.
A typical traversal vulnerability follows a simple pattern:
../ or ..\.Attackers can try to reach unintended files in two ways:
../ on Linux/UNIX or ..\ on Windows to “climb” up the directory tree./etc/passwd on Linux/UNIX or C:\Windows\win.ini on Windows), assuming the application accepts it.Below is an example of PHP code that contains a directory traversal vulnerability, followed by a path traversal attack that exploits it.
A developer wants users to read poems stored in text files on the web server. The poems are stored in a poems directory under the application. The following code in poems/display.php reads a file specified by the user and prints it:
<?php
$file = $_GET["file"];
$handle = fopen($file, 'r');
$poem = fread($handle, filesize($file));
fclose($handle);
echo $poem;
?>Because the filename is taken directly from the GET request, you would retrieve a poem called poem.txt using a URL like:
http://example.com/my_app/display.php?file=poem.txtThe application doesn’t sanitize the file parameter value, so an attacker manipulates it to escape the intended directory and read a sensitive file by sending:
http://example.com/my_app/display.php?file=../../../../etc/passwdThe display.php script traverses upward in the directory structure and then reads the /etc/passwd file with its list of operating system users on the server and sends it back to the attacker instead of a poem.
Many traversal bugs are straightforward, but attackers often combine traversal with encoding tricks and platform-specific quirks to bypass weak filters or inconsistent normalization.
The table below shows common traversal approaches. These examples are illustrative only – real payloads will vary by framework, server, and how the application processes input.
| Technique | Example | Notes |
|---|---|---|
| Basic relative traversal (Linux/UNIX) | ../ |
Uses parent directory segments to escape a base folder |
| Basic relative traversal (Windows) | ..\ |
Windows path separator variant |
| URL-encoded traversal | %2e%2e%2f |
Encodes ../ to bypass naive filtering |
| Mixed separators | ..\/..\/ |
Attempts to exploit inconsistent path handling |
| Absolute path targeting (Linux/UNIX) | /etc/passwd |
Works if the app accepts absolute paths |
| Absolute path targeting (Windows) | C:\Windows\win.ini |
Works if the app accepts Windows absolute paths |
Traversal vulnerabilities are most common in features that handle local files, such as:
Directory traversal is often confused with local file inclusion (LFI) because both vulnerabilities can involve attacker-controlled file paths. Here’s how they differ:
In practice, LFI and directory traversal often appear together and frequently share the same root causes of allowing paths to local files to be passed through user-controlled input and missing access control on file-retrieval functionality.
Traversal is sometimes dismissed as “just file read,” but the information disclosed is often exactly what attackers need to escalate.
The direct outcome of a successful directory traversal attack is unauthorized access to sensitive information. That information may be valuable on its own (for example, confidential documents or private images stored on the server) or it may enable follow-on attacks such as:
In some cases, traversal can be part of an exploit chain that results in remote code execution, depending on the affected software and surrounding conditions.
Attackers commonly probe for files that reveal system and application context. On Linux-based web servers, the following files are frequent targets because they are typically readable:
/proc/version – Linux kernel version (useful for matching known exploits)/proc/mounts and /etc/fstab – mounted filesystems (useful for locating additional targets)/proc/net/arp – ARP table (useful for discovering connected systems)/proc/net/tcp and /proc/net/udp – active connections (useful for mapping services)Attackers also often hunt for application configuration files, environment dumps, secrets, and logs that may contain API keys, database credentials, tokens, or internal URLs.
Traversal is easy to automate using a vulnerability scanner or by fuzzing, i.e. sending many common payloads to many endpoints until something works. Tools such as DotDotPwn exist specifically to probe for traversal paths, so attackers do not need advanced skills to find and exploit weak file-handling logic.
The best detection approach depends on whether you are dealing with known vulnerable software or trying to find unknown issues in custom code.
If you rely on commercial or open-source products and do not develop the software, start by identifying the exact product version and checking vendor advisories and vulnerability databases. If the version has a CVE and is known to be vulnerable to a traversal issue, you should assume you are exposed until you patch.
You can identify versions manually or with security tooling, for example, software composition analysis (SCA) for web application components or network scanners for networked systems.
To confirm a traversal vulnerability in a custom application or to discover unknown vulnerabilities in a known application, you need evidence that the issue is exploitable in practice. This can be done through:
Focus testing on endpoints and functions that accept filenames, file paths, or directory selections.
Preventing traversal is primarily about avoiding untrusted path input and enforcing strict file-access boundaries.
Adhering to these patterns can remove or greatly reduce traversal risk:
When accepting user-controlled file identifiers is unavoidable, you can apply hardening rules to minimize risk:
Avoid blacklisting, simple filtering, and “block special characters” approaches. Attackers can often bypass these controls with encoding and path-manipulation tricks. Similarly, extension-based checks are easy to subvert and do not solve the core boundary problem.
A defense-in-depth strategy will help you catch issues earlier and spot exploitation attempts:
Mitigation reduces the damage a traversal bug can cause, but it does not replace fixing the root cause.
For zero-day issues or when patching is delayed, temporary web application firewall (WAF) rules can help reduce the risk of exploitation. Always treat this as a stopgap that makes known attacks harder, but does not remove the underlying vulnerability or protect you from new attacks against it.
Directory traversal vulnerabilities often slip in through routine features – file download endpoints, export functions, image retrieval, log viewers – especially when code changes quickly and file-handling logic gets reused across services. Regular vulnerability scanning using DAST helps catch traversal issues early by continuously testing the application the way an attacker would, across environments and releases, rather than relying on one-off reviews.
A practical approach is to scan on a schedule and also automatically after meaningful changes, then route verified findings to the right owners with enough detail to fix quickly. If you want to see how this works in practice, a unified platform like Invicti can help you identify and validate exploitable traversal issues as part of your broader web and API security testing workflow. Request a demo to see how automated scanning and validation can fit into your SDLC and release process.
Anywhere the application reads from disk based on request data. Common hotspots include download and export endpoints, document viewers, image fetch and resize services, log and diagnostic viewers, template or theme loaders, and administrative portals. APIs are also frequently affected when they expose file identifiers that are mapped to filesystem paths.
Because path parsing is full of edge cases. Encodings, mixed separators, repeated delimiters, and differences between application-layer decoding and filesystem normalization can all cause a filter to miss a traversal attempt. Fixing the application design through strict base-directory enforcement with canonicalization checks and allow-listed identifiers is more reliable than trying to filter “bad strings.”
Often, yes. Unix-like systems use forward slashes, while Windows uses backslashes and drive letters, so some frameworks accept both separators. Attackers may try ..\ traversal as well as absolute paths like C:\…. The safest approach is to treat paths as untrusted regardless of platform and always validate the resolved path against an allow-listed base directory.
Symlinks can bypass checks that only look at the raw input string. A path can appear to stay inside an allowed directory but resolve to a location outside it if a symlink points elsewhere. Canonicalization should resolve the final path and verify it remains within the allowed base directory, and sensitive directories should avoid writable paths where attackers could create links.
Avoid using user-supplied filenames as filesystem paths. Store uploads outside the web root, generate server-side identifiers, and keep the real path in a database. Serve files by ID, enforce authorization checks, and construct the path from a trusted base directory plus the stored server-side filename. Apply least privilege so the serving process cannot read unrelated system or application files.
Look for access patterns on file-serving endpoints, spikes in 400/404/500 responses, and unusual requests containing traversal-like sequences or encodings. Prioritize exposure of configuration files, environment files, logs, and secrets. If any credentials or tokens could have been accessed, assume compromise of those secrets and rotate them, then review for follow-on activity such as privilege escalation or lateral movement.
