CWE-35 Path Traversal: '.../...//'
Read Files or Directories; Modify Files or Directories; Bypass Protection Mechanism
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 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.
When validating filenames, use stringent allowlists that limit the character set to be used. If feasible, only allow a single "." character in the filename to avoid weaknesses such as CWE-23 , and exclude directory separators such as "/" to avoid CWE-36 . Use a list of allowable file extensions, which will help to avoid CWE-434 .
Do not rely exclusively on a filtering mechanism that removes potentially dangerous characters. This is equivalent to a denylist, which may be incomplete ( CWE-184 ). For example, filtering "/" is insufficient protection if the filesystem also supports the use of "\" as a directory separator. Another possible error could occur when the filtering is applied in a way that still produces dangerous data ( CWE-182 ). For example, the ".../...//" manipulation is useful for bypassing some path traversal protection schemes. If "../" sequences are removed from the ".../...//" string in a sequential fashion (as some regular expression engines and other algorithms operate) the string can collapse into the unsafe "../" value ( CWE-182 ). Removing the first "../" yields "....//" and the second removal yields "../".
Strategy: Input Validation
Class: Not Language-Specific (Undetermined Prevalence)
Suppose the product serves files from a specific "public" directory -- / /product/public/ -- and has an algorithm that attempts to protect against common path traversal attacks. The algorithm works by sequentially scanning through a requested filename and removes each occurrence of "../" that it encounters, then appending the filename to the public directory.
If an attacker provides this filename:
then the code would correctly remove the "../" resulting in the name:
This request would fail, because secret.dat is not in / /product/public/secret.dat.
The attacker could attempt to bypass this protection mechanism using this string:
The algorithm would remove the first occurrence of "../" to produce:
The algorithm would then find and remove the second (and final) "../" sequence, producing:
At this point, the algorithm stops because it removed all "../" that appeared in the original string, but the algorithm has collapsed the original input into an unsafe value ( CWE-182 ) that is still subject to path traversal.
Which the OS resolves to / /product/secret.dat, a file that is outside the public directory.
Note: this is a curated list of examples for users to understand the variety of ways in which this weakness can be introduced. It is not a complete list of all CVEs that are related to this CWE entry.
Automated Static Analysis
The full story
This article is one source in a clustered incident — the cluster page carries the summary, timeline and every other outlet covering it.
