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

Open
opened 2026-04-13 10:26:24 -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: mainHead: fix/passkey-cleanup-race-8376


📝 Commits (3)

  • 8e96951 fix(passkey): prevent stale expired verification reads
  • 0068c69 style: fix biome formatting in verification cleanup
  • 6f6ca4c 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 the internal adapter’s findVerificationValue and uses it in passkey routes to prevent returning expired verification tokens. Fixes #8376 while keeping the default cleanup behavior unchanged.

  • Bug Fixes

    • Passkey registration/auth call findVerificationValue with { cleanupBeforeFind: true } to stop stale reads.
    • Added a test confirming expired verifications return null and delete hooks still run.
  • Refactors

    • Introduced cleanupBeforeFind in the InternalAdapter API and updated types.
    • Preserved default cleanup-after-find to avoid global behavior changes.

Written for commit 6f6ca4ca57. 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:** `main` ← **Head:** `fix/passkey-cleanup-race-8376` --- ### 📝 Commits (3) - [`8e96951`](https://github.com/better-auth/better-auth/commit/8e969511ccf5d24fd37158a8ab4f16bdccbf0e55) fix(passkey): prevent stale expired verification reads - [`0068c69`](https://github.com/better-auth/better-auth/commit/0068c69e57fab4b8d90d5fd54e0545bec309364e) style: fix biome formatting in verification cleanup - [`6f6ca4c`](https://github.com/better-auth/better-auth/commit/6f6ca4ca57d07819f5e4e0321e6bc6ff9c69671d) 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 the internal adapter’s findVerificationValue and uses it in passkey routes to prevent returning expired verification tokens. Fixes #8376 while keeping the default cleanup behavior unchanged. - **Bug Fixes** - Passkey registration/auth call findVerificationValue with { cleanupBeforeFind: true } to stop stale reads. - Added a test confirming expired verifications return null and delete hooks still run. - **Refactors** - Introduced cleanupBeforeFind in the InternalAdapter API and updated types. - Preserved default cleanup-after-find to avoid global behavior changes. <sup>Written for commit 6f6ca4ca57d07819f5e4e0321e6bc6ff9c69671d. 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-04-13 10:26:24 -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#16204