← ClaudeAtlas

file-uploadslisted

Use when a ticket lets users send files — avatars, documents, CSV imports, attachments — or serves them back, and the path must be safe against oversized, malicious, or mis-typed content, store files outside the web root or in object storage, and never trust the client's filename or content type. Invoke for "let users upload X", "add an import", "serve the attachment", or any multipart or presigned-URL work.
tmj-90/gaffer · ★ 1 · Data & Documents · score 70
Install: claude install-skill tmj-90/gaffer
# Handle file uploads and downloads safely An upload is untrusted input that is large, binary, and often stored for years. Limit it before you read it, verify what it really is, write it under a name you chose, atomically, in a place that cannot execute, and serve it back with headers that stop the browser guessing. Source: OWASP File Upload Cheat Sheet; OWASP ASVS 5 V5 (file handling). ## Steps 1. **Use the repo's storage and upload path.** Object storage with presigned URLs, a local store behind an abstraction, or existing multipart middleware. Call `search_lore` for bucket layout, key naming and size limits. Do not add a second storage mechanism. 2. **Authorise and limit before reading.** Check the caller may upload here (the `security-authz` skill) and that the form is CSRF-protected if cookie-authenticated. Enforce a maximum body size at the edge (proxy and framework), a maximum part count, and a request timeout; reject with `413` without buffering. Stream to storage; never hold a whole file in memory. For presigned uploads, sign the exact key, `Content-Type` and size limit (a `content-length-range` POST-policy condition, or a signed `Content-Length` for PUT), with a short expiry. 3. **Validate content, not labels.** Allow-list extensions (after normalising case and rejecting double extensions like `x.jpg.php`, NUL bytes and `:`), check the declared `Content-Type` against the allow-list, then detect the real type from the bytes (mag