Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Only these characters should be considered for use in file and path names. This is an instance of rule IDS00-J. Sanitize untrusted data passed across a trust boundary.

Noncompliant Code Example

In the following noncompliant code, unsafe characters are used as part of a file name.

...

An implementation is free to define its own mapping of the non-"safe" characters. For example, when tested on an Ubuntu Linux distribution, this noncompliant code example resulted in the following file name:

Code Block
A?

Compliant Solution

Use a descriptive file name, containing only the subset of ASCII previously described.

Code Block
bgColor#ccccff
File f = new File("name.ext");
OutputStream out = new FileOutputStream(f);

Noncompliant Code Example

This noncompliant code example creates a file with input from the user without sanitizing it.

...

No checks are performed on the file name to prevent troublesome characters. If an attacker knew this code was in a program used to create or rename files that would later be used in a script or automated process of some sort, they could choose particular characters in the output file name to confuse the later process for malicious purposes.

Compliant Solution

In this compliant solution, the program uses a whitelist to reject unsafe file names.

...

Similarly, all file names originating from untrusted sources must be sanitized to ensure they contain only safe characters.

Risk Assessment

Failing to use only the subset of ASCII that is guaranteed to work can result in misinterpreted data.

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

IDS15-J

medium

unlikely

medium

P4

L3

Related Guidelines

Bibliography

ISO/IEC 646-1991

ISO 7-bit coded character set for information interchange

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="451e65e3a0b2ed07-e52c109d-47234616-9589b5b9-55c3aecd08a62a5bbf22b12a"><ac:plain-text-body><![CDATA[

[[Kuhn 2006

AA. Bibliography#Kuhn 06]]

UTF-8 and Unicode FAQ for UNIX/Linux

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="7173f970803d9f08-3466d815-4efd4526-a231a088-4236294fe2a83cee35c57eb2"><ac:plain-text-body><![CDATA[

[[Wheeler 2003

AA. Bibliography#Wheeler03]]

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="37228c0e8004d5cb-c743651d-449540f2-bdc7a1f6-7d1a370238aaeb54b084cd27"><ac:plain-text-body><![CDATA[

[[VU#881872

AA. Bibliography#VU881872]]

 

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

...