CWE-795: Only Filtering Special Elements at a Specified Location
Weakness ID: 795
Abstraction: Base Structure: Simple
View customized information:
Description
The software receives data from an upstream component, but only accounts for special elements at a specified location, thereby missing remaining special elements that may exist before sending it to a downstream component.
Extended Description
A filter might only account for instances of special elements when they occur:
relative to a marker (e.g. "at the beginning/end of string; the second argument"), or
at an absolute position (e.g. "byte number 10").
This may leave special elements in the data that did not match the filter position, but still may be dangerous.
Relationships
This table shows the weaknesses and high level categories that are related to this weakness. These relationships are defined as ChildOf, ParentOf, MemberOf and give insight to similar items that may exist at higher and lower levels of abstraction. In addition, relationships such as PeerOf and CanAlsoBe are defined to show similar weaknesses that the user may want to explore.
Relevant to the view "Research Concepts" (CWE-1000)
Nature
Type
ID
Name
ChildOf
Base - a weakness
that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
Variant - a weakness
that is linked to a certain type of product, typically involving a specific language or technology. More specific than a Base weakness. Variant level weaknesses typically describe issues in terms of 3 to 5 of the following dimensions: behavior, property, technology, language, and resource.
Variant - a weakness
that is linked to a certain type of product, typically involving a specific language or technology. More specific than a Base weakness. Variant level weaknesses typically describe issues in terms of 3 to 5 of the following dimensions: behavior, property, technology, language, and resource.
This table shows the weaknesses and high level categories that are related to this weakness. These relationships are defined as ChildOf, ParentOf, MemberOf and give insight to similar items that may exist at higher and lower levels of abstraction. In addition, relationships such as PeerOf and CanAlsoBe are defined to show similar weaknesses that the user may want to explore.
Relevant to the view "Software Development" (CWE-699)
Nature
Type
ID
Name
MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.
This table shows the weaknesses and high level categories that are related to this weakness. These relationships are defined as ChildOf, ParentOf, MemberOf and give insight to similar items that may exist at higher and lower levels of abstraction. In addition, relationships such as PeerOf and CanAlsoBe are defined to show similar weaknesses that the user may want to explore.
Relevant to the view "Architectural Concepts" (CWE-1008)
Nature
Type
ID
Name
MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.
The different Modes of Introduction provide information about how and when this weakness may be introduced. The Phase identifies a point in the life cycle at which introduction may occur, while the Note provides a typical scenario related to introduction during the given phase.
Phase
Note
Implementation
REALIZATION: This weakness is caused during implementation of an architectural security tactic.
Common Consequences
This table specifies different individual consequences associated with the weakness. The Scope identifies the application security area that is violated, while the Impact describes the negative technical impact that arises if an adversary succeeds in exploiting this weakness. The Likelihood provides information about how likely the specific consequence is expected to be seen relative to the other consequences in the list. For example, there may be high likelihood that a weakness will be exploited to achieve a certain impact, but a low likelihood that it will be exploited to achieve a different impact.
Scope
Impact
Likelihood
Integrity
Technical Impact: Unexpected State
Demonstrative Examples
Example 1
The following code takes untrusted input and uses a regular expression to filter a "../" element located at the beginning of the input string. It then appends this result to the /home/user/ directory and attempts to read the file in the final resulting path.
(bad code)
Example Language: Perl
my $Username = GetUntrustedInput(); $Username =~ s/^\.\.\///; my $filename = "/home/user/" . $Username; ReadAndSendFile($filename);
Since the regular expression is only looking for an instance of "../" at the beginning of the string, it only removes the first "../" element. So an input value such as:
(attack code)
../../../etc/passwd
will have the first "../" stripped, resulting in:
(result)
../../etc/passwd
This value is then concatenated with the /home/user/ directory:
(result)
/home/user/../../etc/passwd
which causes the /etc/passwd file to be retrieved once the operating system has resolved the ../ sequences in the pathname. This leads to relative path traversal (CWE-22).
Example 2
The following code takes untrusted input and uses a substring function to filter a 3-character "../" element located at the 0-index position of the input string. It then appends this result to the /home/user/ directory and attempts to read the file in the final resulting path.
(bad code)
Example Language: Perl
my $Username = GetUntrustedInput(); if (substr($Username, 0, 3) eq '../') {
$Username = substr($Username, 3);
} my $filename = "/home/user/" . $Username; ReadAndSendFile($filename);
Since the if function is only looking for a substring of "../" between the 0 and 2 position, it only removes that specific "../" element. So an input value such as:
(attack code)
../../../etc/passwd
will have the first "../" filtered, resulting in:
(result)
../../etc/passwd
This value is then concatenated with the /home/user/ directory:
(result)
/home/user/../../etc/passwd
which causes the /etc/passwd file to be retrieved once the operating system has resolved the ../ sequences in the pathname. This leads to relative path traversal (CWE-22).
Content History
Submissions
Submission Date
Submitter
Organization
2009-12-04
CWE Content Team
MITRE
Modifications
Modification Date
Modifier
Organization
2010-06-21
CWE Content Team
MITRE
updated Description
2011-06-01
CWE Content Team
MITRE
updated Common_Consequences
2011-06-27
CWE Content Team
MITRE
updated Common_Consequences
2017-01-19
CWE Content Team
MITRE
updated Relationships
2017-11-08
CWE Content Team
MITRE
updated Modes_of_Introduction, Relationships
2020-02-24
CWE Content Team
MITRE
updated Relationships
2021-03-15
CWE Content Team
MITRE
updated Demonstrative_Examples
More information is available — Please select a different filter.