Path Traversal and Directory Access
What you'll learn: How attackers use special character sequences to escape intended directories and access sensitive files on a server.
Path traversal (also called directory traversal) is an attack where malicious users manipulate file paths to access files and directories stored outside the web application's intended root folder. Instead of requesting files the application expects you to access, you navigate "up" the directory tree to reach restricted areas.
How Path Traversal Works
Web applications often accept file paths as input—perhaps to load a user profile image, download a document, or display a template. Attackers exploit this by inserting ../ sequences (or ..\ on Windows), which mean "go up one directory level."
Example scenario:
Suppose an application expects: https://example.com/files?document=report.pdf
The server might construct the path: /var/www/app/uploads/report.pdf
An attacker tries: https://example.com/files?document=../../../etc/passwd
The server might resolve this to: /var/www/app/uploads/../../../etc/passwd → /etc/passwd
Now they've accessed the system's password file!
Encoding Tricks
Attackers often encode the ../ sequence to bypass naive filters:
- URL encoding:
%2e%2e%2for%2e%2e/ - Double encoding:
%252e%252e%252f - Unicode/UTF-8 variations:
..%c0%af
These bypass simple string-matching defenses while still being interpreted as path traversal by the underlying system.
Real-World Impact
Successful path traversal can expose:
- Configuration files with database credentials
- Application source code
- System files (
/etc/passwd,/etc/shadow) - Private user data
- SSH keys or certificates
Key Takeaway: Path traversal exploits weak input validation to let attackers navigate beyond intended directories using ../ sequences and encoding tricks—always validate and sanitize file paths, use allowlists, and never trust user-supplied path input.