CVE-2026-126604: Incorrect Behavior Order: Validate Before Canonicalize in sanitize-filename
sanitize-filename (PyPI) < 1.2.1 is vulnerable to path traversal attacks. sanitize() removed blacklisted characters before applying Unicode NFKD normalization. Characters such as FULLWIDTH SOLIDUS (U+FF0F), FULLWIDTH REVERSE SOLIDUS (U+FF3C) and SMALL REVERSE SOLIDUS (U+FE68) passed the blacklist and became real path separators in the returned value. An attacker who controls the input filename could make sanitize() return an absolute path. Example, sanitize("\uFF0F..\uFF0F..\uFF0F..\uFF0Fetc\uFF0Fpasswd")
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 1.2.1
Event History
Frequently Asked Questions
Which deployments are exposed?
Deployments using the PyPI sanitize-filename package at versions earlier than 1.2.1 are affected if they pass attacker-controlled filename input to sanitize() and use the returned value as a filesystem path or filename.
What does an attacker need to exploit this issue?
An attacker needs control over the input filename supplied to sanitize(). They can use Unicode characters that are not removed by the blacklist but become path separators after Unicode NFKD normalization, enabling traversal or an absolute returned path.
Is upgrading available, and what should be done if it cannot be applied immediately?
Version 1.2.1 is the referenced fixed release. If upgrading is not immediately possible, do not rely on sanitize() output alone for untrusted filenames; ensure the resulting path cannot escape the intended directory before using it.
How can I identify potentially vulnerable usage?
Review uses of sanitize() that accept untrusted filenames, especially where its returned value is joined to or used as a filesystem path. Inputs containing FULLWIDTH SOLIDUS (U+FF0F), FULLWIDTH REVERSE SOLIDUS (U+FF3C), or SMALL REVERSE SOLIDUS (U+FE68) are relevant indicators.