Weakness · High
CWE-646: Reliance on File Name or Extension of Externally-Supplied File
What it is
The product allows a file to be uploaded, but it relies on the file name or extension of the file to determine the appropriate behaviors. This could be used by attackers to cause the file to be misclassified and processed in a dangerous fashion.
- Severity (our rating)
- High
- Likelihood of exploit
- High
- Introduced during
- Architecture and Design, Implementation, Operation
- Exploited in the wild
- No CVE in CISA's catalog
In more detail
An application might use the file name or extension of a user-supplied file to determine the proper course of action, such as selecting the correct process to which control should be passed, deciding what data should be made available, or what resources should be allocated. If the attacker can cause the code to misclassify the supplied file, then the wrong action could occur. For example, an attacker could supply a file that ends in a ".php.gif" extension that appears to be a GIF image, but would be processed as PHP code. In extreme cases, code execution is possible, but the attacker could also cause exhaustion of resources, denial of service, exposure of debug or system data (including application source code), or being bound to a particular server side process. This weakness may be due to a vulnerability in any of the technologies used by the web and application servers, due to misconfiguration, or resultant from another flaw in the application itself.
What an attacker can do
- Read Application Data (Confidentiality)
- DoS: Crash, Exit, or Restart (Availability)
- Gain Privileges or Assume Identity (Access Control)
How to prevent it
Architecture and Design
- Make decisions on the server side based on file content and not on file name or extension.
H2 Security
Found it in your code?
We review where it appears, fix it with your team, and check it was not already used against you.
Talk to our teamT Academy
Stop writing it in the first place
Learn to build software and systems without weaknesses like this one, with practice on real hosts in your browser, every objective checked on the machine.
Start freeSource: MITRE Common Weakness Enumeration, CWE version 4.19.1. CWE is a trademark of The MITRE Corporation.