fix(auth): reject password-reset tokens after they expire#44
Open
clawedassistant26 wants to merge 1 commit into
Open
fix(auth): reject password-reset tokens after they expire#44clawedassistant26 wants to merge 1 commit into
clawedassistant26 wants to merge 1 commit into
Conversation
accountForResetToken compared reset_expires against SQLite's
datetime('now') as a string. reset_expires is written by setResetToken
as an ISO-8601 timestamp (Date#toISOString, e.g. "2026-07-20T20:53:43.696Z"),
whereas datetime('now') returns a space-separated form
("2026-07-20 21:23:43"). Lexically the ISO "T" separator (0x54) always
sorts after the space (0x20), so any token whose expiry falls on the
current UTC day read as still valid — defeating the intended 1-hour
expiry and keeping reset links usable for up to ~24h.
Compare against an ISO "now" (new Date().toISOString()) so it is a
like-for-like comparison; ISO-8601 UTC strings sort chronologically.
Adds a regression test (in-memory libSQL) asserting an expired token is
rejected while a future one is accepted.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Bug: password-reset tokens don't actually expire (up to ~24h instead of 1h)
Root cause
lib/db.tsaccountForResetToken()gates the token on:But
reset_expiresis written bysetResetToken()with an ISO-8601 string fromDate#toISOString()(seeapp/api/auth/reset/route.ts:new Date(Date.now() + 60*60*1000).toISOString()), e.g.2026-07-20T20:53:43.696Z. SQLite'sdatetime('now')returns a space-separated form, e.g.2026-07-20 21:23:43.The comparison is a lexical string comparison of two different formats. At index 10 the ISO
T(0x54) always sorts after the space (0x20), so for any token whose expiry timestamp falls on the current UTC day,reset_expires > datetime('now')is always true regardless of the real time. The 1-hour expiry is defeated — a reset link stays valid for the remainder of the UTC day (up to ~24h).Reproduction
In-memory libSQL, issue a token that expired 30 minutes ago:
Before the fix this returns the account id; it should return
null.Fix
Compare against an ISO "now" so it is a like-for-like comparison (ISO-8601 UTC strings sort chronologically):
reset_expiresis only ever written as an ISO string (orNULL), so ISO-vs-ISO is correct and self-consistent. Minimal, one-query change.Test
Adds
tests/reset-token-expiry.test.mjs(in-memory libSQL): a future token is accepted, an already-expired token is rejected. It fails on the current code and passes with the fix.Suite
node --experimental-strip-types --test tests/*.test.mjs-> 21 tests, 21 pass, 0 fail (20 existing + 1 new).