...
Wiki Markup |
---|
There are several national variants of ASCII. Therefore, the original ASCII is often referred as *US-ASCII*. The international standard _ISO 646_ defines a character set similar to US-ASCII, but with code positions corresponding to US-ASCII characters {{@\[\]\{\|\}}} as "_national use positions"_. It also gives some liberties with characters {{\#$^`\~}}. In _ISO 646_, several "national variants of ASCII"\ have been defined, assigning different letters and symbols to the "national use" positions. ThusConsequently, the characters that appear in those positions -, including those in *US-ASCII*, are somewhatless unsafeportable in international data transfer. Consequently, due to the "national variants," some characters are less _safe_portable than others--they might be transferred or interpreted incorrectly. |
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 can be regarded as safeare portable:
No Format |
---|
% & + , - . : = _ |
...
File names containing particular characters can be troublesome and can cause can cause unexpected behavior leading to potential vulnerabilities. If a program allows the allows the user to specify a filename in the creation or renaming of a file, certain checks should be made to disallow the following characters and patterns:
- Leading dashes
- Control characters such as newlines, carriage returns, and escape
- Spaces
- Invalid character encodings
- Any characters other than letters, numbers, and punctuation designated above as portable
Many of the punctuation characters aren't unconditionally safe for filenames even of they are portably available.
Most of these characters or patterns are primarily a problem to scripts or 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 filenames of this sort in different ways. Leading dashes can cause programs when programs are called with this filename as a parameter, the first character or characters of the file might be taken to mean that its an option switch. Control characters in a filename can cause unexpected results from shell scripts and in logging. Spaces can again cause problems with scripts and anytime double quotes aren't used to surround the filename. Character encodings can be a huge issue and are also discussed in MSC10-A. Character Encoding - UTF8 Related Issues. Other special characters are included in this recommendation because they are commonly used as separators and having them in a filename can cause unexpected and potentially insecure behavior.
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 some cases file names are case sensitive while in other cases they are case insensitive.
Non-Compliant Coding Example: Encoding
...
An implementation is free to define its own mapping of the non-"safe" characters. For example, when tested on a Red Hat Linux distribution, this non-compliant code example resulted in the following filename resultedfile name:
Code Block |
---|
?????? |
Compliant Solution: Encoding
...