sast-path-traversal
Detect Path Traversal vulnerabilities in file handling code, API routes, and static file serving. Use when reviewing endpoints that read/write/delete files using user-supplied paths or filenames. Covers ../ sequences, null bytes, and encoding bypasses.
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-05
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- sast-path-traversal
- description
- Detect Path Traversal vulnerabilities in file handling code, API routes, and static file serving. Use when reviewing endpoints that read/write/delete files using user-supplied paths or filenames. Covers ../ sequences, null bytes, and encoding bypasses.
03 SKILL.md 正文
SAST: Path Traversal Detection
Scan for Path Traversal (Directory Traversal) vulnerabilities — OWASP A01:2021.
What to Look For
High Risk Patterns
// ❌ VULNERABLE: user-controlled path in file operations
import { readFileSync } from 'fs';
const content = readFileSync(`./uploads/${req.params.filename}`);
// ❌ VULNERABLE: path.join doesn't prevent traversal alone
const filePath = path.join(__dirname, 'uploads', userFilename);
// If userFilename = '../../etc/passwd', path.join resolves it!
// ❌ VULNERABLE: directory listing with user input
const files = fs.readdirSync(`./data/${req.query.folder}`);
// ❌ VULNERABLE: unvalidated file deletion
fs.unlinkSync(`./uploads/${req.body.file}`);
Safe Patterns
// ✅ SAFE: resolve and verify prefix
import path from 'path';
const UPLOAD_DIR = path.resolve('./uploads');
const requested = path.resolve(UPLOAD_DIR, userFilename);
if (!requested.startsWith(UPLOAD_DIR + path.sep)) {
throw new Error('Path traversal detected');
}
const content = readFileSync(requested);
// ✅ SAFE: allowlist filenames
const ALLOWED_FILES = ['report.pdf', 'invoice.xlsx'];
if (!ALLOWED_FILES.includes(userFilename)) throw new Error('Not allowed');
// ✅ SAFE: use database IDs instead of filenames
const file = await db.collection('files').doc(fileId).get();
const storagePath = file.data().path; // trusted, from DB
Kalmeron-Specific Checks
app/api/user/avatar/route.ts— verify upload path is confined to Firebase StoragePDF Worker(port 8000) — check FastAPI file handling endpoints- Any endpoint that accepts
filename,path,file,dirparameters
Scan Checklist
- [ ] All file paths resolved with
path.resolve()+startsWith(baseDir)check - [ ] No raw user input used in
fs.*calls - [ ] Upload directories are outside the application root
- [ ] File extensions validated against allowlist
- [ ] Null bytes (
\0) stripped from filenames - [ ] URL-encoded traversal sequences (
%2e%2e%2f) decoded and checked
Severity Matrix
| Pattern | Severity |
|---|---|
Read arbitrary file with ../ |
Critical |
| Write to arbitrary path | Critical |
| Delete arbitrary file | Critical |
| List arbitrary directory | High |
| Source code disclosure via traversal | Critical |
Remediation
- Resolve path + check it starts with expected base directory
- Use allowlists for filenames/extensions
- Store files with UUID names (not user-supplied names)
- Use cloud storage (Firebase Storage) — paths are managed by the service
- Chroot or containerize file serving processes
04 同仓库更多 Skills
skill-creator
To create new CLI skills following Anthropic's official best practices with zero manual configuration. This skill automates brainstorming, template application, validation, and installation processes while maintaining progressive disclosure patterns and writing style standards.
business-investment-advisor
Business investment analysis and capital allocation advisor. Use when evaluating whether to invest in equipment, real estate, a new business, hiring, technology, or any capital expenditure. Also use for ROI calculations, IRR, NPV, payback period, build vs buy decisions, lease vs buy analysis, vendor evaluation, or deciding where to allocate limited budget for maximum return.
add-new-agent
خطوات تفصيليّة لإضافة وكيل ذكاء اصطناعي جديد إلى منصّة Kalmeron من الفكرة إلى الإنتاج
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
writing-plans
Use when you have a spec or requirements for a multi-step task, before touching code
web-design-guidelines
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".