The Reset Mail Sent to a Look-Alike

Medium

· Backend

Incident

SEV-1

BUG-CVE-2019-19844

Priority: Critical (account takeover) · reported by security

Time to fix: 20 min

Failing checks on the shipped build

  • a dotless-i look-alike gets nothing

    the look-alike is not the account's address: expected [] but got [{"to": "m\u0131ke@example.org", "username": "mike"}]

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Inspired by

Django · CVE-2019-19844

Modelled on Django CVE-2019-19844 (December 2019). Django's password-reset form found accounts with a case-insensitive database lookup, and Unicode case mapping lets different strings compare equal — a dotless ı uppercases to a plain I. The form then mailed the reset link to the address as typed, not the address on the account, so an attacker could request a reset for a look-alike of a victim's email and receive the victim's reset token. The fix sends mail only to the stored address and re-checks the match with Unicode normalisation and case folding.

This reconstruction's send_reset has both halves of the original bug.

Fix send_reset.

Code map

db = bug_require("./db.py")


def send_reset(email, users, outbox):
    for user in db.users_with_email_iexact(users, email):
        if not user["active"]:
            continue
        outbox.append({"to": email, "username": user["username"]})

Sign in to edit the file, run the tests and submit a fix

A free account — no card, no trial clock. You come straight back here.

The Reset Mail Sent to a Look-Alike — Python Bug Hunt

Modelled on Django CVE-2019-19844 (December 2019). Django's password-reset form found accounts with a case-insensitive database lookup, and Unicode case…

  • Language: Python
  • Layer: Backend
  • Difficulty: Medium
  • Concepts: Security, Unicode, Auth
  • Modelled on: Django · CVE-2019-19844
  • Visible tests: the account's own address gets the link; a dotless-i look-alike gets nothing
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-1 (priority: Critical (account takeover))
  • Ticket: BUG-CVE-2019-19844
  • Reported by: security
  • Time to fix: 20 minutes, the target for a medium incident

Failing checks on the shipped build

  • a dotless-i look-alike gets nothing — the look-alike is not the account's address: expected [] but got [{"to": "m\u0131ke@example.org", "username": "mike"}]

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Briefing

Modelled on Django CVE-2019-19844 (December 2019). Django's password-reset form found accounts with a case-insensitive database lookup, and Unicode case mapping lets different strings compare equal — a dotless ı uppercases to a plain I. The form then mailed the reset link to the address as typed, not the address on the account, so an attacker could request a reset for a look-alike of a victim's email and receive the victim's reset token. The fix sends mail only to the stored address and re-checks the match with Unicode normalisation and case folding.

This reconstruction's send_reset has both halves of the original bug.

Fix send_reset.

Bug report

BUG-CVE-2019-19844 · Priority: Critical (account takeover) · Reported by: security

send_reset(email, users, outbox) appends one message per matching ACTIVE account, of the form {"to": <the account's stored email>, "username": ...}.

  • candidates come from db.users_with_email_iexact (the database lookup)
  • a candidate only matches if NFKC-normalised + casefolded, the typed address equals the stored one (so "MIKE@Example.ORG" matches "mike@example.org", but "mıke@example.org" with a dotless i does not)
  • mail never goes to the typed address; unknown or inactive accounts get nothing

Observed: a reset for a look-alike address was delivered to the attacker's mailbox carrying a valid token for the victim's account.

Logs

[reset] lookup email__iexact="mıke@example.org" -> user mike
[reset] sent reset link for user=mike to=mıke@example.org

The code as shipped

src/accounts/reset.py (editable)

db = bug_require("./db.py")


def send_reset(email, users, outbox):
    for user in db.users_with_email_iexact(users, email):
        if not user["active"]:
            continue
        outbox.append({"to": email, "username": user["username"]})

Read-only context: src/accounts/db.py.

Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Python bug hunts.