According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Web Application Scanner Web Services Scanner Database Scanners
Unrestricted Upload of File with Dangerous Type
This vulnerability occurs when an application accepts file uploads without properly restricting the file types, allowing attackers to upload and execute malicious files on the server.
What is CWE-434?
Real-world CVEs caused by CWE-434
-
PHP-based FAQ management app does not check the MIME type for uploaded images
-
Web-based mail product stores ".shtml" attachments that could contain SSI
-
PHP upload does not restrict file types
-
upload and execution of .php file
-
upload file with dangerous extension
-
program does not restrict file types
-
improper type checking of uploaded files
-
Double "php" extension leaves an active php extension in the generated filename.
Step-by-step attacker path
- 1
The following code intends to allow a user to upload a picture to the web server. The HTML code that drives the form on the user end has an input field of type "file".
- 2
Once submitted, the form above sends the file to upload_picture.php on the web server. PHP stores the file in a temporary location until it is retrieved (or discarded) by the server side code. In this example, the file is moved to a more permanent pictures/ directory.
- 3
The problem with the above code is that there is no check regarding type of file being uploaded. Assuming that pictures/ is available in the web document root, an attacker could upload a file with the name:
- 4
Since this filename ends in ".php" it can be executed by the web server. In the contents of this uploaded file, the attacker could use:
- 5
Once this file has been installed, the attacker can enter arbitrary commands to execute using a URL such as:
Vulnerable PHP
Once submitted, the form above sends the file to upload_picture.php on the web server. PHP stores the file in a temporary location until it is retrieved (or discarded) by the server side code. In this example, the file is moved to a more permanent pictures/ directory.
```
// Define the target location where the picture being*
*// uploaded is going to be saved.*
$target = "pictures/" . basename($_FILES['uploadedfile']['name']);
*// Move the uploaded file to the new location.*
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target))
{
```
echo "The picture has been successfully uploaded.";
}
else
{
echo "There was an error uploading the picture, please try again.";
} The problem with the above code is that there is no check regarding type of file being uploaded. Assuming that pictures/ is available in the web document root, an attacker could upload a file with the name:
malicious.php Secure HTML
The following code intends to allow a user to upload a picture to the web server. The HTML code that drives the form on the user end has an input field of type "file".
<form action="upload_picture.php" method="post" enctype="multipart/form-data">
Choose a file to upload:
<input type="file" name="filename"/>
<br/>
<input type="submit" name="submit" value="Submit"/>
</form> How to prevent CWE-434
- Architecture and Design Generate a new, unique filename for an uploaded file instead of using the user-supplied filename, so that no external input is used at all.[REF-422] [REF-423]
- Architecture and Design When the set of acceptable objects, such as filenames or URLs, is limited or known, create a mapping from a set of fixed input values (such as numeric IDs) to the actual filenames or URLs, and reject all other inputs.
- Architecture and Design Consider storing the uploaded files outside of the web document root entirely. Then, use other mechanisms to deliver the files dynamically. [REF-423]
- Implementation Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue." Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright. For example, limiting filenames to alphanumeric characters can help to restrict the introduction of unintended file extensions.
- Architecture and Design Define a very limited set of allowable extensions and only generate filenames that end in these extensions. Consider the possibility of XSS (CWE-79) before allowing .html or .htm file types.
- Implementation Ensure that only one extension is used in the filename. Some web servers, including some versions of Apache, may process files based on inner extensions so that "filename.php.gif" is fed to the PHP interpreter.[REF-422] [REF-423]
- Implementation When running on a web server that supports case-insensitive filenames, perform case-insensitive evaluations of the extensions that are provided.
- Architecture and Design For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server.
How to detect CWE-434
According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Fuzz Tester Framework-based Fuzzer
According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Focused Manual Spotcheck - Focused manual analysis of source Manual Source Code Review (not inspections)
According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Source code Weakness Analyzer Context-configured Source Code Weakness Analyzer
According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Formal Methods / Correct-By-Construction ``` Cost effective for partial coverage: ``` Inspection (IEEE 1028 standard) (can apply to requirements, design, source code, etc.)
Plexicus auto-detects CWE-434 and opens a fix PR in under 60 seconds.
Codex Remedium scans every commit, identifies this exact weakness, and ships a reviewer-ready pull request with the patch. No tickets. No hand-offs.
Frequently asked questions
What is CWE-434?
This vulnerability occurs when an application accepts file uploads without properly restricting the file types, allowing attackers to upload and execute malicious files on the server.
How serious is CWE-434?
MITRE rates the likelihood of exploit as Medium — exploitation is realistic but typically requires specific conditions.
What languages or platforms are affected by CWE-434?
MITRE lists the following affected platforms: ASP.NET, PHP, Web Server.
How can I prevent CWE-434?
Generate a new, unique filename for an uploaded file instead of using the user-supplied filename, so that no external input is used at all.[REF-422] [REF-423] When the set of acceptable objects, such as filenames or URLs, is limited or known, create a mapping from a set of fixed input values (such as numeric IDs) to the actual filenames or URLs, and reject all other inputs.
How does Plexicus detect and fix CWE-434?
Plexicus's SAST engine matches the data-flow signature for CWE-434 on every commit. When a match is found, our Codex Remedium agent opens a fix PR with the corrected code, tests, and a one-line summary for the reviewer.
Where can I learn more about CWE-434?
MITRE publishes the canonical definition at https://cwe.mitre.org/data/definitions/434.html. You can also reference OWASP and NIST documentation for adjacent guidance.
Weaknesses related to CWE-434
Incorrect Resource Transfer Between Spheres
This vulnerability occurs when an application incorrectly moves or shares a resource (like data, permissions, or functionality) between…
Exposure of Sensitive Information during Transient Execution
Transient execution vulnerabilities occur when a processor speculatively runs operations that don't officially commit, potentially leaking…
Improper Removal of Sensitive Information Before Storage or Transfer
This vulnerability occurs when an application stores or transmits a resource containing sensitive data without properly cleaning it first,…
Creation of chroot Jail Without Changing Working Directory
This vulnerability occurs when a program creates a chroot jail but fails to change its current working directory afterward. Because the…
Download of Code Without Integrity Check
This vulnerability occurs when an application fetches and runs code from an external source—like a remote server or CDN—without properly…
Reliance on Cookies without Validation and Integrity Checking
This vulnerability occurs when an application uses cookies to make security decisions—like granting access or changing settings—but fails…
Inclusion of Functionality from Untrusted Control Sphere
This weakness occurs when an application integrates executable code, like a library or plugin, from a source it does not fully control or…
Insufficient Type Distinction
This vulnerability occurs when an application fails to properly differentiate between different types of data or objects, leading to…
Interpretation Conflict
An interpretation conflict occurs when two systems process the same data or sequence of events differently, leading one system to make…
Further reading
- MITRE — official CWE-434 https://cwe.mitre.org/data/definitions/434.html
- Dynamic File Uploads, Security and You https://web.archive.org/web/20090208005456/http://shsc.info/FileUploadSecurity
- 8 Basic Rules to Implement Secure File Uploads https://www.sans.org/blog/8-basic-rules-to-implement-secure-file-uploads/
- Top 25 Series - Rank 8 - Unrestricted Upload of Dangerous File Type https://www.sans.org/blog/top-25-series-rank-8-unrestricted-upload-of-dangerous-file-type/
- Least Privilege https://web.archive.org/web/20211209014121/https://www.cisa.gov/uscert/bsi/articles/knowledge/principles/least-privilege
- Automated Source Code Security Measure (ASCSM) http://www.omg.org/spec/ASCSM/1.0/
Don't Let Security
Weigh You Down.
Stop choosing between AI velocity and security debt. Plexicus is the only platform that runs Vibe Coding Security and ASPM in parallel — one workflow, every codebase.