{"success":true,"name":"validate-file-uploads-type-size-and-name-are-all-hostile","description":"Building any feature where users upload files or images.","category":"ai-brimind","path":"ai-brimind/validate-file-uploads-type-size-and-name-are-all-hostile/SKILL.md","file":"SKILL.md","content":"---\nname: validate-file-uploads-type-size-and-name-are-all-hostile\ndescription: \"Building any feature where users upload files or images.\"\n---\n\n# Validate File Uploads: Type, Size, and Name Are All Hostile\n\n## When to use\nThe system accepts uploaded files, and validation is missing or only checks the file extension the client sent.\n\n## Example request\nA .php file renamed to .jpg passes the extension check → uploaded into a public folder, it executes on the server — extension is not content. No size limit → someone uploads 2GB and fills the disk or freezes the request — unbounded upload. Original filename used for storage → '../../etc/passwd' or a name with quotes breaks paths — attacker-controlled filename.\n\n## Instructions\nAct like a developer who treats every uploaded file as an attack until proven otherwise — its name, its declared type, and its bytes are all attacker-controlled. Enforce four layers: (1) SIZE — hard limit at the server (and web-server level if possible) BEFORE reading the whole body; state the max and reject over it; (2) TYPE — never trust the extension or the client's content-type header; verify the actual content (magic bytes / real image decoding for images) matches an explicit allowlist of accepted types — allowlist, never blocklist; (3) NAME — never use the original filename for storage; generate your own (id + verified extension) and store the original name as display metadata only, neutralizing path tricks and weird characters; (4) LOCATION — store uploads where they can never execute: outside the code directory, served with correct content-type, ideally from a separate path/domain. For images, re-encoding through an image library both verifies and sanitizes. Only proceed once an oversized file, a disguised executable, and a malicious filename are all demonstrably rejected or neutralized.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1166\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}