Python's str.lower() got a CVE: how to compare strings safely

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.

4 min read
AI-assisted

Author's AI disclosure

The author reports using AI to help with this article.

The author confirms reviewing this article.

Python's str.lower() got a CVE: how to compare strings safely

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.3

StringPrep, 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:

>>> "\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

fi (ligature)

fi

fi

Only casefold() expands it

The Kelvin sign is the one to remember. A check like this passes:

"\u212aernel.org".lower() == "kernel.org"  # True

The 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 A are different again.

A small helper handles most of this:

from unicodedata import normalize

def fold(s: str) -> str:
    return normalize("NFKC", s).casefold()

Checked against the cases above:

A

B

lower() equal?

fold() equal?

STRASSE

straße

no

yes

Admin (fullwidth A)

admin

no

yes

e + combining accent

é

no

yes

file

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

Comments0

Log in to join the discussion.

No comments yet.

Pradeep Kumar

Read articles by this author.

Subscribe to Pradeep Kumar's newsletter

Get the articles this author chooses to send by email.