Join our Newsletter — 33% off our NHI Course

Path Traversal Attack

A path traversal attack is a way for an attacker to access files or directories outside the intended location of an application. By manipulating file paths, the attacker can read, modify, or sometimes execute sensitive content. In secure systems, input validation and strict filesystem controls limit this risk.

How Path Traversal Works

path traversal attacks abuse file path handling so an application resolves a request outside the intended directory. The weakness is often not the file system itself, but the way the application accepts, normalises, and authorises user-controlled path input before it reaches disk access logic.

In practice, the attacker tries to move from a benign-looking path such as a download or image reference into parent directories, alternate locations, or sensitive application files. If validation is weak, the application may treat attacker-supplied separators, dot segments, or encoded path variants as valid navigation rather than hostile input.

Why Path Traversal Is Dangerous

Path traversal can expose configuration files, source code, credentials, logs, or other data that was never meant to be user accessible. When the target application can also write or delete files, the same flaw may become a content tampering issue rather than only a read problem.

The danger increases when the application runs with broad filesystem permissions or stores secrets alongside web content. In those cases, a single successful traversal can reveal sensitive operational material, help an attacker understand internal structure, or unlock follow-on compromise.

Common Variants and Bypass Techniques

Defenders should expect more than simple ../ sequences. Attackers often combine encoding tricks, mixed separators, alternate encodings, or double-decoding issues to bypass naive filters and make the same traversal payload look harmless during validation but dangerous during file access.

Relative traversal, absolute path confusion, and null byte style legacy issues all reflect the same underlying problem: the application does not anchor the final resolved path to a trusted base directory. When canonicalisation and allowlisting are inconsistent, the security boundary becomes easy to cross.

Detection and Prevention Basics

Strong prevention starts with treating file paths as security-sensitive input. The application should resolve paths against an approved base directory, reject attempts to escape that directory, and avoid direct concatenation of untrusted input into filesystem calls.

Operationally, testing should cover traversal payloads, encoding variants, and file access edge cases across upload, download, export, and template-loading features. If a traversal flaw is found, review what the application can reach, because the real impact depends on the permissions, file locations, and data stored on the host.

Risk and Threat Considerations

Path traversal is risky because it can turn a routine file lookup into unintended access to local data, configuration, or code. The same weakness may also support tampering or limited execution if the application can write to privileged locations or consume attacker-selected files.

Failure mechanism: The application trusts a user-controlled path before normalising it and enforcing a strict directory boundary, so the resolved file location escapes the intended scope.

Impact: Attackers may read sensitive files, alter application behaviour, expose secrets, or chain the issue into broader compromise depending on filesystem permissions and the data exposed.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP ASVS, NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.

Framework Control / Reference Relevance
OWASP ASVS V5 — File Handling Path traversal is a file handling weakness involving unsafe file path resolution.
Recommendation — Validate file paths against a trusted base directory and reject traversal beyond it.
NIST SP 800-53 Rev 5 SI-10 — Information Input Validation The attack relies on unsafe handling of attacker-controlled path input.
AC-3 — Access Enforcement Escaping the intended directory defeats the application's access boundary to files.
CM-7 — Least Functionality Restricting file access surface reduces what traversal can reach if exploited.
Recommendation — Apply input validation to constrain path data before it reaches filesystem operations. Enforce access decisions so file access remains limited to authorised application paths. Limit the application's filesystem reach to only the directories it truly needs.
CIS Controls v8 CIS-3 — Data Protection Traversal can expose sensitive local data and secrets stored on the host.
Recommendation — Protect sensitive files so accidental or malicious path escape does not reveal them.

Practitioner Guidance

Why practitioners should care: Path traversal is often easy to miss in features that seem low risk, such as file previews, downloads, exports, archive extraction, and template rendering. Those flows frequently touch high-value data or privileged filesystem paths.

What to watch for: Look for any place where user input becomes a filename, directory name, or path fragment, especially when the application does its own decoding or path cleanup. The safest design is to map user intent to known objects, not to let users describe raw filesystem locations.