File and path names containing particular characters can be troublesome and can cause unexpected behavior resulting in vulnerabilities. If untrusted data is The following characters and patterns can be problematic when used in the construction of a file or path name, the following characters and patterns must be disallowed:
- Leading dashes: Leading dashes can cause problems when programs are called with the file name as a parameter because the first character or characters of the file name might be interpreted as an option switch.
- Control characters, such as newlines, carriage returns, and escape: Control characters in a file name can cause unexpected results from shell scripts and in logging.
- Spaces: Spaces can cause problems with scripts and when double quotes aren't used to surround the file name.
- Invalid character encodings: Character encodings can make it difficult to perform proper validation of file and path names. (See rule IDS11-J. Eliminate non-character code points before validation.)
- Characters other than letters, numbers, and portable punctuation: These characters may be used as name-separator character. Including them Name-space separation characters: Including name-space separation characters in a file or path name can cause unexpected and potentially insecure behavior.
- Command interpreters, scripts and parsers: Some characters have special meaning when processed by a command interpreter, shell, or parser and should consequently, be avoided.
As a result of the influence of MS-DOS, file names of the form xxxxxxxx.xxx
, where x denotes an alphanumeric character, are generally supported by modern systems.
In addition to the letters of the English alphabet ("A" through "Z" and "a" through "z"), the digits ("0" through "9"), and the space, only the following characters are portable:
...
...
% & + , - . : = _
Only these characters should be considered for use in file and path names. Punctuation characters not on this list are not unconditionally safe for file names even if they are portably available. These characters or patterns can cause problems for scripts and automated parsing, but because they are not commonly used, it is best to disallow their use to reduce potential problems. Interoperability concerns also exist because different operating systems handle these punctuation characters in file and path names in an implementation-defined manner.
This is an instance of rule IDS00-J. Sanitize untrusted data passed across a trust boundary.
...
MSC09-C. Character Encoding - Use Subset of ASCII for Safety | ||||
MSC09-CPP. Character Encoding - Use Subset of ASCII for Safety | ||||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="a41e3995e9f2e221-0eb16f2e-4e7f405c-ae61aa43-dbc4d0721314b2b87f08fac1"><ac:plain-text-body><![CDATA[ | [ISO/IEC TR 24772:2010 | http://www.aitcnet.org/isai/] | "Choice of Filenames and other External Identifiers [AJN]" | ]]></ac:plain-text-body></ac:structured-macro> |
CWE ID 116, "Improper Encoding or Escaping of Output" |
...
ISO 7-bit coded character set for information interchange | ||||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="6377a6f5dcbdb26c-00e8f85b-4e9b46bf-a10c9e29-7c8c7a0089da8e557371aa81"><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="ce6760eff8413ca6-961b063f-423c40bb-89aeb8bb-d4137482d22df45a30048fef"><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="36d4846e62e005c0-94d2468c-48414ca6-8bafb82a-effbd5a47db41109077e7e2f"><ac:plain-text-body><![CDATA[ | [[VU#881872 | AA. Bibliography#VU881872]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
...