{"@ID": "795", "@Name": "Only Filtering Special Elements at a Specified Location", "@Abstraction": "Base", "@Structure": "Simple", "@Status": "Incomplete", "Description": "The product 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.", "Technical_Nuance": {"xhtml:p": ["A filter might only account for instances of special elements when they occur:", "This may leave special elements in the data that did not match the filter position, but still may be dangerous."], "xhtml:ul": {"xhtml:li": ["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\")."]}, "#text_blocks": ["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."]}, "Related_Weaknesses": {"Related_Weakness": {"@Nature": "ChildOf", "@CWE_ID": "791", "@View_ID": "1000", "@Ordinal": "Primary"}}, "Weakness_Ordinalities": {"Weakness_Ordinality": {"Ordinality": "Primary"}}, "Applicable_Platforms": {"Language": {"@Class": "Not Language-Specific", "@Prevalence": "Undetermined"}}, "Modes_Of_Introduction": {"Introduction": {"Phase": "Implementation", "Note": "REALIZATION: This weakness is caused during implementation of an architectural security tactic."}}, "Common_Consequences": {"Consequence": {"Scope": "Integrity", "Impact": "Unexpected State"}}, "Demonstrative_Examples": {"Demonstrative_Example": [{"@Demonstrative_Example_ID": "DX-3", "Intro_Text": "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.", "Example_Code": [{"@Nature": "Bad", "@Language": "Perl", "xhtml:div": {"xhtml:br": [null, null, null], "#text": "my $Username = GetUntrustedInput();$Username =~ s/^\\.\\.\\///;my $filename = \"/home/user/\" . $Username;ReadAndSendFile($filename);"}, "#text_blocks": ["my $Username = GetUntrustedInput();", "$Username =~ s/^\\.\\.\\///;", "my $filename = \"/home/user/\" . $Username;", "ReadAndSendFile($filename);"]}, {"@Nature": "Attack", "xhtml:div": "../../../etc/passwd", "#text_blocks": ["../../../etc/passwd"]}, {"@Nature": "Result", "xhtml:div": "../../etc/passwd", "#text_blocks": ["../../etc/passwd"]}, {"@Nature": "Result", "xhtml:div": "/home/user/../../etc/passwd", "#text_blocks": ["/home/user/../../etc/passwd"]}], "Body_Text": ["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:", "will have the first \"../\" stripped, resulting in:", "This value is then concatenated with the /home/user/ directory:", "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)."]}, {"@Demonstrative_Example_ID": "DX-4", "Intro_Text": "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.", "Example_Code": [{"@Nature": "Bad", "@Language": "Perl", "xhtml:div": {"xhtml:br": [null, null, null], "xhtml:div": {"@style": "margin-left:1em;", "#text": "$Username = substr($Username, 3);"}, "#text": "my $Username = GetUntrustedInput();if (substr($Username, 0, 3) eq '../') {}my $filename = \"/home/user/\" . $Username;ReadAndSendFile($filename);"}, "#text_blocks": ["my $Username = GetUntrustedInput();", "if (substr($Username, 0, 3) eq '../') {", "$Username = substr($Username, 3);", "}", "my $filename = \"/home/user/\" . $Username;", "ReadAndSendFile($filename);"]}, {"@Nature": "Attack", "xhtml:div": "../../../etc/passwd", "#text_blocks": ["../../../etc/passwd"]}, {"@Nature": "Result", "xhtml:div": "../../etc/passwd", "#text_blocks": ["../../etc/passwd"]}, {"@Nature": "Result", "xhtml:div": "/home/user/../../etc/passwd", "#text_blocks": ["/home/user/../../etc/passwd"]}], "Body_Text": ["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:", "will have the first \"../\" filtered, resulting in:", "This value is then concatenated with the /home/user/ directory:", "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)."]}]}, "Mapping_Notes": {"Usage": "Allowed", "Rationale": "This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.", "Comments": "Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.", "Reasons": {"Reason": {"@Type": "Acceptable-Use"}}}, "Content_History": {"Submission": {"Submission_Name": "CWE Content Team", "Submission_Organization": "MITRE", "Submission_Date": "2009-12-04", "Submission_Version": "1.7", "Submission_ReleaseDate": "2009-12-28"}, "Modification": [{"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2010-06-21", "Modification_Version": "1.9", "Modification_ReleaseDate": "2010-06-21", "Modification_Comment": "updated Description"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2011-06-01", "Modification_Version": "1.13", "Modification_ReleaseDate": "2011-06-01", "Modification_Comment": "updated Common_Consequences"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2011-06-27", "Modification_Version": "2.0", "Modification_ReleaseDate": "2011-06-27", "Modification_Comment": "updated Common_Consequences"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2017-01-19", "Modification_Version": "2.10", "Modification_ReleaseDate": "2017-01-19", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2017-11-08", "Modification_Version": "3.0", "Modification_ReleaseDate": "2017-11-08", "Modification_Comment": "updated Modes_of_Introduction, Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2020-02-24", "Modification_Version": "4.0", "Modification_ReleaseDate": "2020-02-24", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2021-03-15", "Modification_Version": "4.4", "Modification_ReleaseDate": "2021-03-15", "Modification_Comment": "updated Demonstrative_Examples"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-01-31", "Modification_Version": "4.10", "Modification_ReleaseDate": "2023-01-31", "Modification_Comment": "updated Description"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-04-27", "Modification_Version": "4.11", "Modification_ReleaseDate": "2023-04-27", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-06-29", "Modification_Version": "4.12", "Modification_ReleaseDate": "2023-06-29", "Modification_Comment": "updated Mapping_Notes"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2025-12-11", "Modification_Version": "4.19", "Modification_ReleaseDate": "2025-12-11", "Modification_Comment": "updated Applicable_Platforms, Weakness_Ordinalities"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2026-10-28", "Modification_Version": "5.0", "Modification_ReleaseDate": "2026-10-28", "Modification_Comment": "updated Description, Technical_Nuance"}]}, "entry_type": "Weakness"}
