Gate point before a verify creates a user

Open
#202 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript

Research direction

Start in the verify flow around authenticateWithIdentifier, following the calls to userStore.create and identityStore.create, then read InitiateGate.onVerified and checkVerifiedGate. Decide between the onBeforeCreateUser hook and an onInitiate silentRefuse decision before writing anything. Done means the gate is consulted before any user or identity row is written, a refused correct code returns the same error as a wrong one without clearing the auth_challenge cookie, and isNewUser is documented.

Written by the indexing model from the issue text.

Description

InitiateGate.onVerified runs after authenticateWithIdentifier has already called userStore.create and identityStore.create. An app that answers every initiate the same way, so its form doesn't reveal who has an account, still gets a live code stored for an address it won't serve. If someone guesses that code, the account is created before the gate is asked. To refuse it, the app has to delete rows the library just wrote. Two verifies of the same code can also both get past the challenge and reach that sequence together, so the app can't use "I inserted this row" to mean "this account is new". It needs its own approval mark.

Ask, either of:

  1. A hook such as gate.onBeforeCreateUser({ provider, identifier, request }), called in authenticateWithIdentifier before userStore.create. Its { error } fails the verify like a bad code.
  2. An onInitiate decision such as "silentRefuse": no challenge is stored and no email is sent, but the answer is the same as for an accepted initiate (status, redirect, and a challenge cookie of the same shape).

Also: when onVerified answers { error }, send that error without the provider's cookie that clears auth_challenge (checkVerifiedGate adds it today). If the cookie is cleared, a refused correct code doesn't answer like a wrong one: the next post from that browser gets "Verification not found" instead of "Incorrect code", which shows the guess was right and the address isn't served.

Also worth documenting: isNewUser means "no identity existed", not "the user row is new", which matters for a user store that upserts.

Found while building invites in activescott/four-in-a-row (security reviews on activescott/four-in-a-row#42). That app works around this today with an approved_at column that only onVerified sets.

Milestone: Private Beta, because an invite-only app is exactly the case this affects.

Dominant language
TypeScript
Stars
0
Forks
2
Avg merge
11d 7h
Merged PRs (30d)
10

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from activescott/auth

All issues in activescott/auth

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.