Module lessons (1/4)
Path Traversal (../) in File Servers
Bypass naive string replacement filters, then enforce canonical path resolution pinned strictly inside a base directory.
What you'll learn in this lesson
- Exploit weak non-recursive
.replace('../', '')sanitizers using nested payloads such as....//. - Explain why
resolved.startsWith('/srv/uploads')without a trailing'/'falls for sibling folders (/srv/uploads-secret). - Implement canonical POSIX path resolution (
decodeURIComponent+ null-byte rejection + extension allowlisting) pinned strictly insiderootDir + '/'.
Overview
File download handlers routinely read a query parameter (?file=report.pdf) and join it onto a storage root such as /srv/uploads. Two classic implementation mistakes expose /etc/passwd or .env: naive substring replacement that leaves behind newly formed ../ sequences, and containment checks missing a trailing directory separator.
Trace four real-world failure modes and their canonical defense:
Sections covered in this lesson
- 11. Non-Recursive Replacers, Prefix Traps & Canonical Containment
- 22. Interactive Explorer: Canonical URL & Path Confusion
- 33. Progressive Labs: Warm-Up → Attack → Defend → Harden
- 44. Checkpoints & Code Review
Unlock "Path Traversal (../) in File Servers" and the full Application & Web Security curriculum
Bypass naive string replacement filters, then enforce canonical path resolution pinned strictly inside a base directory.
Unlock all 6 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Application & Web Security plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.