agentleFS
thejefflarsonthejefflarson/soundcheck/.claude/skills/path-traversal/SKILL.md

path-traversal

Skill20 starsChanged 4 months agoMITView on GitHub

Detects file operations with user-controlled paths vulnerable to ../

  • Reads credentials

6 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

Path Traversal Security Check (A01:2025)

What this checks

Protects against directory traversal attacks where an attacker uses ../ sequences, absolute paths, or symlinks to access files outside the intended directory. Exploitation leads to reading sensitive files (/etc/passwd, .env, private keys), overwriting configuration, or achieving remote code execution via file write.

Vulnerable patterns

  • A caller-supplied filename interpolated or concatenated into a path before opening, with no canonicalization.
  • Path-join helper used as the only defense — these collapse some .. segments but do not verify the final path stays under the intended root, and many treat an absolute caller-supplied path as overriding the base.
  • Existence or stat check on the user path that does not follow symlinks, but the subsequent read/write does — symlink escape.
  • Canonicalization performed once at handler entry, but a later file operation uses the un-canonicalized value.

Fix immediately

Flag the vulnerable code and explain the risk. Then suggest a fix that establishes these properties. Translate each property into the audited file's language and filesystem API — use that platform's documented canonicalization and symlink- resolution call.

  1. The intended root is resolved to a canonical absolute path once, up front. Everything that follows compares against the resolved root, not against a relative string that can match itself after traversal.
  2. The caller-supplied path is joined with the root, then resolved to a canonical absolute path that also follows symlinks — using the platform's real-path / canonicalize / resolve-symlinks call. Only after this does the containment check make sense.
  3. The resolved target must start with the resolved root. A mismatch means traversal or symlink escape; reject rather than fall through. Standard path-join APIs alone do not satisfy this — they collapse some .. segments but do not verify containment.
  4. The check runs before every file operation — read, write, delete, stat. A canonicalization that happens once at handler entry but is not re-applied to a later file operation is a bug.

Verification

  • Every file operation using a caller-supplied path or filename resolves to a canonical absolute path and verifies it starts with the intended root directory
  • Symlinks are resolved before the containment check, blocking symlink escapes
  • User-supplied filenames are never concatenated or interpolated into paths without canonicalization — path-join alone is NOT sufficient
  • The root directory itself is resolved to a canonical path before comparison

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.