The Novee Gym is open for business at Black Hat Europe

Book a meeting

The Novee Gym is open for business at Black Hat Europe

Book a meeting

Glossary › Directory Traversal

Directory Traversal

Explore Article +

Key Takeaways

  • Directory traversal, also called path traversal, lets attackers read files outside the folder an application meant to expose.
  • The attack relies on ../ sequences and their encoded variants to climb the file system.
  • It is primarily an information disclosure vulnerability, but leaked secrets often lead to full compromise.
  • The reliable fix is to resolve the canonical path and verify it stays inside an allowed base directory.

What Is Directory Traversal?

Directory traversal is a vulnerability in which an application uses user-supplied input to build a file path without restricting it, letting an attacker read or sometimes write files outside the intended directory. MITRE tracks it as CWE-22, Improper Limitation of a Pathname to a Restricted Directory.

OWASP maps path traversal to Broken Access Control, A01 in the OWASP Top 10:2025, because the application serves files the user was never authorized to see.

The Path Manipulation Technique That Makes Directory Traversal Work

Consider a page that loads images with /view?file=report.png and reads from /var/www/images/. The server appends the parameter to the base path. If an attacker sends file=../../../etc/passwd, each ../ moves up one level until the path resolves to /etc/passwd.

A directory traversal attack rarely stops at plain dots and slashes. Common variants include:

  • URL encoding. %2e%2e%2f or double-encoded %252e%252e%252f slip past filters that check before decoding.
  • Windows separators. ..\ and mixed slashes work on Windows hosts.
  • Absolute paths. Supplying /etc/passwd directly when the code does not enforce a prefix.
  • Nested sequences. ....// collapses to ../ when a filter strips ../ only once.
  • Null bytes. %00 truncated forced file extensions in older PHP and Java runtimes.

The Files and System Data a Traversal Vulnerability Exposes

A confirmed traversal flaw exposes whatever the web server process can read. High-value targets include:

  • System files. /etc/passwd, /etc/hosts and C:\Windows\win.ini confirm the flaw and map the host.
  • Application secrets. .env files, web.config, application.properties and cloud credential files hold database passwords and API keys.
  • Source code. Reading the app’s own code reveals further vulnerabilities and hardcoded tokens.
  • Keys and logs. SSH private keys, TLS keys and access logs that can enable log poisoning.

When the vulnerable function also writes files, as in archive extraction bugs known as Zip Slip, traversal can overwrite scripts and lead to code execution.

How Pentesters Test for Directory Traversal

Testers enumerate every parameter, header and upload field that references a file name or path, including download endpoints, template selectors, language files and export features. They also check APIs behind mobile apps, which often skip the validation applied in the browser, a recurring finding in mobile app testing.

They then send traversal payloads toward a known file, escalating through encodings, separators and depth until the target’s contents appear. Burp Suite Intruder, OWASP ZAP and wordlists such as those in SecLists automate the variations, while manual testing handles filters that need creative bypasses.

File-handling bugs often sit beside other input flaws. Novee’s disclosure of a stored XSS vulnerability in pretalx shows how one overlooked input path can end in account takeover.

How to Fix Directory Traversal Vulnerabilities

  • Avoid user-supplied paths. Map files to IDs or keys on the server and look them up, so users never send a path at all.
  • Canonicalize, then check. Resolve the full path with functions like realpath() or Java’s getCanonicalPath() and confirm it starts with the allowed base directory.
  • Allowlist names. Accept only known file names or a strict character set with no slashes or dots.
  • Restrict the process. Run the server with least privilege and chroot or container isolation so sensitive files are unreachable.

Novee’s AI pentesting agents probe file-handling endpoints with encoded and chained payloads, three independent agents validate each finding, and Agentic Remediation retests to confirm the fix holds.

FAQ

Directory traversal reads or writes a file outside the intended folder; the contents come back as data. Local file inclusion loads the file into the application’s include or require logic, so the server may execute it as code. Traversal sequences are often the delivery method for LFI, but the impact differs.

Yes, when filters inspect input before it is fully decoded. Encodings such as %2e%2e%2f, double encoding like %252e%252e%252f and overlong UTF-8 sequences have all bypassed real filters. The defense is to decode and canonicalize the path first, then validate the result against an allowed base directory.

The flaw lives in application code or server configuration, so it can affect Apache, Nginx, IIS, Tomcat and Node.js alike. Payloads differ by platform: Windows accepts backslashes and drive letters, while Linux uses forward slashes. Server software has had its own bugs too, such as Apache HTTP Server CVE-2021-41773.

A 200 OK containing the target file’s contents is the clearest signal. A 500 error on traversal payloads but not normal input suggests the path reaches the file system. Differences between 403 and 404 can reveal which files exist. Testers confirm by reading a file with known contents.

Often, yes. Public download endpoints, static file handlers and pre-login resources such as language or theme files are common unauthenticated entry points. Traversal behind a login is still serious, because any low-privilege account can read files meant only for administrators or the server itself.