Untrusted input becomes part of a filesystem (or internal URL) path without being resolved and confined to an intended root, so the operation reads, writes or includes a location the developer never meant to expose (CWE-22).
What it is
Root cause: a value from outside the trust boundary (request parameter, filename in a multipart header, archive entry name, manifest field, symlink target, organization name, syslog header) is concatenated or joined into a path and handed to a filesystem API. The code reasons about the string; the OS acts on the resolved location.
The trust boundary that breaks is the directory the feature is supposed to own: an upload folder, a theme directory, a repo worktree, a container, a model store. Anything that lets the resolved path leave that root breaks it.
The same flaw applies to paths on a second server: a proxy that splices user input into an internal request path walks the internal service’s route tree (Starbucks) rather than a disk. Starbucks Path Traversal: Nearly 100M Customer Records
Why it matters
Impact depends on the primitive (read, write, include, delete) and the process’s privileges.
Write-to-RCE is a solved problem on most targets. The DEF CON Bug Bounty Village catalogue grades a write on four dimensions and lists sinks by environment: cron (good on VMs, useless in most containers), systemd (needs enable and reload), /etc/ld.so.preload (fires on every new process), and line-oriented targets such as authorized_keys, shell profiles and .user.ini for append-only writes. It also notes that a write primitive doubles as a path-existence oracle. Write Once, Shell Everywhere - Turning Arbitrary File Writes into RCE (DEF CON Bug Bounty Village)
Normalization rewrites a path string (collapse dot segments, duplicate separators). Canonicalization asks the filesystem for the real location, which also resolves symlinks. Only the second answers “where will this land?”
String prefix checks are not containment. A sibling such as uploads_secret starts with uploads; the Imperva writeup makes the same point about /safe/output-elsewhere. Flask-AdminCopyEscape
TOCTOU. A check on a path the attacker can change (their own symlink, a live container filesystem) is raced. CopyEscape combined a source-walk race with a symlink-following extraction. CopyEscape
Archive extraction
Entry names and link targets inside zip/tar/cryptex archives are attacker-controlled paths. Extracting without per-entry containment is Zip Slip.
Include mechanisms
When the sink is an interpreter’s include (PHP include/require, template resolution), traversal becomes code execution if any reachable file contains or can be made to contain code. See Local File Inclusion.
File-reader tools without a root; 82% of 2,614 MCP servers analysed use path-traversal-prone file ops
Mobile content providers
Android _display_name used as a filename (Xiaomi Mi Browser)
Repo-consuming tools
Build scripts, editors and AI coding agents reading through committed symlinks
How to review and test
Code review:
Trace every filesystem call (open, File, Path, readFile, include, extract*, copy, rename, unlink) back to its inputs. Include indirect inputs: archive entries, manifests, DB fields, headers, filenames from clients.
Is the check done on the canonical path, after symlink resolution, and compared component-wise to the canonical root? Flag startswith/indexOf on strings.
Is the value that is checked the value that is used? Look for re-reads, re-joins and later decoding.
Is every component validated (directory and filename), on every entry point (UI, API, import, RPC)?
Does the code follow symlinks the attacker can create (git checkouts, uploaded archives, shared containers, app groups)? Is there a TOCTOU window?
Are archives extracted with per-entry containment and link handling? Are stdlib filters up to date (see Zip Slip and Archive Extraction)?
Does any include/template loader take user input? Is there an allowlist?
Do patches cover sibling paths? CVE-2025-8110, CVE-2025-6023 and CVE-2026-22559 were all bypasses or variants of earlier fixes.
Does an AI/MCP tool enforce a root in code, not in the prompt?
Behavioral testing (what to observe, not payloads):
ManageEngine ADAudit Plus — CVE-2022-28219 — traversal in /cewolf lets a planted file be deserialized, chained with blind XXE. Rapid7 Analysis: CVE-2022-28219
Xiaomi Mi Browser — CVE-2026-127209 — content-provider _display_name used as filename, write outside staging dir. Xiaomi Mi Browser
iOS containermanagerd — no CVE — symlinked App Group part yields read-write sandbox token for other containers. worse_finder
AWS aidlc-traceability — no CVE — LLM file-reader tool with no root; fixed with read-boundary enforcement. AI Agent File Reader
Cairn AI pentest agents (2026): a traversal in an upload filename wrote sitecustomize.py, which a newly spawned Python training process imported, giving a root shell. (source)
Prevention
Don’t let users name paths. Map an ID to a server-side path through a lookup table, or generate filenames server-side (UUIDs). The JWT kid remediation is the canonical pattern. JWT Signature Bypass via kid Path Traversal
Canonicalize, then verify containment component-wise. Resolve the root and the candidate (following symlinks) and require the candidate to be inside the root. AWS’s fix and the sibling _resolve_safe() helper do this; Path.resolve() also closes the symlink escape. AI Agent File ReaderPython Secure Coding Guidelines
ROOT = Path("/srv/app/files").resolve()def safe_path(user_rel: str) -> Path: p = (ROOT / user_rel).resolve() if not p.is_relative_to(ROOT): # component-wise, not str.startswith raise PermissionError("outside root") return p
Java equivalent, as in UniFi’s fix (toRealPath() containment) and ColdFusion’s resolveCanonical (reject empty, NUL, parent segments, absolute paths, and anything resolving outside the allowed area):
if (userRel.isEmpty() || userRel.indexOf('\0') >= 0) throw new SecurityException("bad path");Path root = baseDir.toRealPath();Path real = root.resolve(userRel).normalize().toRealPath(); // resolves symlinks; file must existif (!real.startsWith(root)) throw new SecurityException("outside root"); // Path.startsWith is per-component
Kill the TOCTOU. A realpath() check followed by open() can be raced. On Linux use openat2() with RESOLVE_BENEATH or RESOLVE_NO_SYMLINKS so the kernel enforces the boundary in one step; O_NOFOLLOW covers only the last component. Imperva’s conclusion for docker cp: filesystem operations must be rooted so the kernel, not a string comparison, guarantees containment. Symlinks Are Still ScaryCopyEscape
Sanitize filenames with framework helpers and also enforce policy. Flask-Reuploaded’s workaround: secure_filename, then os.path.basename, then an extension allowlist, or auto-generated names only. Flask-Reuploaded
safe = os.path.basename(secure_filename(request.form["custom_name"]))if not photos.extension_allowed(photos.get_extension(safe)): abort(400)photos.save(file, name=safe)
Validate every component and entry point. The directory part (guid, org name, chapter title, uploadPath) needs the same treatment as the filename, on API routes as well as the UI.
Allowlist includes and templates. Never pass request data to an include; see Local File Inclusion.
Extract archives safely. Per-entry containment, reject or neutralize links, keep stdlib current; see Zip Slip and Archive Extraction.
Contain the blast radius. Run file-handling services unprivileged (Ollama-in-Docker as root made writes critical), store uploads outside executable directories (see Unrestricted File Upload), sandbox extraction, and treat cloned repos as untrusted before pointing tools or agents at them. Python Security Vulnerabilities - Top Issues - Aikido
Normalize once, at the edge that routes. Reject or canonicalize path parameters and encoded separators so the WAF, proxy and app agree (IBM Db2 Mirror fix advice: use container-normalized servlet info, reject unexpected path parameters, confine reads to an allowlisted directory with canonical-path checks). IBM Db2 Mirror for i: pre-auth RCE and the road to QSECOFR
Monitor for the write. For root-write bugs, file-integrity monitoring catches exploitation better than log greps (Check Point guidance).
Tools
Static analysis: Aikido SAST flags tarfile.extractall() without member filtering (CVE-2007-4559) Aikido; Bandit’s tarfile_unsafe_members rule is covered in Python SAST Tools. Semgrep and CodeQL path-injection rules are not covered by the cited notes.
Practice corpora: YesWeHack vulnerable code snippets include several path-traversal, LFI and upload snippets for review training. GitHub - yeswehack/vulnerable-code-snippets
Fuzzing:ffuf with generated depth wordlists (cook) instead of stock lists, which the author calls weak for traversal; see Web Fuzzing. ffuf advanced tricks - ACCEIS