fabioc-aloha/alex_skill_mall/path-traversal-prevention

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

When copying files or serving content, user-controlled paths can escape the intended directory:

Install

npx vskill@latest install fabioc-aloha/alex_skill_mall/path-traversal-prevention

SKILL.md

Path Traversal Prevention

The Problem

When copying files or serving content, user-controlled paths can escape the intended directory:

javascript
// Vulnerable: attacker controls filename
const dest = path.join(uploadDir, req.body.filename);
// If filename is "../../../etc/passwd", dest escapes uploadDir

The Solution

Validate that resolved paths stay within the intended root:

javascript
function safeJoin(root, userPath) {
const resolved = path.resolve(root, userPath);
const normalized = path.normalize(resolved);
// Ensure result is still within root
if (!normalized.startsWith(path.normalize(root) + path.sep) &&
normalized !== path.normalize(root)) {
throw new Error('Path traversal attempt detected');
}
return normalized;
}
// Usage
try {
const safePath = safeJoin('/uploads', userFilename);
// Safe to use safePath
} catch (err) {
res.status(400).json({ error: 'Invalid filename' });
}

For Directory Trees

When recursively copying directories:

javascript
async function safeCopyTree(src, dest, allowedRoot) {
const entries = await fs.readdir(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
// Validate destination stays in bounds
const resolvedDest = path.resolve(destPath);
if (!resolvedDest.startsWith(path.resolve(allowedRoot))) {
throw new Error(`Path escape: ${entry.name}`);
}
if (entry.isDirectory()) {
await fs.mkdir(destPath, { recursive: true });
await safeCopyTree(srcPath, destPath, allowedRoot);
} else {
await fs.copyFile(srcPath, destPath);
}
}
}

Common Attack Patterns

PatternWhat It Does
../Parent directory
..\\Parent on Windows
....//Bypass naive ../ filter
%2e%2e%2fURL-encoded ../
..%c0%afOverlong UTF-8 encoding

Verification

javascript
const attacks = [
'../etc/passwd',
'..\\windows\\system32',
'foo/../../bar',
'normal/path/file.txt' // Should pass
];
attacks.forEach(p => {
try {
const result = safeJoin('/uploads', p);
console.log(`OK: ${p} -> ${result}`);
} catch (e) {
console.log(`BLOCKED: ${p}`);
}
});

When to Apply

  • File upload handlers
  • Static file servers
  • Archive extraction (zip, tar)
  • Template file loading
  • Any path from user input

Tags

security path-traversal file-system input-validation

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
4
Repository forks
1
7-day trend score
13

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/fabioc-aloha/alex_skill_mall/path-traversal-prevention/badge)](https://verified-skill.com/skills/fabioc-aloha/alex_skill_mall/path-traversal-prevention)

Something wrong with this skill or its page? Tell us.