sast-analysis
Perform codebase analysis and architecture mapping as the first phase of a security assessment. Explores the tech stack,…
Detect path traversal vulnerabilities in a codebase using a three-phase approach: recon (find file-loading sinks with dynamic paths), batched verify (trace user input and mitigations in parallel subagents, 3 sinks each), and merge (consolidate batch results). Requires
Claude Code
$ npx -y skills add utkusen/sast-skills --skill sast-pathtraversal --agent claude-code
Codex
$ npx skills add utkusen/sast-skills --skill sast-pathtraversal -a codex -y
Cursor
$ npx skills add utkusen/sast-skills --skill sast-pathtraversal -a cursor -y
Gemini CLI
$ npx skills add utkusen/sast-skills --skill sast-pathtraversal -a gemini-cli -y
GitHub Copilot
$ npx skills add utkusen/sast-skills --skill sast-pathtraversal -a github-copilot -y
OpenCode
$ npx skills add utkusen/sast-skills --skill sast-pathtraversal -a opencode -y
Windsurf
$ npx skills add utkusen/sast-skills --skill sast-pathtraversal -a windsurf -y
name: sast-pathtraversal description: >- Detect path traversal vulnerabilities in a codebase using a three-phase approach: recon (find file-loading sinks with dynamic paths), batched verify (trace user input and mitigations in parallel subagents, 3 sinks each), and merge (consolidate batch results). Requires sast/architecture.md (run sast-analysis first). Outputs findings to sast/pathtraversal-results.md. Use when asked to find path traversal, directory traversal, or file disclosure bugs.
You are performing a focused security assessment to find path traversal vulnerabilities in a codebase. This skill uses a three-phase approach with subagents: **recon** (find file-loading sinks with dynamic paths), **batched verify** (trace user input and check mitigations in parallel batches of 3), and **merge** (consolidate batch results into one report).
**Prerequisites**: `sast/architecture.md` must exist. Run the analysis skill first if it doesn't.
---
Path traversal (also called directory traversal) occurs when user-supplied input is incorporated into a file path that is then used to read, write, or serve files from the filesystem — without properly constraining the resulting path to an intended base directory. An attacker can supply sequences like `../` or encoded variants (`%2e%2e%2f`, `..%2f`, `%2e%2e/`) to escape the intended directory and access arbitrary files such as `/etc/passwd`, application source code, credentials, or private keys.
The core pattern: *unvalidated user input reaches a filesystem operation and the resolved path is not verified to remain within the intended base directory.*
`open(os.path.join(BASE_DIR, user_filename))`
`fs.readFile(path.join(__dirname, req.query.file), ...)`
`include($_GET['page'] . '.php')`
Do not flag these as path traversal:
When you see these mitigations applied **before** the file operation, the code is likely **not vulnerable**:
**1. `realpath` / `resolve` followed by a base-directory prefix check (most robust fix)**
# Python
import os
BASE = '/var/www/files'
safe_path = os.path.realpath(os.path.join(BASE, user_input))
if not safe_path.startswith(BASE + os.sep):
raise PermissionError("Path escape detected")
with open(safe_path) as f:
...// Node.js
const BASE = path.resolve('/var/www/files');
const resolved = path.resolve(BASE, req.query.file);
if (!resolved.startsWith(BASE + path.sep)) {
return res.status(403).send('Forbidden');
}
fs.readFile(resolved, ...);// Java
Path base = Paths.get("/var/www/files").toRealPath();
Path resolved = base.resolve(userInput).normalize();
if (!resolved.startsWith(base)) {
throw new SecurityException("Path escape");
}
Files.readAllBytes(resolved);**2. `basename()` / `path.basename()` to strip directory components**
# Python — strips all directory parts, only the filename remains
filename = os.path.basename(user_input)
with open(os.path.join(BASE, filename)) as f:
...// PHP
$filename = basename($_GET['file']);
readfile('/var/www/uploads/' . $filename);**3. Allowlist of permitted filenames or extensions**
ALLOWED = {'report.pdf', 'manual.txt', 'logo.png'}
if user_input not in ALLOWED:
abort(400)
with open(os.path.join(BASE, user_input)) as f:
...**4. Framework-provided safe file serving**
# Flask — send_from_directory validates the path stays within the directory
return send_from_directory('/var/www/files', filename)
# Django — FileResponse with a path that was never user-controlled---
# VULNERABLE: user-controlled filename joined without realpath check
@app.route('/download')
def download():
filename = request.args.get('file')
filepath = os.path.join('/var/www/files', filename)
return send_file(filepath)
# SECURE: resolve and verify the path stays within the base directory
@app.route('/download')
def download():
filename = request.args.get('file')
base = os.path.realpath('/var/www/files')
filepath = os.path.realpath(os.path.join(base, filename))
if not filepath.startswith(base + os.sep):
abort(403)
return send_file(filepath)# VULNERABLE: path parameter used directly in file read
@app.get('/file/{name}')
async def get_file(name: str):
return FileResponse(f'/app/static/{name}')
# SECURE: basename strips traversal sequences
@app.get('/file/{name}')
async def get_file(name: str):A collection of agent skills that turn your LLM coding assistant into a fully functional SAST scanner to find vulnerabilities in your codebase. Works natively with Claude Code, Codex, Opencode, Cursor and any other assistant that supports agent skills.
Perform codebase analysis and architecture mapping as the first phase of a security assessment. Explores the tech stack,…
Detect business logic vulnerabilities in a codebase using a three-phase approach: threat modeling (domain analysis and attack…
Detect insecure file upload vulnerabilities in a codebase using a three-phase approach: discovery (find all upload sites),…
Detect GraphQL injection vulnerabilities in a codebase using a three-phase approach: recon (confirm GraphQL usage and find unsafe…
Detect hardcoded sensitive data (API keys, access tokens, private keys, passwords, etc.) in publicly accessible code — frontend…
Use for authorized security assessment of REST, GraphQL, WebSocket, or SOAP APIs, including discovery, authentication,…
Extract and decrypt Windows DPAPI-protected secrets (Credential Manager, browser logins/cookies, Wi-Fi credentials, KeePass keys)…
Clean and finalize authorized natural-language text intended for readers by auditing suspicious invisible Unicode and rewriting…