Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: interim save

...

A path name, whether abstract or in string form, may be either absolute or relative. An absolute path name is complete in that no other information is required to locate the file that it denotes. A relative path name, in contrast, must be interpreted in terms of information taken from some other path name.

An absolute Absolute or relative path names may contain aliasesfile links such as symbolic (soft) links, hard links, short cuts, shadows, symbolic links and shortcuts ( aliases, hereafter) and junctions rather than canonical paths, which refer to the actual files or directories that these point to. These aliases must be fully resolved before any file validation operations are performed. For instanceexample, the final target of a symbolic link called trace might be the path name /home/system/trace. Path names may also contain special file names that make validation difficult:

  1. “.” refers to the directory itself.
  2. Inside a directory, the special file name “..” refers to the directory’s parent directory.

In addition to these specific issues, there are a wide variety of operating and file system specific naming conventions which make validation difficult.

The process of canonicalizing file names makes it easier to verify validate an aliaspath name. More than one alias path name can refer to a single directory or file. Further, the textual representation of an alias path name may yield little or no information regarding the directory or file to which it refers. Consequently, all aliases path names must be fully resolved or canonicalized before validation.

This is necessary because operating on untrusted user input may allow result in a directory traversal or path equivalence vulnerability. A directory traversal vulnerability allows an I/O operation to escape the a specified operating directory. Violation of this rule can result in information disclosure and malicious modification of files existing in directories other than the specified oneA path equivalence vulnerabilities occur when an attacker provides a different but equivalent name for a resource to bypass security checks.

This rule is an a specific instance of IDS01-J. Normalize strings before validating them.

...

This noncompliant code example accepts a file path as a command line argument and uses the File.getAbsolutePath() method to obtain the absolute file path. This method does not automatically resolve symbolic file links or eliminate equivalence errors.

Code Block
bgColor#FFcccc
public static void main(String[] args) {
  File f = new File("/tmp/" + args[0]);
  String absPath = f.getAbsolutePath();

  if (!validate(absPath)) {  // Validation
    throw new IllegalArgumentException();
  }		  
}

Wiki Markup
The application intends to restrict the user from operating on files outside the {{/tmp}} directory and uses a {{validate()}} method to enforce this condition
. An attacker who can create symbolic links in /tmp can cause the program to pass validation checks by supplying the unresolved path. All file operations performed are reflected in the file pointed to by the symbolic link.
Wiki Markup
Let {{argv\[0\]}} be the string {{filename}}, where. The path name validation can be easily circumvented.  For example, an attacker who can create symbolic links in {{/tmp}} can cause the program to pass validation checks by supplying the unresolved path. All file operations performed are reflected in the file pointed to by the symbolic link. If the string {{filename}} is passed as {{argv\[0\]}} and {{/tmp/filename}} is a symbolic link that pointsrefers to the file {{/dirname/filename}} present on the localvalidation file systempasses. The validationThis passesis because the root directory of the compiled path name is still {{/tmp}}, but the operations are carried out on the file {{/dirname/filename}}.

Note that File.getAbsolutePath() actually does resolve all symbolic links, aliases, and short cuts on Windows and Macintosh platforms. Nevertheless, the JLS lacks any guarantee that this behavior is present on all platforms or that it will continue in future implementations.

...

Using path names from untrusted sources without first canonicalizing them and then validating them can result in directory traversal attacksand ath equivalence vulnerabilities.

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

IDS02-J

medium

unlikely

medium

P4

L3

Other Languages

...

Related Guidelines

...

...

...

...

...

Related Vulnerabilities

CVE-2005-0789

 

CVE-2008-5518

 

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8cd32bdd4ecbcd51-bb8ef89d-46c9446d-be69b9bd-577160d6112b602543aead66"><ac:plain-text-body><![CDATA[

[[MITRE 2009

AA. Bibliography#MITRE 09]]

[CWE ID 171

http://cwe.mitre.org/data/definitions/171.html] "Cleansing, Canonicalization, and Comparison Errors"]]></ac:plain-text-body></ac:structured-macro>

 

CWE ID 647 "Use of Non-Canonical URL Paths for Authorization Decisions"

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b28ccf0abf4e4b90-dc424521-43d3469b-9b929bda-d2f416bb4e5d83e7d2c75955"><ac:plain-text-body><![CDATA[

[[API 2006

AA. Bibliography#API 06]]

[method getCanonicalPath()

http://java.sun.com/javase/6/docs/api/java/io/File.html#getCanonicalPath()]

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8f25ff19822554b5-2112b32e-4c9b4ee3-b118-4c8ecd7e2198"><ac:plain-text-body><![CDATA[

[[API 2006

AA. Bibliography#API 06]]

[method getCanonicalFile()

http://java.sun.com/javase/6/docs/api/java/io/File.html#getCanonicalFile()]

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="f10b7d89-a346-4239-a979-53f33f5abad18777-4a0304e0e873"><ac:plain-text-body><![CDATA[

[[Harold 1999

AA. Bibliography#Harold 99]]

 

]]></ac:plain-text-body></ac:structured-macro>

...