{"schemaVersion":"1.0","type":"TechArticle","types":["Article","TechArticle"],"slug":"python-s-str-lower-got-a-cve-how-to-compare-strings-safely-2stki","url":"https://zyvop.com/python-s-str-lower-got-a-cve-how-to-compare-strings-safely-2stki","title":"Python's str.lower() got a CVE: how to compare strings safely","subtitle":"One str.lower() call in the standard library became CVE-2026-17084. Here is what broke, how to check your Python, and how to compare strings safely.","tldr":"CVE-2026-17084 came from a single str.lower() call in the standard library. The bug is narrow, but the cause is general: case mapping depends on the Unicode data your Python ships with. Here is what broke, how to check your interpreter, and what to use instead.","keywords":["Python","security","Unicode","cve","IDNA","Vulnerability"],"entities":["Pradeep Kumar","Python","security","Unicode","cve","IDNA","Vulnerability","ZyVOP"],"keyTakeaways":["In August, CPython got a security advisory for a bug that came down to one line: a call to str.lower() inside the standard library's stringprep module.","The advisory is CVE-2026-17084, and it is rated medium severity.","It affects IDNA 2003 domain name handling (the idna codec) and the stringprep module."],"headings":["What went wrong","Are you patched?","The general problem with lower()","Normalization is the other half","What I would do","The lesson","Sources"],"outboundLinks":["https://sethmlarson.dev/when-str-lower-is-a-security-vulnerability","https://openwall.com/lists/oss-security/2026/08/18/2","https://osv.dev/vulnerability/CVE-2026-17084","https://explore.alas.aws.amazon.com/CVE-2026-17084.html","https://datatracker.ietf.org/doc/html/rfc3454","https://datatracker.ietf.org/doc/html/rfc8265"],"contentText":"In August, CPython got a security advisory for a bug that came down to one line: a call to str.lower() inside the standard library's stringprep module. The advisory is CVE-2026-17084, and it is rated medium severity. The scope is narrow. It affects IDNA 2003 domain name handling (the idna codec) and the stringprep module. If your code never touches those, this exact bug does not reach you. The cause is worth understanding anyway, because it can show up in your own code. What went wrong str.lower() uses the Unicode data that ships with your Python interpreter. You can see which version that is: import unicodedata print(unicodedata.unidata_version) # '15.0.0' on Python 3.12.3StringPrep, the algorithm behind IDNA 2003 domain names, is defined against Unicode 3.2.0. Its case-folding tables are a snapshot of that old version. Python's implementation looked up exceptions in the table and then fell back to code.lower(), which applies today's rules instead of the frozen ones. For most characters nobody notices. For some, the answer changed after 3.2.0. Cherokee capital letter A (U+13A0) is one: Unicode 3.2.0 has no lowercase form for it, and modern Unicode maps it to U+AB70. The result is two different domain names for the same input: &gt;&gt;&gt; \"\\u13a0\\u13a0\".encode(\"idna\") b'xn--kz9aa' # what an unpatched Python returns # RFC 3454 says: b'xn--58da'So Python and a standards-compliant implementation could disagree about which domain a string refers to. That gap is the vulnerability. It only affects domain names containing characters whose case behavior changed after Unicode 3.2.0. Are you patched? The fix did not replace str.lower(). It added a table of exceptions so that lower() behaves like Unicode 3.2.0 inside these functions only. The fixed releases are: Branch Fixed in 3.10 3.10.22 3.11 3.11.17 3.12 3.12.15 3.13 3.13.16 3.14 3.14.8 3.15 3.15.0rc2 Distributions often backport fixes without changing the version number, so a behavior test is more reliable than reading the version string. Run the Cherokee example above. On a patched interpreter it should return b'xn--58da'. The general problem with lower() Even without the CVE, lower() is a poor tool for comparing strings in security checks. The outputs below come from Python 3.12.3 (Unicode 15.0.0): Input lower() casefold() What to notice K (Kelvin sign, U+212A) k k Collapses into plain ASCII k ß ß ss \"STRASSE\" matches \"straße\" only with casefold() ΑΣ (Greek) ας ασ lower() picks the final-sigma form İ (U+0130) i̇ i̇ Two characters now, and not equal to i ﬁ (ligature) ﬁ fi Only casefold() expands it The Kelvin sign is the one to remember. A check like this passes: \"\\u212aernel.org\".lower() == \"kernel.org\" # TrueThe string you are holding is not ASCII, yet after lower() it looks exactly like a name you trust. Whether that matters depends on what reads the value next. A mail server, a DNS resolver or a database may treat the original string differently than your check did. That mismatch between what you validated and what something else uses is where this class of bug lives. Python's own documentation describes casefold() as the method intended for caseless matching. It is the better default. Normalization is the other half Case is only one way two strings can look the same. A precomposed é and an e followed by a combining accent are different strings, and casefold() does not make them equal. Fullwidth letters like Ａ are different again. A small helper handles most of this: from unicodedata import normalize def fold(s: str) -&gt; str: return normalize(\"NFKC\", s).casefold()Checked against the cases above: A B lower() equal? fold() equal? STRASSE straße no yes Ａdmin (fullwidth A) admin no yes e + combining accent é no yes ﬁle FILE no yes NFKC is aggressive. It collapses ligatures, fullwidth forms and other compatibility characters, which is usually what you want for usernames and identifiers. It is not what you want for text where those differences carry meaning, and you should never case-fold passwords. What I would do Domain names: use the idna package (IDNA 2008) instead of .encode(\"idna\"), and keep Python patched if you need the older codec. Usernames and similar identifiers: look at RFC 8265, which defines profiles built for exactly this, or use fold() plus a restriction on allowed characters. Canonicalize once. Store the canonical form and compare canonical forms. Mixing lower() in one place and casefold() in another creates the gaps. Check every layer. The database collation, the proxy and the app should agree on what counts as the same string. Add tests with the Kelvin sign, ß and the Cherokee example. One more limit worth knowing: Python's case functions are not locale-aware. \"I\".lower() returns i even if your users write Turkish. If you need locale rules, you need a library that implements them. The lesson The standard library had a function call that looked obviously correct, and it carried a hidden dependency on a data version. Your own code has the same shape any time two systems must agree on how a string is transformed. That is rarely a problem until a character comes along whose rules changed. Sources Seth Larson, When str.lower() is a security vulnerability in Python (the bug, the Cherokee example, the fix) Python security announcement, CVE-2026-17084 on oss-security (scope and severity) OSV, CVE-2026-17084 (fixed versions by branch) Amazon Linux, CVE-2026-17084 (CVSS 5.3 rating) RFC 3454, StringPrep, and RFC 8265, usernames and passwords Python docs, str.casefold and unicodedata","contentHash":"sha256:2943fffab5af6e0afe7da10d7996aaf669358c648bf0bb3ed4103163261ccc89","authorName":"Pradeep Kumar","authorUrl":"https://zyvop.com/author/pradeep","authorSameAs":[],"category":"Vulnerability","tags":["Python","security","Unicode","cve","IDNA"],"audience":"Software engineers and developers building applications with Vulnerability","tone":"Instructional, practical, code-first","readingTimeMinutes":4,"wordCount":932,"faqs":null,"primaryTopic":"Vulnerability","publishedAt":"2026-12-04T08:08:54.679Z","updatedAt":"2026-12-04T08:08:54.679Z","canonicalUrl":"https://zyvop.com/python-s-str-lower-got-a-cve-how-to-compare-strings-safely-2stki"}