CWE-171: Cleansing, Canonicalization, and Comparison Errors
Cleansing, Canonicalization, and Comparison Errors
Category ID: 171 (Category)
Status: Draft
Description
Description Summary
Weaknesses in this category are related to improper handling of
data within protection mechanisms that attempt to perform sanity checks for
untrusted data.
Applicable Platforms
Languages
All
Potential Mitigations
Phase
Description
Avoid making decisions based on names of resources (e.g. files) if
those resources can have alternate names.
Assume all input is malicious. Use an appropriate combination of black
lists and white lists to ensure only valid, expected and appropriate
input is processed by the system. For example, valid input may be in the
form of an absolute pathname(s). You can also limit pathnames to exist
on selected drives, have the format specified to include only separator
characters (forward or backward slashes) and alphanumeric characters,
and follow a naming convention such as having a maximum of 32 characters
followed by a '.' and ending with specified extensions.
Canonicalize the name to match that of the file system's
representation of the name. This can sometimes be achieved with an
available API (e.g. in Win32 the GetFullPathName function).