bug(auth): Fix error during account delete#20603
Open
dschom wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a race-condition failure path during account deletion by converting a missing-account row in password verification into a typed “unknown account” error, preventing 500s and ensuring /v1/account/destroy fails gracefully.
Changes:
- Add a guard in
Account.checkPasswordto throw a typed not-found error when the account row is missing. - Translate that not-found at the
DB.checkPasswordboundary intoerror.unknownAccount()for consistent caller behavior. - Add a route-level unit test to ensure
/account/destroysurfacesACCOUNT_UNKNOWNand skips follow-up deletion work when password-check fails this way.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/fxa-shared/db/models/auth/account.ts | Throw notFound() when the account row is missing during password verification to avoid unhandled undefined access. |
| packages/fxa-auth-server/lib/db.ts | Catch shared-model not-found and translate to ACCOUNT_UNKNOWN for consistent error semantics across callers. |
| packages/fxa-auth-server/lib/routes/account.spec.ts | Add coverage ensuring /account/destroy propagates ACCOUNT_UNKNOWN and does not enqueue deletion work or emit success telemetry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Because
POST /v1/account/destroyreturns 500 withTypeError: Cannot read properties of undefined (reading 'verifyHash')when two destroy requests for the same account race: the first deletes the row between the second'saccountRecord()lookup and its password check, soAccount.checkPasswordreadsverifyHashoffundefined.This pull request
Account.checkPassword(packages/fxa-shared/db/models/auth/account.ts) — throwsnotFound()when the row is missing instead of lettingaccount.verifyHashblow up. Matches the existing pattern in this file (consumeRecoveryCode).notFoundtoerror.unknownAccount()at theDB.checkPasswordboundary (packages/fxa-auth-server/lib/db.ts) — same pattern already used bydb.account()/db.accountRecord(), so all callers (/account/destroy,/account/reauth, password change/forgot,/session/reauth) see one well-known error shape.lib/routes/account.spec.tscovering the race: response is 400ACCOUNT_UNKNOWN, noquickDelete, no Glean success event.Issue that this pull request solves
Closes: FXA-11660
Checklist
Put an `x` in the boxes that apply
How to review (Optional)
Other information (Optional)
Out of scope: The underlying race itself is not addressed. Instead we fail gracefully. Two truly concurrent destroys still both pass auth before one deletes; they just no longer 500. A real fix (per-uid lock or
SELECT ... FOR UPDATEat destroy entry) might be worth a follow up. But is also more complicated and a bit riskier.