Path Traversal (aka Directory Traversal) is a vulnerability that allows attackers to access files outside the intended directory by manipulating the file path input. This occurs when user-supplied input is improperly validated, allowing use of sequences like ../ to traverse directories.
Example Attack:
Read sensitive system or application files.
Load unintended code files.
Breach of PII, secrets, or logs.
To prevent path traversal:
Ensure user input cannot escape the intended base directory.
Allow access only to known good files or IDs instead of filenames.
Block potentially dangerous extensions (.php, .sh, etc.)
On Unix systems, disallow symlinks pointing outside the allowed dir.
“Path Traversal is deceptively simple but highly dangerous. Fixes are straightforward if caught early. Always validate, normalize, and control file access based on business logic—not user input.”