~/gvndsxnkr
cd ../notes

// security · auth · 3 min read

Two Ways Strangers Could Own an Account

An unverified sign-up that enabled account takeover, and a 'first visitor becomes admin' bootstrap, both fixed by asking what was proved.

Two of the platforms I built had the same kind of hole: someone who got there first could own an account that wasn't theirs. Neither was a clever exploit. Both came from ordinary-looking flows that skipped one question: has this person proved they own this?

Hole 1: register with someone else's phone number

A car rental platform let customers sign up with a phone number and a password, and sign in later with either the password or an SMS code. Registration saved the phone number without verifying it.

Here is how that goes wrong:

  1. An attacker registers with your phone number and a password they choose.
  2. Weeks later, you sign in for the first time with an SMS code. The code arrives on your phone, so it succeeds.
  3. The SMS sign-in finds the existing account for that number, marks the phone as verified, and logs you in.
  4. You book a car and save your details. The attacker's password still works, and it now opens your account.

No step is a bug on its own. Together they are an account takeover.

The fix

The first time a phone number is proved by an SMS code, anything set by whoever registered it is dropped: the password is cleared, so only the person holding the phone controls the account. Alongside that:

  • Codes are counted in the database and can be used once, so attempts can't be spread across server instances.
  • Unknown numbers aren't revealed early. The API only says "please register" after a correct code, so it can't be used to check which numbers have accounts.
  • Suspensions and role changes apply immediately. The session check now includes the user's status, and roles are read fresh instead of trusted from the token. Before this, a suspended admin kept access until their token expired.

Hole 2: the first visitor becomes the admin

An operations app for an agri-processing business had the classic bootstrap problem. A fresh deployment has no users, so how does the first admin get created?

The tempting answer is an HTTP endpoint that creates a super admin if none exists yet. It works in development. In production it means that between deploying and setting up the account, whoever reaches that endpoint first owns the system. Bots scan new deployments constantly; that window is not safe.

The fix

Super-admin creation moved out of HTTP entirely. It's a command run on the server:

npm run admin:create

It prompts for the email, name and password (with the password hidden), and refuses to run if a super admin already exists. There is no route to attack, because there is no route. Operators are then created from inside the app by that admin.

The pattern behind both

Both bugs trust who arrived first instead of who can prove it:

  • Registering a phone number isn't proof of owning it. A code sent to it is.
  • Reaching a fresh server isn't proof of owning it. Shell access is.

When I review an auth flow now, I ask one question of every step that grants or changes control: what has this person proved at this point? If the answer is "nothing yet", that step must not leave anything behind that the real owner inherits.

  • #Security
  • #Auth