Canonicalization Fundamentals and Path Traversal
You'll learn how attackers use multiple representations of the same path to bypass validation and access unauthorized files.
The Core Problem
Canonicalization is the process of converting data into its simplest, standard form. In file systems and URLs, the same resource can be represented in many different ways:
/app/uploads/file.txt/app/./uploads/file.txt(same location, with current directory marker)/app/admin/../uploads/file.txt(same location, going up then down)/app/uploads//file.txt(extra slash)
When your application validates input before canonicalizing it, attackers can sneak malicious paths past your checks.
Path Traversal Attacks
Imagine your app validates that users can only access files in /uploads/. An attacker might submit:
../../../etc/passwd
If your validation checks the literal string but doesn't resolve the .. (parent directory) sequences first, the attacker bypasses your allowlist and accesses sensitive system files.
Why This Matters
URL encoding adds another layer: %2e%2e%2f decodes to ../. Double encoding (%252e) can bypass filters that decode only once. Operating systems also interpret paths differently—Windows accepts both / and \, creating more bypass opportunities.
The sequence matters critically: validate after canonicalizing, not before. Otherwise, you're checking one path but executing another.
Real-World Scenario
Your app blocks paths containing .., but accepts:
....//(extra dots and slashes that normalize to../)- URL-encoded variants
- Unicode equivalents
- OS-specific representations
After your validation passes it, the filesystem or framework canonicalizes it into a path that escapes your intended directory.
Key Takeaway: Always canonicalize input to its simplest form before validation; attackers exploit the gap between what you check and what the system actually interprets.