[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7CSNZE15JGMBC8HJ02P7NZY":3,"skill-same:01M7CSNZE15JGMBC8HJ02P7NZY":50},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":27,"commitSha":28,"skillDirectory":29,"forksCount":30,"repositoryHtmlUrl":31,"repositoryHomepageUrl":32,"ownerHtmlUrl":33,"ownerBlogUrl":6,"ownerDescription":34,"updatedAt":35,"install":36,"resources":49},"01M7CSNZE15JGMBC8HJ02P7NZY","path-traversal-and-file-handling",null,"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","makifbaysal\u002Ftasktrooper","makifbaysal","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F25031940?v=4","01M7CRG3ZCSYZSSEVDMW3DEYC8","Mehmet Akif Baysal","01M7CRG401FJ8YAXH5ER730XYV",122,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fsecurity-agent\u002Fskills\u002Fpath-traversal-and-file-handling\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: path-traversal-and-file-handling\ncategory: security\ndescription: 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\ntech_stack: Web & API\nsource: original; informed by trailofbits\u002Fskills (CC BY-SA 4.0, ideas only, own wording); OWASP Top 10:2025 A01 and CWE cited by name only\n---\n# Path Traversal and File Handling\n\n## Overview\n\n`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.\n\n**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.\n\n## 1. Traversal (CWE-22)\n\n```go\n\u002F\u002F ❌ HasPrefix on a cleaned string: \"\u002Fsrv\u002Ffiles-private\u002Fx\" passes for base \"\u002Fsrv\u002Ffiles\",\n\u002F\u002F    and a symlink inside base escapes entirely\np := filepath.Join(base, name)\nif !strings.HasPrefix(filepath.Clean(p), base) { return errBadPath }\nf, _ := os.Open(p)\n\n\u002F\u002F ✅ Go 1.24+: the root confines every lookup, symlinks included\nroot, _ := os.OpenRoot(base)\nf, err := root.Open(name)\n\u002F\u002F older Go: reject non-local names first — filepath.IsLocal(name) (Go 1.20+)\n```\n\n```java\n\u002F\u002F ❌ normalize() is lexical; a symlink under base still escapes\nPath p = base.resolve(name).normalize();\nif (!p.startsWith(base)) throw new SecurityException();\n\n\u002F\u002F ✅ compare real paths (Path.startsWith is component-wise, String.startsWith is not)\nPath real = base.resolve(name).toRealPath();\nif (!real.startsWith(base.toRealPath())) throw new SecurityException();\n```\n\n```python\n# ❌ os.path.join drops base entirely when name is absolute (\"\u002Fetc\u002Fpasswd\")\npath = os.path.join(UPLOAD_DIR, name)\n\n# ✅\nroot = Path(UPLOAD_DIR).resolve()\npath = (root \u002F name).resolve()\nif not path.is_relative_to(root):   # Python 3.9+\n    abort(400)\n```\n\n```ts\n\u002F\u002F ❌ startsWith without a trailing separator; \"\u002Fdata\u002Fapp-secrets\" passes for \"\u002Fdata\u002Fapp\"\nconst p = path.resolve(base, name); if (!p.startsWith(base)) throw ...\n\u002F\u002F ✅\nconst p = path.resolve(base, name); if (!p.startsWith(base + path.sep)) throw ...\n\u002F\u002F and for symlinks: fs.realpathSync(p) before the check\n```\n\nFlask: `send_from_directory`. Express: `res.sendFile(name, { root: base })` (rejects escaping paths) rather than `res.sendFile(path.join(base, name))`.\n\n## 2. Symlinks (CWE-59)\n\nLexical 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`\u002F`EvalSymlinks`\u002F`toRealPath`, or open with `O_NOFOLLOW` \u002F `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.\n\n## 3. Archive Extraction (zip-slip)\n\nArchive entry names are attacker input: `..\u002F..\u002F.ssh\u002Fauthorized_keys`, absolute paths, and symlink entries that point outside and are then written through.\n\n```java\n\u002F\u002F ❌\nFile out = new File(destDir, entry.getName());\nFiles.copy(zis, out.toPath());\n\u002F\u002F ✅\nPath out = destDir.resolve(entry.getName()).normalize();\nif (!out.startsWith(destDir)) throw new IOException(\"bad entry: \" + entry.getName());\n```\n\n- Python `tarfile.extractall()` without `filter=\"data\"` (the safe default only from Python 3.14); `shutil.unpack_archive` on tar. `zipfile.extractall` sanitises `..` and absolute names — not a finding by itself.\n- Go `archive\u002Fzip` and `archive\u002Ftar`: check `filepath.IsLocal(hdr.Name)` and skip or reject symlink entries.\n- Node: hand-rolled extraction with `adm-zip`\u002F`unzipper`\u002F`yauzl` joining `entry.path`.\n\nDecompression 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).\n\n## 4. Uploads (CWE-434)\n\n- **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.\n- **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.\n- **What type it is served as:** an uploaded `.html` or `.svg` served inline from the app's own origin is stored XSS. Serve user files with `Content-Disposition: attachment`, a fixed safe `Content-Type`, `X-Content-Type-Options: nosniff`, or from a separate cookieless domain.\n- **How the type is checked:** the client's `Content-Type` and the extension are claims. Allowlist extensions and verify the magic bytes when the type decides how the file is processed (image libraries, document parsers).\n- **Size:** unlimited size is resource exhaustion — excluded; do not report it.\n\n## 5. Serving and Static Routes\n\n- A static mapping widened to the project root exposes `.env`, `.git\u002F`, source and backups.\n- 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\u002FB\u002Freport.pdf`?\n- Signed URLs whose key is built from user input without the tenant prefix.\n\n## 6. Temporary Files (CWE-377)\n\nPredictable names in a shared temp directory (`\u002Ftmp\u002Fexport-` + userId) let a local attacker pre-create or symlink the file. Use `os.CreateTemp`, `tempfile.mkstemp`\u002F`NamedTemporaryFile`, `Files.createTempFile`, `fs.mkdtemp`. Only a finding when other local users or tenants share the machine.\n\n## Severity Guide\n\nReading arbitrary server files or writing outside the intended directory → HIGH; CRITICAL when the write reaches code, config or `authorized_keys`, or the read reaches credentials. Inline-served HTML\u002FSVG upload → HIGH (stored XSS).\n\n## Common Mistakes\n\n- Reporting traversal where the value is a server constant, an enum, or a UUID parsed before use.\n- Reporting path traversal in browser or mobile client code — it is the user's own filesystem.\n- Trusting `filepath.Clean`, `path.normalize` or `os.path.normpath` as a containment check.\n- Missing that Flask's default `\u003Cname>` converter rejects `\u002F`, while `\u003Cpath:name>` accepts it.\n\n## Red Flags\n\n- `Join`\u002F`resolve` followed by a string `startsWith`\u002F`HasPrefix` check.\n- `entry.getName()`, `hdr.Name`, `member.name` used to build an output path.\n- `extractall(` with no `filter=` on Python \u003C 3.14.\n- An upload handler that writes `file.originalname` \u002F `filename` into the path.\n- `Content-Type` taken from the upload when serving it back.\n\n## References (names and links only)\n\nCWE-22, CWE-59, CWE-367, CWE-377, CWE-434 at [cwe.mitre.org](https:\u002F\u002Fcwe.mitre.org\u002F) · [OWASP Top 10:2025 A01 Broken Access Control](https:\u002F\u002Fowasp.org\u002FTop10\u002F2025\u002F) · [ASVS 5.0 V5 File Handling](https:\u002F\u002Fgithub.com\u002FOWASP\u002FASVS\u002Ftree\u002Fmaster\u002F5.0\u002Fen)\n","# Path Traversal and File Handling\n\n## Overview\n\n`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.\n\n**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.\n\n## 1. Traversal (CWE-22)\n\n```go\n\u002F\u002F ❌ HasPrefix on a cleaned string: \"\u002Fsrv\u002Ffiles-private\u002Fx\" passes for base \"\u002Fsrv\u002Ffiles\",\n\u002F\u002F    and a symlink inside base escapes entirely\np := filepath.Join(base, name)\nif !strings.HasPrefix(filepath.Clean(p), base) { return errBadPath }\nf, _ := os.Open(p)\n\n\u002F\u002F ✅ Go 1.24+: the root confines every lookup, symlinks included\nroot, _ := os.OpenRoot(base)\nf, err := root.Open(name)\n\u002F\u002F older Go: reject non-local names first — filepath.IsLocal(name) (Go 1.20+)\n```\n\n```java\n\u002F\u002F ❌ normalize() is lexical; a symlink under base still escapes\nPath p = base.resolve(name).normalize();\nif (!p.startsWith(base)) throw new SecurityException();\n\n\u002F\u002F ✅ compare real paths (Path.startsWith is component-wise, String.startsWith is not)\nPath real = base.resolve(name).toRealPath();\nif (!real.startsWith(base.toRealPath())) throw new SecurityException();\n```\n\n```python\n# ❌ os.path.join drops base entirely when name is absolute (\"\u002Fetc\u002Fpasswd\")\npath = os.path.join(UPLOAD_DIR, name)\n\n# ✅\nroot = Path(UPLOAD_DIR).resolve()\npath = (root \u002F name).resolve()\nif not path.is_relative_to(root):   # Python 3.9+\n    abort(400)\n```\n\n```ts\n\u002F\u002F ❌ startsWith without a trailing separator; \"\u002Fdata\u002Fapp-secrets\" passes for \"\u002Fdata\u002Fapp\"\nconst p = path.resolve(base, name); if (!p.startsWith(base)) throw ...\n\u002F\u002F ✅\nconst p = path.resolve(base, name); if (!p.startsWith(base + path.sep)) throw ...\n\u002F\u002F and for symlinks: fs.realpathSync(p) before the check\n```\n\nFlask: `send_from_directory`. Express: `res.sendFile(name, { root: base })` (rejects escaping paths) rather than `res.sendFile(path.join(base, name))`.\n\n## 2. Symlinks (CWE-59)\n\nLexical 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`\u002F`EvalSymlinks`\u002F`toRealPath`, or open with `O_NOFOLLOW` \u002F `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.\n\n## 3. Archive Extraction (zip-slip)\n\nArchive entry names are attacker input: `..\u002F..\u002F.ssh\u002Fauthorized_keys`, absolute paths, and symlink entries that point outside and are then written through.\n\n```java\n\u002F\u002F ❌\nFile out = new File(destDir, entry.getName());\nFiles.copy(zis, out.toPath());\n\u002F\u002F ✅\nPath out = destDir.resolve(entry.getName()).normalize();\nif (!out.startsWith(destDir)) throw new IOException(\"bad entry: \" + entry.getName());\n```\n\n- Python `tarfile.extractall()` without `filter=\"data\"` (the safe default only from Python 3.14); `shutil.unpack_archive` on tar. `zipfile.extractall` sanitises `..` and absolute names — not a finding by itself.\n- Go `archive\u002Fzip` and `archive\u002Ftar`: check `filepath.IsLocal(hdr.Name)` and skip or reject symlink entries.\n- Node: hand-rolled extraction with `adm-zip`\u002F`unzipper`\u002F`yauzl` joining `entry.path`.\n\nDecompression 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).\n\n## 4. Uploads (CWE-434)\n\n- **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.\n- **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.\n- **What type it is served as:** an uploaded `.html` or `.svg` served inline from the app's own origin is stored XSS. Serve user files with `Content-Disposition: attachment`, a fixed safe `Content-Type`, `X-Content-Type-Options: nosniff`, or from a separate cookieless domain.\n- **How the type is checked:** the client's `Content-Type` and the extension are claims. Allowlist extensions and verify the magic bytes when the type decides how the file is processed (image libraries, document parsers).\n- **Size:** unlimited size is resource exhaustion — excluded; do not report it.\n\n## 5. Serving and Static Routes\n\n- A static mapping widened to the project root exposes `.env`, `.git\u002F`, source and backups.\n- 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\u002FB\u002Freport.pdf`?\n- Signed URLs whose key is built from user input without the tenant prefix.\n\n## 6. Temporary Files (CWE-377)\n\nPredictable names in a shared temp directory (`\u002Ftmp\u002Fexport-` + userId) let a local attacker pre-create or symlink the file. Use `os.CreateTemp`, `tempfile.mkstemp`\u002F`NamedTemporaryFile`, `Files.createTempFile`, `fs.mkdtemp`. Only a finding when other local users or tenants share the machine.\n\n## Severity Guide\n\nReading arbitrary server files or writing outside the intended directory → HIGH; CRITICAL when the write reaches code, config or `authorized_keys`, or the read reaches credentials. Inline-served HTML\u002FSVG upload → HIGH (stored XSS).\n\n## Common Mistakes\n\n- Reporting traversal where the value is a server constant, an enum, or a UUID parsed before use.\n- Reporting path traversal in browser or mobile client code — it is the user's own filesystem.\n- Trusting `filepath.Clean`, `path.normalize` or `os.path.normpath` as a containment check.\n- Missing that Flask's default `\u003Cname>` converter rejects `\u002F`, while `\u003Cpath:name>` accepts it.\n\n## Red Flags\n\n- `Join`\u002F`resolve` followed by a string `startsWith`\u002F`HasPrefix` check.\n- `entry.getName()`, `hdr.Name`, `member.name` used to build an output path.\n- `extractall(` with no `filter=` on Python \u003C 3.14.\n- An upload handler that writes `file.originalname` \u002F `filename` into the path.\n- `Content-Type` taken from the upload when serving it back.\n\n## References (names and links only)\n\nCWE-22, CWE-59, CWE-367, CWE-377, CWE-434 at [cwe.mitre.org](https:\u002F\u002Fcwe.mitre.org\u002F) · [OWASP Top 10:2025 A01 Broken Access Control](https:\u002F\u002Fowasp.org\u002FTop10\u002F2025\u002F) · [ASVS 5.0 V5 File Handling](https:\u002F\u002Fgithub.com\u002FOWASP\u002FASVS\u002Ftree\u002Fmaster\u002F5.0\u002Fen)\n",{"name":5,"source":24,"category":25,"tech_stack":26,"description":7},"original; informed by trailofbits\u002Fskills (CC BY-SA 4.0, ideas only, own wording); OWASP Top 10:2025 A01 and CWE cited by name only","security","Web & API","main","910394a0b6db9fc8c9a8f36328ec421d3ebd8b38","catalog\u002Fagents\u002Fsecurity-agent\u002Fskills\u002Fpath-traversal-and-file-handling",18,"https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper","https:\u002F\u002Ftasktrooper.ai","https:\u002F\u002Fgithub.com\u002Fmakifbaysal","Senior Software Developer","2026-11-15 04:50:29",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add makifbaysal\u002Ftasktrooper --skill path-traversal-and-file-handling",{"tool":42,"command":43},"bunx","bunx skills add makifbaysal\u002Ftasktrooper --skill path-traversal-and-file-handling",{"tool":45,"command":46},"pnpm","pnpm dlx skills add makifbaysal\u002Ftasktrooper --skill path-traversal-and-file-handling","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fsecurity-agent\u002Fskills\u002Fpath-traversal-and-file-handling\u002FSKILL.md",true,[],[51,57,64,71,78,85],{"skillNo":52,"name":53,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":54,"categories":55,"keywords":56,"publishedAt":19},"01M7CSVEPQW6J6TD6CS2T5FPNZ","visual-craft","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fvisual-craft\u002FSKILL.md",[],[],{"skillNo":58,"name":59,"nameZh":6,"description":60,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":61,"categories":62,"keywords":63,"publishedAt":19},"01M7CSVAQG91ETHQ0HBNZDG5FR","ux-copy","Use when you write any words a user reads in a mockup or a hand-off - content language and voice, buttons, labels, errors, empty states, confirmations, numbers and dates, and the longest-string check","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fux-copy\u002FSKILL.md",[],[],{"skillNo":65,"name":66,"nameZh":6,"description":67,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":19},"01M7CSV6H0J38659NDXHJQ8396","screen-mockup-html","Use when you draw screens as the design task's HTML mockup - ONE canvas document holding every screen and every variant side by side, the sanitizer-safe recipe, phone and wide frames, the states grid, static control states, and the loopback self-check with screenshots at 375, 768 and 1440 attached to the task","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fscreen-mockup-html\u002FSKILL.md",[],[],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":19},"01M7CSV3JFRF3BM3XK52M7YEYR","performance-awareness","How the performance score moves for your role. Use when the score context shows a declining trend, or before handing off work you have not self-checked against every criterion.","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fperformance-awareness\u002FSKILL.md",[],[],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":19},"01M7CSTZDH00YRF5SCT7BRT9QD","design-variants","Use when a screen design needs variants - how many, variants as side-by-side rows on the one canvas, what makes two variants genuinely different, recommending one, how the human's choice is read, and narrowing to the chosen one in revision","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fdesign-variants\u002FSKILL.md",[],[],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":19},"01M7CSTV6P3SM3PAE28DB0RF77","design-system-authoring","Use when you derive, change or extend a design system - where tokens live per stack, the DTCG token tree, role-based names for both themes, base vs layer vs drift, the DESIGN.md section order, the inventory format, the contrast check and the lint every proposal returns","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fdesign-system-authoring\u002FSKILL.md",[],[]]