Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Is Path Traversal?

Path traversal lets an attacker read or write files outside the directory an application intended, usually by inserting relative path sequences into a filename parameter.

Illustration for the cybersecurity term Path Traversal
Home / Blog / Cybersecurity Terms / What Is Path Traversal?
17 November 2026

What Is Path Traversal?

What Is Path Traversal?

Path traversal, also called directory traversal and tracked as CWE-22, is the oldest trick in web security that still works. An application takes a filename from a request and uses it to build a path. The attacker includes ../ sequences, the path resolves somewhere else on the filesystem, and files the application never meant to expose are returned to the browser.

Why Simple Filters Fail

Most attempts to fix this with string matching are defeated within an afternoon. Developers strip ../, so attackers send ....//, which becomes ../ after a single non-recursive replacement. Percent-encoding gives %2e%2e%2f, double encoding gives %252e%252e%252f, and on systems that decode UTF-8 loosely, overlong sequences have historically produced the same result. Windows accepts backslashes as well as forward slashes and ignores trailing dots and spaces. Absolute paths skip the question altogether where the application concatenates without checking.

Nor does a filename have to come from a URL. Archive extraction is a recurring source: an entry inside a zip file whose name contains traversal sequences writes outside the extraction directory when unpacked, a pattern named Zip Slip and found in libraries across every major language. Upload filenames, email attachment names, and values read from a database all reach the same code.

Recent, Real, and Severe

Both illustrate the same point: these are not only application bugs. Web servers, build systems, and file transfer products handle paths constantly, and a traversal in one of them usually reaches credentials before it reaches anything else.

What an Attacker Reads First

On Linux, /etc/passwd confirms the vulnerability and is rarely the objective. The targets that matter are application configuration files holding database credentials and API keys, .env files, private keys under a user’s SSH directory, cloud credential files, and source code that reveals further weaknesses. On Windows, the equivalents are web.config, unattended installation answer files, and the SAM database. Where the application writes rather than reads, traversal becomes file upload to an arbitrary location, which generally means a web shell.

Validating a Path Correctly

  1. Avoid user-supplied paths. Map an identifier to a filename through a lookup table or a database record, so the request never contributes to the path at all.
  2. Where a filename is unavoidable, resolve first and check second. Canonicalise the full path with the platform’s own function, which collapses relative sequences and follows symbolic links, then confirm the result begins with the intended base directory. Checking the raw input before resolution is the mistake that defeats every filter listed above.
  3. Allow-list the characters and extensions you accept in a filename, rejecting separators entirely.
  4. For archives, validate each entry’s resolved destination before writing it, and refuse absolute paths and symbolic links.
  5. Constrain the process. A container, a chroot, or an operating system sandbox limits what a successful traversal can reach, and a service account with read access only to its own directory limits it further.
  6. Store user content in object storage rather than on the local filesystem, which removes the class of bug for that content entirely.

Detection and Testing

Traversal attempts are noisy in logs, and alerting on encoded dot sequences in request parameters catches opportunistic scanning. The more valuable signal is behavioural: a web process opening files outside its content directory is a strong indicator, and file integrity monitoring on configuration directories detects the write variant. For testing, every parameter that could reach a file operation deserves a set of encoded probes, as described for file upload vulnerabilities and file inclusion. Our web application security testing covers both read and write paths, including archive handling.

FAQ – Frequently Asked Questions

How Is Path Traversal Different from File Inclusion?

Both start with user input influencing a file path. Traversal reads the file and returns its contents, so the impact is disclosure of configuration, credentials, or source code. File inclusion passes the file to an interpreter, so the contents are executed. An application with inclusion is usually one step from code execution; one with traversal is usually one step from credentials.

Is Stripping ../ From Input a Valid Defence?

No. A single non-recursive replacement is defeated by nested sequences that reassemble after substitution, and the filter never sees percent-encoded, double-encoded, or backslash variants. Validation also runs against the raw string rather than the path the operating system will resolve. Canonicalise the full path first, then verify it sits inside the permitted directory.

Can Path Traversal Lead to Code Execution?

Frequently, through two routes. If the vulnerable operation writes rather than reads, an attacker places a script in a directory the web server executes. If it only reads, the stolen material, such as SSH keys, cloud credentials, or an application secret, usually provides access elsewhere. Apache CVE-2021-41773 reached execution directly where CGI scripts were enabled.

Does Running in a Container Prevent It?

It limits the blast radius rather than preventing the flaw. A container restricts the attacker to that filesystem, which is a genuine improvement, but application configuration, mounted secrets, service account tokens, and environment variables all live inside it and are usually the objective. Treat isolation as containment and fix the path handling itself.

Related Terms

You May Be Interested In These

What Is Looney Tunables?

Cybersecurity Terms

17 November 2026

What Is Looney Tunables?

Read More
What Are DMA Attacks?

Cybersecurity Terms

17 November 2026

What Are DMA Attacks?

Read More
What Is Cryptojacking?

Cybersecurity Terms

17 November 2026

What Is Cryptojacking?

Read More