Skip to content
BENIBIX Learn

Path Traversal

Development🔐 SecurityAttacks

Also known as Directory Traversal, Dot-Dot-Slash Attack

Adding ../ to a file name to climb out of the folder an app should use.

Think of it like

Think of it like a note that says go back two rooms and bring the safe.

Example

A site shows a picture when you ask for cat.png. An attacker asks for ../../../etc/passwd and gets a server file back instead.

Why it matters

Server files hold passwords, keys and settings. One leaked file can open the whole system.

Definition

Path traversal tricks an app into opening files outside the folder it should use. The app builds a file path from user text. The attacker adds ../, which means one folder up. With enough of them, the path climbs out to secret files on the server. The fix is to check that the final path stays inside the allowed folder, or to use a fixed list of names.

Example code

http
GET /view?file=../../../etc/passwd HTTP/1.1
Host: example.com
Each ../ climbs one folder up, out of the picture folder and into the system.
The second row: three ../ steps climb out of the site's folder to a system file.

Common mistake

Removing ../ from the text once. A trick like ....// leaves a fresh ../ behind after the cut.

Key takeaways

  1. 1
    Climb with ../. Each one goes a folder up.
  2. 2
    Check the final path. It must stay in its folder.
  3. 3
    Prefer fixed names. Map each choice to a known file.