wowprompt

Secure file upload handler with type checks and size limits

Writes or reviews a file upload endpoint so it accepts only the files it should: real type checks from file content, size and count limits, safe random file names, storage outside the web root and no way to run an uploaded file. Use it for profile pictures, document uploads, invoices and any form that takes attachments.

An upload handler with content-based type detection, size limits and random names, a security checklist with pass or fail marks, and tests for rejected files
The output this prompt produced, unedited.

The prompt

What to give

  • Language and framework: [e.g. Python with FastAPI, or PHP 8.3 without a framework]
  • What users upload: [e.g. profile photos as JPEG, PNG or WebP up to 5 MB; invoices as PDF up to 10 MB]
  • Where files go: [e.g. a local folder, an S3-compatible bucket, a separate media domain]
  • Current code, if any: [paste, or new]
  • Who can download a file afterwards: [e.g. anyone with the link, or only the owner when signed in]

Check and build each point

  1. Size limit enforced by the server and the web server, before the whole file is read into memory.
  2. Type detected from the file's first bytes, not from the extension or the browser's content type, against an allow-list.
  3. Images decoded and re-encoded, which strips metadata such as GPS location and drops any hidden payload.
  4. The stored name is random; the original name is saved only as data and cleaned before display.
  5. Files stored outside the web root, or on a domain or bucket that cannot execute scripts and serves files with a fixed content type and nosniff.
  6. Downloads of private files go through an access check or a short-lived signed URL.
  7. A limit on uploads per user per hour.
  8. PDFs and office files are flagged for a virus scan step, with the hook shown even if no scanner is set up yet.
  9. Errors tell the user what was wrong (too large, wrong type) without exposing paths.

Output format

  1. Checklist: | Point | Pass, fail or not applicable | Note |, if existing code was given.
  2. The complete handler code.
  3. Web server or bucket settings needed, such as the body size limit and headers.
  4. Tests: a valid file, an oversized file, a renamed executable with an image extension, an image with GPS metadata, a double extension such as photo.jpg.php.

Guardrails

  • Never trust the extension or the client's content type alone.
  • Never build a file path from user input.
secure file uploadfile upload validationmime type checkupload securityimage upload handlerweb application security

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity