What is CWE-73: External Control of File Name or Path?+
CWE-73: External Control of File Name or Path is a Common Weakness Enumeration (CWE) entry maintained by MITRE. The product allows user input to control or influence paths or file names that are used in filesystem operations. This could allow an attacker to access or modify system files or other files that are critical to the application. Path manipulation errors occur when the following two conditions are met: 1. An attacker can specify a path used in an operation on the filesystem. 2. By specifying the resource, the attacker gains a capability that would not otherwise be permitted. For example, the program may give the attacker the ability to overwrite the specified file or run with a configuration controlled by the attacker.
What are the security consequences of External Control of File Name or Path?+
If exploited, CWE-73 (External Control of File Name or Path) it can compromise Integrity, Confidentiality and Availability, leading to outcomes such as Read Files or Directories, Modify Files or Directories, Execute Unauthorized Code or Commands, DoS: Crash, Exit, or Restart and DoS: Resource Consumption (Other).
How do you prevent or mitigate External Control of File Name or Path?+
Recommended mitigations for CWE-73 include: When the set of filenames is limited or known, create a mapping from a set of fixed input values (such as numeric IDs) to the actual filenames, and reject all other inputs. For example, ID 1 could map to "inbox.txt" and ID 2 could map to "profile.txt". Features such as the ESAPI AccessReferenceMap provide this capability. Run your code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict all access to files within a particular directory. Examples include the Unix chroot jail and AppArmor. In general, managed code may provide some protection. This may not be a feasible solution, and it only limits the impact to the operating system; the rest of your application may still be subject to compromise. Be careful to avoid CWE-243 and other weaknesses related to jails. 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 is External Control of File Name or Path detected?+
CWE-73 can be detected using Automated Static Analysis. Combining automated tooling with manual review typically yields the best coverage.
Which programming languages are affected by External Control of File Name or Path?+
CWE-73 commonly affects Not Language-Specific. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.
What are real-world examples of External Control of File Name or Path?+
MITRE documents real CVEs mapped to CWE-73, including CVE-2022-45918, CVE-2008-5748 and CVE-2008-5764. You can look up the full details of each CVE, including CVSS scores and remediation guidance, on our CVE Lookup tool.
What is the difference between a CWE and a CVE?+
A CWE (Common Weakness Enumeration) like CWE-73 describes a category of software weakness — the underlying flaw type. A CVE (Common Vulnerabilities and Exposures) identifies a specific, real-world vulnerability in a particular product. In short, a CWE is the kind of mistake, and a CVE is an instance of that mistake being found in software.