OOmnistu

Blog / Engineering Playbooks

Engineering Playbooks

Letting users upload files safely: a checklist for app teams

Review file upload restrictions, validation, storage and access controls before accepting images or documents from users.

OOmnistu
Reviewed 2026-11-16 · 4 min read
Validate everything
Allow only needed extensions, validate the file type, and never trust the Content-Type header.
Store away from the webroot
OWASP's priority order: a different host, then outside the webroot, then inside with write-only permissions.
Scanning is extra
An additional check, not permission to run an arbitrary file. No size-limit figures: the source gives none.

All wording checked against the OWASP File Upload Cheat Sheet linked in Sources.

Profile photos, CVs, documents, videos: file upload is common and risky. OWASP's File Upload Cheat Sheet says the app must be able to fend off bogus and malicious files. We read it in full on 15 November 2026 and not the CWE, vendor or Java code references. We summarise it as a checklist and give no code.

What can go wrong

OWASP lists:

OWASP says there is no silver bullet: use several techniques together.

The sheet's summary principles

Allow only needed extensions; apply input validation before checking the extension; validate the file type and do not trust the Content-Type header; replace the filename with an application-generated one; limit filename length and characters; limit file size; allow only authorised users to upload; store files on a different server or at least outside the webroot; serve public files through a handler that maps an ID to a file; scan with antivirus or a sandbox where available; apply Content Disarm and Reconstruct (CDR) for types like PDF and DOCX where applicable; keep libraries configured and updated; protect the upload from CSRF.

Validating the file

Double extensions

.jpg.php

Null bytes

Decode the filename before checking the extension.

Case changes

.pHp

Alternative extensions

.phtml, .php5 - same interpreter, different name.

Alternate data streams

Reject any filename with a colon.

Bad regexes

Badly tested regular expressions miss tricks. An allowlist is the strong option.

Where to store files, in order of OWASP's priority

  1. On a different host.
  2. Outside the webroot with administrative access only.
  3. Inside the webroot with write-only permissions and proper read controls. Storing files in a database is possible but OWASP advises it only when a DBA is on the team and it proves an improvement, since it brings performance, backup and SQL injection concerns. Also, attackers may upload server configuration files (such as .htaccess or web.config); as a second layer, disable per-directory configuration overrides on upload directories.
  1. On a different host.
  2. Outside the webroot, with administrative access only.
  3. Inside the webroot with write-only permissions and proper read controls.
  4. In a database - possible, but OWASP advises it only when a DBA is on the team and it proves an improvement.

Who and how much

Questions for your team

Related: input validation basics, CSRF prevention basics, API rate limiting and resource limits, XSS prevention.

Limits

One OWASP page, read in full. Referenced articles (CWE-434, Microsoft, Java code) unread. No figures for size limits are given by the source, and we give none. Legal duties about hosted content depend on your place and product; ask counsel.

By Omnistu.

Sources

Previous
Error handling without leaking details to attackers