Skip to content
Web Design & Development

Secure File Uploads, Done Properly

Accepting files from users, such as images, documents and CVs, without letting attackers upload malware or executable files to your server.

MediaScaleUp Editorial Team 2 min read 11 views
Secure File Uploads, Done Properly

The key figures

Validation
check file type by content, not only by extension
Storage
store uploads outside the web root or in separate object storage
Names
generate new file names instead of using the user's
Limits
enforce file size and count limits

Why this is worth getting right

Upload features are a frequent route to server compromise and stored malware, so they need several layers of defense.

Do this, not that

Do

  • Allowlist the file types you accept
  • Rename files and store them outside the web root
  • Scan uploads for malware where risk warrants
  • Serve files with safe content types and download headers
  • Keep uploaded files private unless they must be public

Don’t

  • Executable files stored in public folders
  • Trusting the file extension or MIME type sent by the browser
  • Unlimited upload sizes
  • Serving user uploads from the main domain without restrictions

When to bring in help

Our advice Bring in help when adding upload features, or when a security review flags upload handling.

Where this comes from

The figures and practices above come from the sources listed.

Working on something like this?

We take on Web Design & Development work for teams who want it done once, properly. Tell us what you are building and we will tell you honestly whether we are the right studio for it. Start a project.

Where to go next

Spotted something wrong? Report an error on this page. We correct on the page and say what changed.

All services

The work behind this article, and what it costs.

MediaScaleUp Editorial Team

Articles here are researched, written and checked by the MediaScaleUp studio team before they are published, and dated when they are reviewed.

Keep reading

More in Web Design & Development