A filesystem path is a route. When user input is joined to a base directory, normalization decides whether the route stays inside the building.
The application joins a user-controlled filename to a public directory. `../` moves up one level. If the resolved path is not checked against the base directory, the attacker reads files outside it.
We see a filename and think data. The filesystem sees a route. The attacker only has to change the route.
What is actually at stake?
Before touching a payload, map the assets, the actors and the boundary that is supposed to protect them. A finding only becomes a vulnerability when you can connect the failed boundary to a real asset.
Assets
- Configuration and secret files
- Other tenants' uploaded documents
- Source code and backups
- Logs containing session or personal data
Actors
- User who controls a filename or download path
- Authenticated customer in a multi-tenant file store
- Attacker chaining traversal with file inclusion or execution
Trust boundaries
- Request parameter to filesystem path
- Upload directory to application root
- Tenant folder to another tenant folder
- URL normalization to filesystem normalization
Abuse cases
- Request ../../secret/flag.txt
- Use encoded dots or slashes to bypass a filter
- Supply an absolute path
- Exploit a symlink inside an allowed directory
- Chain traversal with an include or template loader
Follow the decision, not the payload
Every family has a moment where trusted data becomes an authorization, parsing or state decision. Learn to point at that moment in the request path.
- 01
Accept
A route accepts a filename, document key, template name or export path.
- 02
Join
The handler concatenates the value with a base directory, sometimes after a naive replace of ../.
- 03
Normalize
The filesystem resolves . and .. segments, encoded characters and symlinks.
- 04
Open
The process opens the resolved path with the privileges of the application user.
- 05
Return
The file is streamed, included, parsed or executed, turning a path bug into disclosure or code execution.
Apache HTTP Server path traversal, CVE-2021-41773
CVE-2021-41773, public advisoryApache HTTP Server 2.4.49 changed path normalization in a way that allowed encoded traversal sequences to escape an intended directory when a filesystem path was mapped.
Researchers found that a crafted URL could read files outside the document root. In configurations that enabled CGI, the same primitive could lead to remote code execution.
Internet-facing servers exposed configuration and system files, and some deployments were exploited for code execution. The vulnerability was rapidly scanned after disclosure.
Path normalization and access checks disagreed about the resolved path. Encoded traversal reached the filesystem after the security decision.
Patch the server, canonicalize the path before authorization, compare the resolved path with the allowed root, and avoid serving user-controlled filesystem paths directly.
Read it as a chain: discovery → failed decision → impact → fix. Then ask which link would have broken earliest.
A repeatable testing sequence
- Find file, download, export, attachment and template parameters.
- Try `../`, encoded variants, backslashes and absolute paths.
- Observe errors and content types; a changed error often reveals the resolved path.
- Target the secret file one level above the public directory.
Where smart people get fooled
- Blocking the literal `../` once does not handle encoding or alternate separators.
- Client-side validation is only a suggestion.
- A random filename does not protect the path join.
What would the logs show?
A control is stronger when someone can see it fail. These signals are starting points for a detection rule, not a complete SIEM use case.
- Requests containing ../, encoded dots, backslashes or absolute paths
- File reads outside the expected upload or static directory
- A single session requesting many filenames or directories
- Errors that reveal filesystem paths
- Access to configuration, backup or secret filenames
index=web sourcetype=access_combined | eval trav=if(match(uri,"(\.\.|%2e%2e|%252e|\\|/etc/|/proc/|web\.config)"),1,0) | where trav=1 | stats count values(uri) by clientip, status | where status=200Fix the decision, then prove it stays fixed
- Canonicalize the resolved path and verify it is still inside the intended root.
- Prefer mapping an ID to a known file instead of accepting a path.
- Run the service with a filesystem sandbox and least privilege.
const file = path.join(uploadRoot, req.query.name);
return res.sendFile(file);const name = path.basename(String(req.query.name));
const file = path.resolve(uploadRoot, name);
if (!file.startsWith(path.resolve(uploadRoot) + path.sep)) {
return res.status(404).end();
}
return res.sendFile(file);Resolve first, then compare the canonical path with the allowed root. Reject absolute paths, null bytes and symlinks, and prefer opaque object keys over user-supplied names.
Regression tests a reviewer would ask for
Basic traversal
GivenA download endpoint accepts a filename
WhenThe value is ../../secret/flag.txt
ThenThe server rejects it or returns only a file inside the allowed directory
Encoded traversal
GivenThe endpoint decodes the parameter
WhenThe value uses %2e%2e%2f or double encoding
ThenCanonicalization still confines the path to the root
Absolute path
GivenThe handler joins a base directory and a user value
WhenThe value is /etc/passwd or a Windows absolute path
ThenThe path is rejected, not treated as absolute
Symlink
GivenAn allowed upload directory contains a symlink
WhenThe user requests the symlink target
ThenThe resolved target is checked against the root and denied if outside it
What this finding is not
Strong testers kill their own findings before someone else does. These are the shortcuts that turn a real bug into a weak report — or a false alarm into a wasted escalation.
- The server returns 400 for ../: test encoded variants, double encoding, backslashes and Unicode normalization.
- A filename is passed to an object store: traversal may appear as key confusion or prefix escape rather than a local file read.
- The input is sanitized by removing ../ once: nested patterns such as ....// can reconstruct the sequence after replacement.
- The download works but returns a public file: verify the file is outside the intended directory before rating impact.
Terms you should be able to use precisely
- Path traversal
- Using relative path segments to escape an intended directory.
- Canonicalization
- Resolving a path to its final absolute form before making a security decision.
- Normalization mismatch
- Different components interpret encoded or repeated separators differently.
- Symlink
- A filesystem link that points to another path and can escape a directory boundary.
- Null byte
- A legacy string terminator that can truncate a filename in vulnerable runtimes.
- Opaque key
- A server-generated identifier that maps to a file without exposing a filesystem path.
Answer these without reciting a payload
Why is replacing ../ once insufficient?
Nested patterns can reconstruct the sequence after replacement, and encoded or alternate separators may be normalized later by the filesystem.
What is the correct order of operations?
Decode and canonicalize the path, resolve symlinks, then compare the final path with the allowed root before opening it.
How can traversal lead to code execution?
If the resolved file is included, parsed as a template or executed by CGI, reading outside the root becomes code execution.
Can you separate the mechanism from the payload?
Four questions, graded on the server. Answers and explanations are released only after you submit, and signed-in learners keep a best score.
Path Traversal هي خلاف بين من يفحص المسار ومن يفتحه: الفلتر يرى نصًا، ونظام الملفات يرى مسارًا آخر بعد فك الترميز وتطبيع النقاط والروابط الرمزية.
لهذا لا تفحص النص الخام؛ حوّله إلى مسار مطلق، ثم تأكد أنه ما زال داخل الجذر المسموح. الأفضل ألا تقبل اسم ملف أصلًا، بل مفتاحًا عشوائيًا يولده الخادم. وتذكّر أن القراءة قد تتحول إلى تنفيذ إذا مر الملف على include أو قالب أو CGI.
What is the canonical path after normalization, and is it still inside the intended root?