What Is a Directory Traversal Attack, and How Can You Spot It? (Explained Clearly) - Path Traversal
Learn what a directory traversal attack is, how to use security logs to tell an attempt from a confirmed file leak, and how to prevent path traversal.
👉 Master your Security+ skills with Pluralsight here: Pluralsight
You’ll learn what a directory traversal attack (also called path traversal) is, how to distinguish a suspicious request from a confirmed file leak using security logs, and how file access controls and least privilege help prevent it.
Chapters:
0:00 Intro
0:14 What is a directory traversal attack?
0:59 What makes directory traversal dangerous?
1:47 How can you spot directory traversal in security logs?
2:41 How do you prevent directory traversal?
3:47 Outro
Disclaimer: Only test systems you own or have explicit permission to assess.
Affiliate notice: Some links may earn a commission. Thanks for your support.
- A directory traversal attack (CWE-22) tricks an application into reading, writing, or deleting files outside its approved directory. The impact depends on what the feature does and what files the service can access.
- A suspicious request is not proof of a leak. Match the request to application and host logs to identify which file the service opened or changed. For a read, verify separately whether the contents reached the requester.
- Keep file locations under server control. Use document IDs with per-document authorization and server-generated upload names. When paths are necessary, verify that the resolved destination stays inside the approved directory before accessing it or writing archive entries.
- Use least privilege to limit damage. Give the service access only to the files it needs, and enforce directory boundaries and authorization checks in the application.
- 👉 Practice with Pluralsight to build security investigation skills in guided labs, get feedback, and use practice exams to focus your certification prep.
A directory traversal attack, also called path traversal, occurs when software is tricked into reading, writing, or deleting a file outside the directory it was supposed to use. In a security alert, an unusual file path can be a sign of an attempt, but it doesn’t prove that a file was exposed. To find out what happened, trace the request to the file operation the service actually performed.
What is a directory traversal attack?
Imagine a training portal that lets visitors download public course handouts. The download feature should only open files in the handouts folder. If it uses a location influenced by the request and opens a private staff document in another folder, it has crossed its intended directory boundary. MITRE classifies this weakness as CWE-22: Path Traversal.
FAQ
Quick answers to the questions people usually ask about this topic.
What’s the difference between directory traversal and insecure direct object reference (IDOR)?
What’s the difference between directory traversal and insecure direct object reference (IDOR)?
Directory traversal crosses a filesystem boundary: the application opens or changes a file outside its approved directory. IDOR crosses an authorization boundary: the application lets someone access an object they aren’t entitled to, even if the file is in the right directory. Using document IDs instead of paths reduces traversal risk, but the server must still check who can access each document. MITRE catalogs path traversal as CWE-22.
Can a web application firewall (WAF) stop directory traversal attacks?
Can a web application firewall (WAF) stop directory traversal attacks?
A WAF can flag or block some suspicious requests, but it can’t reliably determine which file the application ultimately opens. Treat it as an extra layer: the application still needs to enforce the directory boundary when it opens a file, and the service should have access only to the files it needs.
What should applications log to make directory traversal easier to investigate?
What should applications log to make directory traversal easier to investigate?
Use a shared request ID to connect the incoming request, the file operation, and the response. Record the file-handling feature, the operation attempted, the destination the service actually accessed, and whether the operation succeeded. For downloads, record which file was served when possible. Protect these logs and avoid recording file contents or credentials.
How should you classify a suspected directory traversal incident if the logs are incomplete?
How should you classify a suspected directory traversal incident if the logs are incomplete?
Report what the evidence supports and state what remains unknown. A suspicious request and a successful HTTP response don’t confirm file access. If you can tie the request to a read outside the approved directory but can’t establish what the response contained, report confirmed unauthorized file access with disclosure unconfirmed.
Where can I practice investigating alerts like directory traversal after learning the basics?
Where can I practice investigating alerts like directory traversal after learning the basics?
If you’re ready to apply what you’ve learned, explore guided labs with Pluralsight. Use the labs and feedback to practice deciding what an alert actually proves, then use assessments and practice exams to identify gaps and focus your certification prep.
Comments
Add a comment...Pinned by @jaymayor
@jaymayor👉 Master your Security+ skills with Pluralsight here: https://www.jaymayor.com/go/security-plus
Some links may earn a commission. Thanks for your support.
