Pcornel
Browse topics
Options
Recent
Favorites
Security · Technical reference

Path Traversal

Direct answer

Path traversal uses sequences like ./ in file names to read or write files outside the intended folder. Canonicalize paths, check them against an allowed base directory and avoid user-supplied file names.

When to use this

Use this when file paths come from user input.

First 30 seconds

1. Path traversal accesses files outside intended directories (../).

2. Canonicalise and verify paths stay in base dir.

3. Use IDs instead of filenames.

4. Run with least privilege.

5. Decode before validation.

Operational verification

requested path → canonicalise → inside base dir?

Context & applicabilityCommon mistakes · platform/version boundaries
Common mistakes
Common mistakes
  • Blocking ../ but not ..\, URL-encoded %2e%2e%2f or double-encoded variants.
  • Checking the path before decoding or normalising it.
  • Using startsWith(base) on an unnormalised path.
  • Zip/tar extraction without checking entry names (Zip Slip).
Platform / version applicability
Security architecture and operations
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformSecurity architecture and operations
Scope / prerequisiteUse this when file paths come from user input.
What next?2 suggested next steps
Evidence1
On this pageJump to a specific section
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • ./ sequences escape the intended folder.
  • Canonicalize paths and check the base directory.
  • Avoid user-supplied file names.
Key checks
  • curl -s 'https://<site>/download?file=../../etc/passwd' — test (authorised)
  • Path canonicalisation and base-dir checks — code
  • Allowlist of file IDs — design
ReferenceWhy it matters1 section · depth on demand

Example and fix

Request GET /download?file=../../etc/passwd reads a file outside the download folder.

Fix: map user input to IDs instead of file names, or resolve the canonical path (realpath) and check it starts with the allowed base directory. Reject encoded variants (%2e%2e%2f) by validating after decoding.

ReferenceImportant terms & boundaries1 section · depth on demand

In depth

Path traversal lets an attacker read or write files outside the intended directory by manipulating file paths in input — for example sequences that move up the directory tree, or absolute paths. It can expose configuration files, credentials and source code.

Prevention:

1. Do not use user input directly in file paths; map identifiers to files server-side.

2. If paths are needed, canonicalise them and verify they stay inside the allowed base directory.

3. Run the application with minimal filesystem permissions.

from pathlib import Path
base = Path("/srv/app/reports").resolve()
target = (base / user_name).resolve()
if not target.is_relative_to(base):
    raise PermissionError("invalid path")

Also watch for traversal in archive extraction (zip/tar entries with .. in names).

ReferenceConfiguration & state1 section · depth on demand

Safe pattern

from pathlib import Path
base = Path("/srv/files").resolve()
target = (base / user_input).resolve()
if not target.is_relative_to(base):
    raise PermissionError()

Documented example, not captured output. Better still: map IDs to files on the server and never accept file paths from users.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docSecurity architecture and operations current

Authoritative/upstream documentation reviewed for bounded claims in Web Security → Path Traversal. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://owasp.org/www-project-application-security-verification-standard/ · confidence 94%
Confirmation

Confirm action

Continue?