How a Simple Endpoint Exposed /etc/passwd via Path Traversal
An image endpoint accepted a user-controlled filename parameter and concatenated it into a filesystem path without validation, allowing directory traversal. An attacker could read arbitrary files such as /etc/passwd and potentially source code, keys, and credentials.
medium.com
Published on medium.com
Hello guys, after a while, here’s a simple but classic vulnerability I came across while testing a feature on target.com.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The application built a file path by concatenating a fixed base directory with unsanitised user input, so traversal sequences could escape the intended directory.
Impact
An attacker could read arbitrary files on the server, which may expose source code, API keys, database credentials, SSH keys, environment variables, internal configs, and log files, potentially leading to deeper compromise.
What the attacker needed
Access to the image endpoint; no authentication required
The fix
The application should not let users directly control file paths; instead it should use internal file IDs, strict allowlists, canonicalise paths before access, block traversal patterns, and enforce directory boundaries server-side.
How it was found
- Open a product image in a new tab and intercept the image request.
- Modify the filename parameter to include traversal sequences.
- Send the request and observe that the response contains the contents of /etc/passwd instead of image data.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
The website had a feature that fetched images by name from a folder on the server. It trusted the name the user supplied and did not check that the name stayed inside that folder. By putting special 'go up one folder' sequences in the name, a visitor could make the server read files from anywhere on the machine, such as the list of user accounts.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.