Dev.to Security 🔐 Cybersecurity 👁 0 📖 2 min read

The Email Parser Nightmare: Unicode, RFC Quirks and Account Takeover

A single email address can hand over an account. The trick is that it passes through three systems that each normalize it differently. You wouldn't think an email address could trigger a zero-click account takeover. It'

A single email address can hand over an account. The trick is that it passes through three systems that each normalize it differently.

You wouldn't think an email address could trigger a zero-click account takeover. It's just a string: [email protected]. But that string travels through at least three systems:

  1. the frontend validator (regex / HTML5),
  2. the auth and database layer (SQL, Mongo, your OAuth provider),
  3. the delivery engine (SES, SendGrid, Postmark, raw SMTP).

When those three normalize differently, authentication collapses. Here are the edge cases worth testing.

1. IDN homograph and Punycode collisions

Register with а[email protected] — the first letter is U+0430, Cyrillic "а", not ASCII "a".

  • If the system stores it literally and never canonicalizes to Punycode (xn--dmin-43d), it passes uniqueness checks as a brand-new account.
  • But if some casing or folding step folds that Unicode character improperly (Turkish dotless i, Cyrillic folding), it can normalize to the real admin's identifier.

2. Zero-width and whitespace steganography

victim@example[u200B].com   zero-width space
victim[u00A0]@example.com   non-breaking space
victim[x00]@example.com     null-byte truncation

The auth database strips the unprintable character and sees [email protected]. The mailer keeps it and delivers the reset link somewhere else.

3. Gmail dot-blindness

Gmail ignores dots: [email protected] is the same inbox as [email protected]. If an app treats them as two users but allows Google SSO, an attacker can register the dotted variant first and later hijack pre-seeded state, invites or payment methods when the victim signs in with OAuth.

4. RFC 822 header smuggling

Two classics:

  • CRLF injection: [email protected]%0d%0aBcc:[email protected]. Concatenated straight into SMTP headers, that injects a Bcc: and silently copies every reset email to the attacker.
  • Display-name abuse: some lax parsers accept a display name plus a bracketed mailbox, then a second mailbox after it, and deliver to the wrong one.

How to fix email normalization

  • Canonicalize IDNs to ASCII Punycode at the boundary, before any database lookup.
  • Strip invisible and control characters — zero-width (u200B, u200C, u200D), non-breaking space (u00A0), control codes (x00–x1F).
  • Case-fold in ASCII, not with locale-dependent Unicode folding.
  • Never interpolate addresses into raw mail templates. Use a library that parameterizes headers.

Ever caught an auth bypass or reset hijack from an email-parser mismatch? Share it below.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.