{"success":true,"name":"treat-every-file-upload-as-hostile-until-proven-safe","description":"Adding a feature where users upload files or images","category":"ai-brimind","path":"ai-brimind/treat-every-file-upload-as-hostile-until-proven-safe/SKILL.md","file":"SKILL.md","content":"---\nname: treat-every-file-upload-as-hostile-until-proven-safe\ndescription: \"Adding a feature where users upload files or images\"\n---\n\n# Treat Every File Upload as Hostile Until Proven Safe\n\n## When to use\nYou are writing the code that receives, stores, or serves a file uploaded by a user (avatar, document, attachment, import).\n\n## Example request\nTrusting the file extension or the browser's content-type → attackers rename a script to photo.jpg; check the real file type from the file's bytes (magic-number validation). Saving uploads with the user's original filename → names like '../../config' or 'index.php' cause overwrites or execution; generate your own random filename (path and execution safety). Storing uploads inside the app's public code folder → the server may execute an uploaded script; store files outside the web root or in object storage like S3 (separate storage from code). Accepting any file size → one giant upload fills the disk or memory; enforce a size limit before processing (resource protection).\n\n## Instructions\nAct like a developer who knows file upload is one of the fastest paths from 'small feature' to 'server compromised'. Before writing the handler, define exactly what is allowed: which file types, verified by inspecting the file's actual bytes (not the extension, not the client-sent content-type), and the maximum size, enforced before the file is fully processed. Then control everything about how the file is stored: generate your own safe random filename and never reuse the user's name in a path; store files outside the executable web root, ideally in dedicated object storage or the platform's upload service, so an uploaded file can never run as code; and serve files back with headers that force download or safe display rather than execution. Check whether the framework or platform already provides a hardened upload mechanism and prefer it over hand-written handling. For images, prefer re-encoding (resizing/converting) so hidden payloads are destroyed. If any step is unclear — where the web root is, what the platform executes, what types are truly needed — investigate or ask before coding. Only finish once type, size, name, storage location, and serving behavior are each explicitly handled, and explain how this blocks real attacks (uploaded shells, path traversal, disk exhaustion) instead of just accepting the happy-path photo.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #519\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}