What Is Path Traversal?

Path Traversal : A vulnerability that allows attackers to access files and directories outside the intended scope by manipulating file path inputs. Using sequences like ../ or encoded variants, attackers can read sensitive system files, application source code, configuration files containing credentials, or write to arbitrary locations.

Why It Matters for AI-Coded Apps

AI-generated file handling code rarely validates file paths properly. When a vibe coder prompts ‘add a file download feature,’ the AI generates the simplest working solution that directly concatenates user input with a base directory, creating an exploitable path traversal vulnerability.

Real-World Example

An API endpoint serves user uploads: app.get('/files/:name', (req, res) => res.sendFile('/uploads/' + req.params.name)). An attacker requests /files/../../etc/passwd and reads the system password file. The fix: use path.resolve() and verify the resolved path starts with the intended directory.

How to Detect and Prevent It

Always resolve file paths to their canonical form and verify they fall within the expected directory. Use allowlists of permitted file names when possible. Never concatenate user input directly into file paths. Use framework-provided safe file serving methods. Strip or reject inputs containing .., ~, or null bytes.

Frequently Asked Questions

What files do attackers target with path traversal?

Common targets include /etc/passwd, /etc/shadow (Linux credentials), .env files (API keys and secrets), application source code, configuration files (database credentials), SSH keys, and cloud provider metadata endpoints at 169.254.169.254.

Does using a CDN prevent path traversal?

A CDN can reduce exposure by serving static files separately, but path traversal targets dynamic file-serving endpoints in your application code. If your app has an API that reads files based on user input, a CDN does not protect against traversal in that endpoint.

How do I test for path traversal?

Try accessing files using ../ sequences in any parameter that references files: URL paths, query parameters, form fields, and HTTP headers. Test encoded variants like %2e%2e%2f, ..%5c, and double-encoding. Automated tools like OWASP ZAP and Burp Suite include path traversal scanners.

Scan your app for security issues automatically

Vibe Eval checks for 200+ vulnerabilities in AI-generated code.

Try Vibe Eval

AI Coding Security Insights.
Ship Vibe-Coded Apps Safely.

Effortlessly test and evaluate web application security using Vibe Eval agents.