path-traversal-and-file-handling
Use when the diff builds a filesystem path from input, extracts an archive, accepts an upload, serves a file or writes a temp file - traversal, symlinks…
от makifbaysal★ 123 звезды на GitHub
Установить path-traversal-and-file-handling в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Path Traversal and File Handling
Overview
Join, normalize, resolve and clean are lexical: they rewrite a string, they do not ask the filesystem where it points. A path check that runs on the string and an open that runs on the filesystem disagree whenever there is a .., an absolute path, or a symlink.
Core principle: resolve the real path first, then check containment by path components, then open what you checked — or use an API that confines the open itself.
1. Traversal (CWE-22)
// ❌ HasPrefix on a cleaned string: "/srv/files-private/x" passes for base "/srv/files",
// and a symlink inside base escapes entirely
p := filepath.Join(base, name)
if !strings.HasPrefix(filepath.Clean(p), base) { return errBadPath }
f, _ := os.Open(p)
// ✅ Go 1.24+: the root confines every lookup, symlinks included
root, _ := os.OpenRoot(base)
f, err := root.Open(name)
// older Go: reject non-local names first — filepath.IsLocal(name) (Go 1.20+)
// ❌ normalize() is lexical; a symlink under base still escapes
Path p = base.resolve(name).normalize();
if (!p.startsWith(base)) throw new SecurityException();
// ✅ compare real paths (Path.startsWith is component-wise, String.startsWith is not)
Path real = base.resolve(name).toRealPath();
if (!real.startsWith(base.toRealPath())) throw new SecurityException();
# ❌ os.path.join drops base entirely when name is absolute ("/etc/passwd")
path = os.path.join(UPLOAD_DIR, name)
# ✅
root = Path(UPLOAD_DIR).resolve()
path = (root / name).resolve()
if not path.is_relative_to(root): # Python 3.9+
abort(400)
// ❌ startsWith without a trailing separator; "/data/app-secrets" passes for "/data/app"
const p = path.resolve(base, name); if (!p.startsWith(base)) throw ...
// ✅
const p = path.resolve(base, name); if (!p.startsWith(base + path.sep)) throw ...
// and for symlinks: fs.realpathSync(p) before the check
Flask: send_from_directory. Express: res.sendFile(name, { root: base }) (rejects escaping paths) rather than res.sendFile(path.join(base, name)).
2. Symlinks (CWE-59)
Lexical checks never see a symlink. It matters when the attacker can create files inside the base (an upload directory, an extracted archive, a cloned repository, a shared volume). Resolve with realpath/EvalSymlinks/toRealPath, or open with O_NOFOLLOW / os.Root. A check-then-open gap on a directory the attacker writes to is a race (CWE-367) — report it only when the attacker demonstrably controls that directory.
3. Archive Extraction (zip-slip)
Archive entry names are attacker input: ../../.ssh/authorized_keys, absolute paths, and symlink entries that point outside and are then written through.
// ❌
File out = new File(destDir, entry.getName());
Files.copy(zis, out.toPath());
// ✅
Path out = destDir.resolve(entry.getName()).normalize();
if (!out.startsWith(destDir)) throw new IOException("bad entry: " + entry.getName());
- Python
tarfile.extractall()withoutfilter="data"(the safe default only from Python 3.14);shutil.unpack_archiveon tar.zipfile.extractallsanitises..and absolute names — not a finding by itself. - Go
archive/zipandarchive/tar: checkfilepath.IsLocal(hdr.Name)and skip or reject symlink entries. - Node: hand-rolled extraction with
adm-zip/unzipper/yauzljoiningentry.path.
Decompression bombs are a resource issue — excluded, except a bomb expanded before any size check on a shared worker by an unauthenticated or low-trust sender (security-hard-exclusions-and-precedents §4).
4. Uploads (CWE-434)
- Where it is stored: under a web root or a directory the server executes from (PHP, JSP, CGI) → upload becomes code. Store outside, under a generated name.
- What name it gets: the client filename used in the path → traversal (section 1). Use a server-generated id; keep the original name only as metadata.
- What type it is served as: an uploaded
.htmlor.svgserved inline from the app's own origin is stored XSS. Serve user files withContent-Disposition: attachment, a fixed safeContent-Type,X-Content-Type-Options: nosniff, or from a separate cookieless domain. - How the type is checked: the client's
Content-Typeand the extension are claims. Allowlist extensions and verify the magic bytes when the type decides how the file is processed (image libraries, document parsers). - Size: unlimited size is resource exhaustion — excluded; do not report it.
5. Serving and Static Routes
- A static mapping widened to the project root exposes
.env,.git/, source and backups. - A download endpoint that takes a full path or an object-storage key from the client — combine with access-control-and-idor: can user A fetch
tenants/B/report.pdf? - Signed URLs whose key is built from user input without the tenant prefix.
6. Temporary Files (CWE-377)
Predictable names in a shared temp directory (/tmp/export- + userId) let a
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл path-traversal-and-file-handling?
Use when the diff builds a filesystem path from input, extracts an archive, accepts an upload, serves a file or writes a temp file - traversal, symlinks, zip-slip, upload type and served content-type
Как установить скилл path-traversal-and-file-handling?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл path-traversal-and-file-handling запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…