Skip to content

Lesson 6 of 20 · 15m

Unicode, normalization, and lookalike identifiers

Identifiers compare at the byte level: NFC vs NFD, Turkish-I case folding, bcrypt's 72-byte cutoff, and lookalike glyphs all change what 'equal' means.

Two strings can print identically and compare unequal, or print differently and compare equal — and every authz check, dedupe, uniqueness constraint, and signature verify is a string compare. Unicode makes both directions exploitable, and the bugs live in normalization, case folding, and glyphs that look alike.

Normalization: same letter, different bytes

é exists twice: U+00E9 as one code point, and e + U+0301 as two. "café" in NFC is six bytes; in NFD it's seven, and === reports different strings. macOS made this famous by normalizing filenames (HFS+ stored NFD; APFS compares normalization-insensitively), but the security version is username dedupe and path checks: josé registered in NFC and queried in NFD either double-books an account or misses the record, depending on which side of the compare normalizes.

Fix: normalize before you compare, store, or hash — NFC or NFKC (unicodedata.normalize("NFC", s), str.normalize("NFKC")) — on both sides. NIST 800-63B prescribes the same for passwords: normalize before the KDF, because the same passphrase typed on two keyboards must hash identically. Watch bcrypt's other interaction while you're here: it truncates at 72 bytes, not characters — multibyte passwords get cut mid-codepoint, and two different passwords can share their first 72 bytes. Argon2id doesn't truncate; it was the better pick anyway.

Case folding: toLowerCase is not equality

"I".toLowerCase() is "i" — unless the runtime's locale is Turkish, where it produces the dotless ı. The Turkish-I class has broken equalsIgnoreCase-style checks for decades; Java's answer is toLowerCase(Locale.ROOT), .NET's is ToLowerInvariant(), and Node inherits ICU's default locale unless you pin it. German runs the other direction: ß folds to ss, which lower() never yields — Python carries str.casefold() precisely because lower() is wrong for equality. If your uniqueness check is username.lower(), STRASSE and straße diverge or collide depending on runtime and locale.

The subtler case is identifiers that pass through a mapping: IDNA ToASCII folds ß differently across its revisions, and domain comparisons run pre-fold see different hosts than post-fold. Compare after the final normalization, at the layer where the decision happens — the recurring shape is two layers comparing differently, nginx matching a route prefix byte-for-byte while the app compares post-normalization, so admіn (Cyrillic і) slips the route guard and hits the handler.

Lookalikes: the glyph you didn't type

The famous demo is Xudong Zheng's April 2017 аррӏе.com — Cyrillic code points Chrome and Firefox rendered pixel-identically to apple.com (xn--80ak6aa92e.com). The same class exists wherever humans read identifiers: package names on npm and PyPI, forum handles, sender display names, filenames in uploads. Unicode publishes confusables.txt (UTS-39) — the official lookalike list — and zero-width characters (U+200B, U+200E) and bidi controls make two genuinely different strings render identically, which is how "impersonation" happens without touching the credential system at all. Register admin with a Cyrillic а and every moderator's eyes pass over it.

Bidi controls go further than impersonation: the 2021 Trojan Source paper (CVE-2021-42574) showed U+202E-class overrides reordering source code in editors and review UIs, so the diff you approved rendered differently than the code that compiled. If your review tooling doesn't flag bidi characters, that gap is on you.

Practice

Normalize, then fold, then compare — casefold, Locale.ROOT, ToLowerInvariant — and reject what you can't render safely: zero-widths, bidi controls, mixed-script confusables in usernames and filenames. For domains, punycode (xn--) is the honest display, and browsers switched to showing it for exactly this reason. Anywhere a human-approved string becomes a security decision — repo names, package names, principal names — the compare must be byte-exact after normalization, never glyph-exact.

Keep reading

Related articles from the SudoSecurity blog.