Directory Traversal Explained: The Bug That Reads Files It Shouldn’t
Imagine a website that lets you download a document: you click a link, and the server fetches a file from a folder and sends it to you. Now imagine you could change which file it fetches — not to another document, but to the server’s password file, its configuration, or its source code. That is directory traversal, and it is one of the oldest, simplest bugs in web security. It still pays bounties today.
How It Works
Web applications often build a file path from user input. A download link might look like: https://example.com/download?file=report.pdf
Behind the scenes, the server does something like: open files/ + report.pdf. But what if you ask for ../config.php instead? The ../ means “go up one directory.” Chain enough of them — ../../../../etc/passwd — and you can walk out of the intended folder entirely and read files anywhere on the server that the application user can access. If the server returns the contents of that system file, the application is vulnerable. The same trick works with encoded variants, backslashes on Windows servers, and absolute paths — which is why a single naive filter rarely fixes it.
Why It Is So Dangerous
Traversal is not just about reading one file. Depending on what the server can access, an attacker can read:
- Configuration files containing database passwords and API keys.
- Source code, revealing further vulnerabilities and secrets.
- System files that map users, services and internal network details.
- Other users’ files, if the application stores uploads or documents per user.
In some cases traversal escalates further: if the application includes the requested file as code rather than just displaying it, traversal becomes local file inclusion (LFI) and can lead to full remote code execution. That escalation is why traversal reports with real impact earn serious bounties.
How Hunters Find It — Legally
Only test applications you own, a lab you built, or a program whose scope explicitly allows it. Never point traversal payloads at a live site without written permission — reading files you are not authorised to read is unauthorised access, even if the bug made it easy. In a legal target, the workflow looks like this:
- Find file parameters. Look for download links, image viewers, template selectors, language pickers — anything where a filename or path appears in a URL parameter.
- Test with a harmless marker. Try traversing to a known, non-sensitive file in your lab and see whether its contents come back. A unique string in the response confirms the bug.
- Map the impact carefully. Show what an attacker could reach — a config file, another user’s document — without actually exfiltrating sensitive production data. Screenshots of your own lab files prove the point safely.
- Report with a fix. Good reports explain the root cause (user input used directly in a file path) and suggest the fix below.
How Developers Stop It
- Never build paths from raw user input. Map user input to an allowlist of permitted files instead.
- Resolve and validate the final path. After joining the path, check that it still sits inside the intended directory. If it escapes, reject the request.
- Strip or reject path separators and .. sequences — but do this as defence in depth, not as the only fix, because encodings and edge cases bypass naive filters.
- Run the application with least privilege. If the web server user can only read its own folder, traversal can only reach that folder. Defence in depth limits the blast radius even when a bug slips through.
Your Practice Path
Set up a deliberately vulnerable app in your own lab — OWASP Juice Shop and similar practice apps include traversal-style challenges — and practise there. Learn to recognise file parameters, test them methodically, and write the report as if a real company were reading it. That discipline is what turns a found bug into a paid bounty. Directory traversal is a beginner-friendly bug with a serious lesson inside it: never trust user input to name a file. One ../ is all it takes to walk out of the folder — and out of the application’s entire security model.



Comments
Post a Comment