Group
  • Security

    Secure my file upload handling

    Validates file types by content not extension, caps sizes, renames uploads, and keeps them outside the web root.

    • Improve quality
    • Debug & fix
    • Intermediate
    • General

Free Prompt

Audit and harden my app's file upload handling. Find every endpoint that accepts file uploads (avatars, attachments, imports, media). Apply these protections to each: validate the file's actual content (magic bytes or a library that sniffs MIME types) instead of trusting the extension or the client-supplied Content-Type; enforce a maximum file size; generate a random server-side filename instead of using the uploader's original name; store uploads outside the public web root or in object storage so they can never be executed as code; and serve them with a safe Content-Type and Content-Disposition: attachment where appropriate. Do not break existing uploads or change the allowed file types without flagging it to me first. If the app resizes or processes images, make sure the processing library is current and errors on malformed files instead of crashing. Show me each upload endpoint, what it accepted before, and what it accepts now. Give me verification steps: how to attempt uploading an executable file or a file with a fake extension and confirm it's rejected or neutralized.

What This Does / How This Helps

Hardens every upload endpoint so users can't push executable files, oversized payloads, or files lying about their type into your app. Uploads are a direct path to server compromise when they trust the file extension. A renamed script uploaded as a profile photo, stored in the web root, and served back can execute on your server or attack other users. Content-based validation, size caps, random filenames, and storage outside the web root close that path. You'll see what each endpoint accepted before and after, plus attack-style verification steps like uploading a disguised executable and watching it fail.

Want to skip doing this by hand?

Fortivibe audits your app for all of the areas these prompts cover (and more).

See What We Check

Related Prompts