File upload is one of the first features people ask an AI tool to add: avatars, documents, receipts. The generated code usually works. It often skips the checks that stop an upload from becoming a way in. Here are six checks, and a test for each.
1. Check the type on the server, not just in the browser
accept="image/*" only changes the file picker. A stranger can send any file with a direct request. Validate the content type and the file signature (magic bytes) on the server, and keep an allow-list of types you actually need.
Test: upload a .txt file renamed to .png. If it is accepted and served back as an image path, the check is client-side only.
2. Limit size
No limit means one user can fill your storage or your bill. Set a maximum on the server and in your storage bucket policy.
Test: try a file ten times your intended limit.
3. Never trust the filename
Names like ../../x or shell.php should never decide where a file is stored. Generate your own random name and keep the original only as display text.
4. Do not serve uploads from the same origin as your app
An HTML or SVG file served from your own domain can run script in your users' sessions. Serve uploads from a separate domain or storage host, with Content-Disposition: attachment and X-Content-Type-Options: nosniff for anything that is not an image you checked.
Test: upload an SVG with a script tag and open its URL. If the script runs on your app's domain, that is stored XSS.
5. Check who can read the file
A public bucket with guessable paths exposes every user's documents. For Supabase Storage or Firebase Storage, check the bucket is private unless the files are meant to be public, and that policies tie access to the owner.
Test: open a file URL signed out, then as a second test account.
6. Check who can write
Make sure only signed-in users can upload and that they can only overwrite their own files.
Test: with no session, call the upload endpoint directly.
What an outside check can and cannot see
A signed-out scan can notice a public bucket listing or an open upload route. It cannot see what your server does with a file after login. Use the tests above with two accounts for that.
Check your own app from the outside, free. Run the free ProofForge scan on your live URL. No account needed for the first scan. It looks at your public site the way a stranger would and says pass, fail or inconclusive, so you know what is confirmed and what it could not see. One-time reports start at $9: see pricing. Building with an AI agent? There is an MCP server so it can check before it deploys.
