security
file_security
ai_generated
true
Path traversal — ../ sequences bypass file access control
ID: security/path-traversal-dotdot-normalization
90%Fix Rate
92%Confidence
4Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| any | active | — | — | — |
Root Cause
User input containing ../ allows access to files outside the intended directory.
genericWorkarounds
-
93% success Resolve the full canonical path and verify it is within the allowed directory
real = os.path.realpath(os.path.join(base, user_input)); assert real.startswith(os.path.realpath(base))
Sources: https://owasp.org/www-community/attacks/Path_Traversal
-
90% success Use a whitelist of allowed filenames
allowed = {'report.pdf': '/data/reports/report.pdf'}; path = allowed.get(user_input)Sources: https://owasp.org/www-community/attacks/Path_Traversal
Dead Ends
Common approaches that don't work:
-
Filter out ../ with string replace
90% fail
Attackers use URL encoding, double encoding, or OS-specific separators to bypass
-
Check if path starts with allowed directory using startswith
80% fail
Path may resolve differently after symlink resolution