Skip to content

Auth tables compare ISO timestamps against datetime('now') #1286

Open

Description

@neuromechanist

Found while planning #1281 (epic #1272). Not in that phase's scope.

auth_codes.expires_at, web_sessions.expires_at, orcid_link_intents.expires_at (and tokens.expires_at when set) are written from JavaScript with toISOString() (YYYY-MM-DDTHH:MM:SS.sssZ) and compared in SQL against datetime('now') (YYYY-MM-DD HH:MM:SS). The two formats differ at index 10 (T versus a space) and 'T' > ' ', so an ISO value compares greater than every same-day SQL datetime. A row is therefore treated as live until the end of its UTC day rather than for its TTL. For sign-in codes that means a 10-minute code can verify for up to about 24 hours; the attempt counter and rotation mitigate it, and /auth/code/verify has no JS-side expiry check (backend/src/routes/auth-web.ts around lines 430-445).

Suggested fix: write every expiry SQL-side (datetime('now', '+N seconds')), compare only in SQL, and add a migration that rewrites the stored ISO values into the SQL format so existing rows expire on time. Phase 1 of #1272 (device_codes, migration 0081) already follows the SQL-side rule and pins the format in its migration test; use it as the model.

Verification: a migration test that inserts a row expiring in ten minutes via the production INSERT, backdates the clock comparison, and asserts the consumer predicate returns zero rows; plus the existing route tests for code verify and session lookup.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendBackend/API relatedbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions