All vulnerabilities
CRITICALAppSec

APPSEC-FILE-UPLOAD

Web app · Unrestricted File Upload

Summary

Unrestricted file upload occurs when an application accepts an uploaded file without validating its type or content and stores it inside a web-accessible directory where the server will execute it, letting an attacker upload a script such as a .php or .jsp webshell and request it to run arbitrary code as the web user. At the code level the flaw is trusting client-supplied data (the filename extension or the Content-Type header) instead of verifying actual content, and saving to an executable path; weak filters are also bypassable, for example a regex without an anchoring $ or extension checks that ignore trailing characters. CVE-2017-12615 (disclosed 19 September 2017) is a documented case: Apache Tomcat 7.0.0 to 7.0.79 on Windows with the Default servlet's readonly parameter set to false allowed HTTP PUT uploads, and appending a trailing slash like shell.jsp/ bypassed the extension check, writing a JSP that Tomcat then executed for full remote code execution. This class maps to OWASP A04:2021 Insecure Design and overlaps A05 Security Misconfiguration; CWE-434.

How to avoid it in your code

  • Validate file content by magic bytes and a strict allow-list of extensions, not the client-supplied Content-Type or name.
  • Store uploads outside the web root or in object storage and serve them via a handler that never executes them.
  • Generate server-side random filenames and disable script execution in the upload directory.
  • Disable HTTP PUT and the writable Default servlet (readonly=true) on application servers.
  • Enforce size limits and scan content; reject double extensions, trailing slashes, and null bytes.

References

Related vulnerabilities

All AppSec →