Unrestricted File Upload

The application accepts uploaded files without properly restricting their type, content and storage, so dangerous files can be run by the server or served to users.

SeverityHigh
CVSS 3.18.8 CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H Open in the calculator
CVSS 4.08.7 CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N Open in the calculator
CWECWE-434: Unrestricted Upload of File with Dangerous Type
OWASP Top 10A06:2025 Insecure Design
MITRE ATT&CKT1190 Exploit Public-Facing Application, T1505.003 Web Shell
CategoryInput Validation

Description

The application lets users upload files but does not adequately control what is accepted and how it is stored and served. Typical gaps are relying on the file extension or the Content-Type header sent by the client, checking extensions against a blocklist that misses alternatives such as .phtml, .phar or other script extensions the server will run, keeping the user's file name, and storing files inside the web root where the server executes scripts.

Where an uploaded script can be executed, an attacker can run arbitrary code on the server with the web server's privileges, typically through a web shell, giving them the application's data, its secrets and a foothold in the network. Files that change server behaviour, such as .htaccess or web.config, and HTML or SVG files served from the application's own origin, are dangerous even where scripts cannot run: uploaded HTML or SVG files can deliver stored cross-site scripting to other users, and the application can be used to host malware or phishing content under the organisation's domain. Most upload functions require an account, which reduces the exposure but not the impact.

The weakness typically shows itself on a test when a file with an executable extension, or one that passes the checks through a double extension, a change of case, an altered content type or an image header placed in front of script code, is accepted and its stored address can be requested. Running a harmless marker script confirms code execution, and an uploaded HTML or SVG file that runs script in the browser confirms stored cross-site scripting. Missing size limits, unsafe processing of archives and documents, and file names containing traversal sequences are related findings in the same function. The issue is largely found manually, with scanner support for common bypasses.

Remediation

Control what is accepted, what it is called, where it is kept and how it is served:

  • Allow only the file types the function needs, using an allowlist of extensions, and check that each file's content matches its type. Re-encode images where practical, which removes embedded content.
  • Ignore the user's file name: generate a random name on the server and add the extension from the allowlist.
  • Store uploads outside the web root, or in separate object storage, and serve them through a handler that sets an explicit Content-Type, Content-Disposition: attachment and X-Content-Type-Options: nosniff. Serve user content from a separate domain where it must be displayed in the browser.
  • Where files must stay under the web root, disable script execution and configuration overrides for the upload directory, for example by removing script handler mappings and setting AllowOverride None in Apache.
  • Enforce size limits, scan uploads for malware, and process documents and archives with up-to-date libraries.

Confirm the fix by repeating the original uploads, including bypass variants, and checking that they are rejected or stored in a way that cannot be executed or rendered.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Web Applications Findings

Every Web Applications finding