134
Scope Impact Likelihood
Confidentiality
Availability
Execute Unauthorized Code or Commands
The application can operate on unexpected files. This
may violate integrity if the filename is written to, or if the
filename is for a program or other form of executable code.
Availability DoS: Crash, Exit, or Restart
DoS: Resource Consumption (Other)
The application can operate on unexpected files.
Availability can be violated if the attacker specifies an
unexpected file that the application modifies. Availability
can also be affected if the attacker specifies a filename for
a large file, or points to a special device or a file that does
not have the format that the application expects.
Detection Methods
Automated Static Analysis
The external control or influence of filenames can often be detected using automated static
analysis that models data flow within the product. Automated static analysis might not be able
to recognize when proper input validation is being performed, leading to false positives - i.e.,
warnings that do not have any security consequences or require any code changes.
Potential Mitigations
Phase: Architecture and Design
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.
Phase: Architecture and Design
Phase: Operation
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.
Phase: 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.
Phase: Implementation
Strategy = Input Validation
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
CWE Version 4.14
CWE-73: External Control of File Name or Path
CWE-73: External Control of File Name or Path