[PR #8412] fix(passkey): prevent stale expired verification reads #7958

Open
opened 2026-03-13 13:54:35 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8412
Author: @Oluwatobi-Mustapha
Created: 3/5/2026
Status: 🔄 Open

Base: canaryHead: fix/passkey-cleanup-race-8376


📝 Commits (3)

  • fb0663e fix(passkey): prevent stale expired verification reads
  • c106e61 style: fix biome formatting in verification cleanup
  • 8e3bd67 fix(passkey): avoid global verification cleanup behavior change

📊 Changes

4 files changed (+60 additions, -22 deletions)

View changed files

📝 packages/better-auth/src/db/internal-adapter.test.ts (+18 -0)
📝 packages/better-auth/src/db/internal-adapter.ts (+28 -13)
📝 packages/core/src/types/context.ts (+6 -1)
📝 packages/passkey/src/routes.ts (+8 -8)

📄 Description

Fixes #8376

Run verification cleanup before lookup in findVerificationValue so expired verification tokens are not returned.

Updates the internal adapter regression test to assert expired values return null while cleanup hooks still execute.


Summary by cubic

Adds an optional cleanupBeforeFind flag to findVerificationValue and uses it in passkey routes to avoid stale reads of expired tokens. Fixes #8376 and prevents the passkey cleanup race without changing default cleanup behavior.

  • Bug Fixes

    • Passkey registration/auth now call findVerificationValue with { cleanupBeforeFind: true } to avoid returning expired tokens.
    • Added a test confirming expired verifications return null while delete hooks still run.
  • Refactors

    • Introduced cleanupBeforeFind option in InternalAdapter and kept default cleanup after lookup to avoid global behavior changes.
    • Minor formatting cleanup.

Written for commit 8e3bd6719b6ee7f78f13223eae7fbb1a8863e072. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/8412 **Author:** [@Oluwatobi-Mustapha](https://github.com/Oluwatobi-Mustapha) **Created:** 3/5/2026 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `fix/passkey-cleanup-race-8376` --- ### 📝 Commits (3) - [`fb0663e`](https://github.com/better-auth/better-auth/commit/fb0663ee4cb2f656415b1ec1fd67ac3ef7a9c5b0) fix(passkey): prevent stale expired verification reads - [`c106e61`](https://github.com/better-auth/better-auth/commit/c106e61e4c11fb3af2f69e1139fd3860ea010883) style: fix biome formatting in verification cleanup - [`8e3bd67`](https://github.com/better-auth/better-auth/commit/8e3bd6719b6ee7f78f13223eae7fbb1a8863e072) fix(passkey): avoid global verification cleanup behavior change ### 📊 Changes **4 files changed** (+60 additions, -22 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/internal-adapter.test.ts` (+18 -0) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+28 -13) 📝 `packages/core/src/types/context.ts` (+6 -1) 📝 `packages/passkey/src/routes.ts` (+8 -8) </details> ### 📄 Description Fixes #8376 Run verification cleanup before lookup in `findVerificationValue` so expired verification tokens are not returned. Updates the internal adapter regression test to assert expired values return `null` while cleanup hooks still execute. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds an optional cleanupBeforeFind flag to findVerificationValue and uses it in passkey routes to avoid stale reads of expired tokens. Fixes #8376 and prevents the passkey cleanup race without changing default cleanup behavior. - **Bug Fixes** - Passkey registration/auth now call findVerificationValue with { cleanupBeforeFind: true } to avoid returning expired tokens. - Added a test confirming expired verifications return null while delete hooks still run. - **Refactors** - Introduced cleanupBeforeFind option in InternalAdapter and kept default cleanup after lookup to avoid global behavior changes. - Minor formatting cleanup. <sup>Written for commit 8e3bd6719b6ee7f78f13223eae7fbb1a8863e072. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:54:35 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#7958