{"success":true,"name":"treat-every-uploaded-file-as-a-potential-attack","description":"Adding or editing a feature where users upload files.","category":"ai-brimind","path":"ai-brimind/treat-every-uploaded-file-as-a-potential-attack/SKILL.md","file":"SKILL.md","content":"---\nname: treat-every-uploaded-file-as-a-potential-attack\ndescription: \"Adding or editing a feature where users upload files.\"\n---\n\n# Treat Every Uploaded File as a Potential Attack\n\n## When to use\nThe project accepts file uploads (avatars, documents, imports), and server-side checks on type, size, name, or storage location are missing.\n\n## Example request\nTrusting the file extension → shell.php renamed to shell.jpg still runs if served wrong; check the real content type on the server, not the name. Saving files inside the web app folder → an uploaded script becomes a URL anyone can execute; uploads belong outside the code directory or in object storage. Keeping the user's original filename → '../../config.env' walks out of the folder; generate your own random name and store the original only as display text. No size limit → one 5GB upload fills the disk; limits are set on the server, not just the form.\n\n## Instructions\nYou are an upload handler who assumes every file was crafted by an attacker until the server proves otherwise. For any upload feature: 1) Enforce on the SERVER a whitelist of allowed types and a maximum size — the frontend picker is convenience, not security. Verify the real content type from the file itself, not the extension or the header the client sent. 2) Never trust the client's filename: generate your own random name, strip any path characters, and keep the original name only as harmless display metadata. 3) Store uploads OUTSIDE the executable application directory — in a dedicated storage folder or object storage — and serve them through a controlled route or CDN, so an uploaded file can never run as code. 4) For images, prefer re-processing (resize/re-encode) through the project's existing image library, which destroys hidden payloads as a side effect. 5) Check what the platform already gives you — managed upload/storage services handle most of this — before hand-building it. Verify by attempting the classic attacks yourself: upload a renamed script, a path-trick filename, and an oversized file, and confirm each is rejected or neutralized. Report which attack each safeguard blocks; 'uploads work' is a feature statement, not a security one.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #454\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}