In plain words

path traversal

A security flaw that lets an unauthorized user view or modify files outside of a web app's normal directory.

What it means

Path traversal is a cybersecurity vulnerability that occurs when a web application lets users access files outside the folder they are supposed to view. Developers normally restrict users to a single directory, such as a folder holding public images, user profile pictures, or downloadable documents. When a path traversal flaw exists, an attacker can bypass these boundaries. The attacker can then view, modify, or run sensitive files on the underlying web server.

This flaw is also widely known as directory traversal. It belongs to a broader family of input validation issues. In simple terms, it means the software trusts file names or paths supplied by users without checking them carefully enough.

How it works

To understand path traversal, you must understand how computer operating systems navigate folders. In almost every major operating system, including Linux, Windows, and macOS, file paths use special characters to represent locations:

  • Root directory: The top-level folder of a file system, written as a forward slash on Linux or a drive letter like C: on Windows.
  • Parent directory: Two dots followed by a slash (../ on Linux or .. on Windows) tell the system to go up one folder level. This sequence is often called the dot-dot-slash sequence.

Web applications often load files dynamically based on input from users. For example, a web address might look like example.com/view?file=report.pdf. The backend code might take the word report.pdf and search for it inside a safe folder, such as /var/www/public/.

If the application does not validate the input, an attacker can replace report.pdf with a path containing dot-dot-slash characters. An attacker might request ../../../../etc/passwd. The server interprets each dot-dot-slash as an instruction to climb higher in the folder tree. Eventually, the path reaches the root directory. From there, the server opens the requested file, such as the system file containing user accounts. The server then sends the contents back to the attacker in the web browser.

Path traversal can also allow writing files. If an application allows users to upload avatars or reports, an attacker might submit a filename like ../../var/www/shell.php. If the application writes that file outside the intended upload directory, the attacker can overwrite critical system files or upload malicious code that executes on the server.

A real example

Open-source electronic medical record platforms, such as OpenEMR, have historically faced path traversal vulnerabilities. Medical platforms manage large volumes of user-uploaded files, such as scanned charts, insurance cards, and digital lab results.

In typical path traversal flaws discovered in such systems, a specific script or API endpoint handles document viewing. The script takes an identifier or a file name parameter from the user. Because the script fails to strip out dot-dot-slash sequences, an attacker can manipulate the request. By repeatedly stepping back out of the document repository, the attacker can read critical configuration files. These files often store database passwords, encryption keys, and administrative credentials. With those keys, attackers can compromise entire databases of patient health records.

Why it matters for builders and investors

For builders, path traversal bugs are dangerous because they are easy to exploit and hard to notice without deliberate testing. Attackers do not need advanced tools to test for them; they only need to send simple modified text strings in a browser or API request.

Builders can protect their applications by applying basic defensive programming principles:

  • Avoid direct file system calls: Instead of accepting user-provided file names, store files using unique database keys or random identifiers.
  • Input validation and sanitization: Strip out special characters, slashes, and dot-dot sequences before processing file requests.
  • Hardcoded allowlists: Only permit specific, approved file extensions and names.
  • Use built-in framework security: Modern frameworks provide built-in functions that resolve absolute paths and verify that the target file stays inside the intended root directory.
  • Least privilege: Run the web server using an account that has minimal file system permissions. If the server user cannot read system files, a path traversal attempt will fail even if the code has a bug.

For investors, widespread security bugs represent operational and legal risks. When a company suffers a data breach due to a basic vulnerability like path traversal, the root cause is almost always poor software quality assurance. Regulatory bodies can issue massive fines for failing to protect consumer data. Furthermore, security disclosures can force engineering teams to halt product roadmaps to patch legacy code, directly hurting product delivery speed.

Common mix-ups

People often confuse path traversal with other web vulnerabilities that involve files or inputs:

  • Local File Inclusion (LFI): Path traversal simply reads or writes a file. LFI takes things a step further: the server actually executes the code inside that file. While an attacker can use path traversal techniques to achieve LFI, the two are distinct concepts.
  • Remote File Inclusion (RFI): RFI occurs when an application downloads and runs code hosted on an external, third-party server. Path traversal deals strictly with files already present on the local server.
  • SQL Injection: SQL injection manipulates database queries using untrusted input. Path traversal bypasses file system paths on the server operating system, completely separate from the database.
  • Broken Access Control: Broken access control is an umbrella category for when users can view things they should not. Path traversal is one specific technical method used to break access controls at the file system level.

Questions people ask

What is the difference between path traversal and directory traversal?

There is no difference. They are two names for the exact same security vulnerability.

Can path traversal lead to full server takeover?

Yes. If an attacker can overwrite system files or upload executable code into a public directory, they can achieve remote code execution.

How can developers prevent path traversal vulnerabilities?

Developers should avoid passing user input directly into file system APIs. They should use allowlists, validate paths, and ensure the server runs with minimal permissions.

Stories that use this word

Play and test yourself

Riddle of the day

Who or what am I?

I do not run your code to see if it breaks.

Solve itNew every day
Real or invented?

Spot the headline we made up

Five headlines. Four are real stories from this week. One is not.

Play nowA new round every day
Weekly quiz

How well did you follow the week?

5 questions. 2 minutes. Points for every right answer.

Take the quizNew every Monday
Prediction of the week

Will Northrop Grumman’s Cygnus XL successfully dock or berth with the ISS within 7 days?

Put free points on Yes or No and climb the leaderboard.

Make your callFor fun, no money