Skip to content

fix(registration): make phone numbers unique only once verified - #644

Open
Bccorb wants to merge 2 commits into
mainfrom
fix/unverified-phone-squatting
Open

Bccorb wants to merge 2 commits into
mainfrom
fix/unverified-phone-squatting

Conversation

@Bccorb

@Bccorb Bccorb commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Part of #600 (L-API-3).

A unique constraint over every users.phone row let anyone attach a stranger's number to an account of their own without proving it, and the number's owner could then never add it. The 409 from POST /registration/phone also told any signed-in caller which numbers were registered.

What changes

  • Migration 20261204130000-unique-verified-phone: the index is created before the constraint is dropped, and existing data already satisfies it.
    • Adds the unique index users_verified_phone_key on phone WHERE phone_verified = true.
    • Drops the constraint users_phone_key.
    • Any number of unverified accounts may now hold the same number, and verifying it claims it.
    • The down migration restores the constraint, and fails if two accounts hold the same number.
  • POST /registration/register drops a supplied phone only when another account has verified it.
  • POST /registration/phone sends a code whatever account holds the number. It is now also limited per destination number (otpPhoneTargetLimiter, at four times flow_rate_limits.otp.perIdentity), so many accounts cannot each send codes to one phone.
  • POST /registration/phone/verify and POST /otp/verify-phone-otp answer 409 Phone number in use when another account has already verified the number. The index raises it as a unique violation when the phone is marked verified. This is the only point where it shows, and only to someone who has just proven they hold the phone.
  • User import treats a number as taken only when another account has verified it.
  • PATCH /admin/users/{userId} answers 409 instead of 500 when the update hits the email or verified-phone uniqueness.

Sign-in by phone, login phone OTP and account recovery already read only verified phones.

Contract (minor changeset, breaking)

  • POST /registration/phone no longer answers 409.
  • POST /registration/phone/verify and POST /otp/verify-phone-otp can answer 409.
  • phone in webhook and login hook payloads may now be an unverified number that another account also holds. Integrations that key on it should use the user id.

Ripple survey (read-only):

  • seamless-auth-server forwards these routes through its manifest passthrough and does not branch on their status codes.
  • seamless-auth-js treats any non-2xx from verify-phone-otp as an error result.
  • The admin dashboard shows the message body for a 409.
  • No consumer branched on the old 409 from /registration/phone.

Tests

  • Postgres (tests/postgres/verifiedPhoneUnique.spec.ts): unverified duplicates are allowed, the owner can verify a number a stranger attached, and a second verified holder is refused. The migration was run up, down and up against a scratch database.
  • Integration and unit: the unverified holder no longer blocks registration, /registration/phone answers alike, the 409 at both verify routes, the per-number limiter, the import lookup, and the admin 409.

A unique constraint over every row let anyone attach a stranger's number to an
account of their own without proving it, so its owner could never add it, and
the 409 from /registration/phone told any signed-in caller which numbers were
registered. Only verified numbers are unique now; a code goes out either way and
a number another account has verified is refused at verification.
…bers as taken

Import matched unverified holders as owners, an admin update that hit the
verified-phone index answered 500, and without the 409 nothing bounded how many
accounts could send codes to one number.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant