File names and path names containing particular characters can be troublesome and can cause unexpected behavior leading to potential vulnerabilities. If a program allows the user to specify a file name in the creation or renaming of a file, certain checks should be made to disallow the following characters and patterns:
- Leading dashes—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 escape: Control characters in a file name can cause unexpected results from shell scripts and in logging.
- Spaces—Spaces 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 be a huge issue. (See rule IDS03-J. Sanitize non-character code points before performing other sanitization.)
- Any characters other than letters, numbers, and punctuation designated here as portable — : Other special characters are included in this recommendation because they are commonly used as separators and having them in a file name can cause unexpected and potentially insecure behavior.
...