fix(auth): store only SHA-256 hashes of reset/verify one-time tokens#800
Open
k08200 wants to merge 1 commit into
Open
fix(auth): store only SHA-256 hashes of reset/verify one-time tokens#800k08200 wants to merge 1 commit into
k08200 wants to merge 1 commit into
Conversation
verifyToken/resetToken were stored as raw hex in the User table while Device.tokenHash already stored only a SHA-256 hash — a DB read (backup leak, replica misconfig, SQLi elsewhere) yielded directly usable password-reset and email-verify links. - new one-time-token.ts: mintOneTimeToken/hashOneTimeToken - 3 mint sites (register, forgot-password, resend-verification) store the hash and email the raw token only - 2 redemption sites (reset-password, verify-email) hash the presented token for lookup; atomic single-use semantics unchanged - migration nulls outstanding plaintext tokens (users re-request; verify links were 24h-lived, reset links 1h)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
User.verifyToken/User.resetTokenstored the raw emailed token, whileDevice.tokenHashalready held only a SHA-256 hash — an inconsistent standard where a DB read (backup leak, replica misconfig, SQLi elsewhere) yielded directly usable password-reset / email-verify links.one-time-token.ts(mintOneTimeToken/hashOneTimeToken): all 3 mint sites (register, forgot-password, resend-verification) now store the hash and put the raw token only in the email; both redemption sites (reset-password, verify-email) hash the presented token for lookup. Atomic single-useupdateManysemantics unchanged.Type
Checklist
tsc --noEmit)Test plan
vitest runin packages/api — full suite 2109 passed (routes-auth.test.ts 64/64: hash-storage assertions, reset/verify round trips through hashed lookup, single-use, expiry, enumeration-safe responses)tsc --noEmit— clean;biome check --diagnostic-level=error src/— cleanverifyTokenidentifier shadow)