Skip to content

feat(otp): switch one_time_tokens table to source of truth - #2788

Merged
annabkr merged 5 commits into
masterfrom
annabaker/auth-1553-switch-one_time_tokens-table-to-source-of-truth
Sep 18, 2026
Merged

annabkr merged 5 commits into
masterfrom
annabaker/auth-1553-switch-one_time_tokens-table-to-source-of-truth

Conversation

@annabkr

@annabkr annabkr commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Feat

What is the current behavior?

We dual-write token data to the one_time_tokens and users table, but read token data from them inconsistently.

What is the new behavior?

When a flag GOTRUE_EXPERIMENTAL_ENABLE_OTT_AS_SOURCE_OF_TRUTH is enabled, we treat one_time_tokens as the source of truth for token data, and only lookup the user to validate eligibility and confirm identifier binding.

Additional context

I've intentionally split out the Twilio Verify flow + Test OTP handling into a separate PR, but will wait until both are merged to release.

Closes AUTH-1553.

@annabkr
annabkr changed the base branch from master to annabaker/auth-1572-start-writing-to-one_time_tokensexpiresat September 4, 2026 19:53
@annabkr
annabkr force-pushed the annabaker/auth-1553-switch-one_time_tokens-table-to-source-of-truth branch from 2ed1e5b to 0665647 Compare September 9, 2026 16:14
@annabkr
annabkr changed the base branch from annabaker/auth-1572-start-writing-to-one_time_tokensexpiresat to annabaker/auth-1553-ott-query-helpers September 9, 2026 16:14
@annabkr
annabkr force-pushed the annabaker/auth-1553-switch-one_time_tokens-table-to-source-of-truth branch from 0665647 to 8bf17f6 Compare September 9, 2026 16:20
@annabkr
annabkr force-pushed the annabaker/auth-1553-ott-query-helpers branch 2 times, most recently from 7577774 to fc7f405 Compare September 9, 2026 19:14
@annabkr
annabkr force-pushed the annabaker/auth-1553-switch-one_time_tokens-table-to-source-of-truth branch 2 times, most recently from 31b4e74 to 6d15a97 Compare September 10, 2026 14:50
Comment thread internal/api/verify_ott.go Resolved
Comment thread internal/models/one_time_token.go Resolved
Comment thread internal/api/verify_ott.go Resolved
@annabkr
annabkr marked this pull request as ready for review September 10, 2026 20:39
@annabkr
annabkr requested a review from a team as a code owner September 10, 2026 20:39
Comment thread internal/api/verify_ott.go Resolved

@xlgmokha xlgmokha left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done! Nothing stood out for me as blockers. I left one question but it's not a blocker.

I'm not as familiar with this part of the codebase so you might choose to wait for another review from someone else or not. I trust your discretion.

Comment thread internal/api/verify_ott.go Resolved
Base automatically changed from annabaker/auth-1553-ott-query-helpers to master September 18, 2026 14:09
@annabkr
annabkr force-pushed the annabaker/auth-1553-switch-one_time_tokens-table-to-source-of-truth branch from 8d464cf to 8b451ac Compare September 18, 2026 14:39
Comment thread internal/api/verify_ott.go Resolved
Adds GOTRUE_EXPERIMENTAL_ENABLE_OTT_AS_SOURCE_OF_TRUTH, gating the
typed-OTP verification path reading its challenge from one_time_tokens
instead of the users.*_token columns. Ships dark.
Centralizes the expiry check the OTT-as-source-of-truth verification
path needs. Treats a nil ExpiresAt as expired rather than valid, since
that's the safer default for a security check.
…rAndToken

When EnableOTTAsSourceOfTruth is on, verifyUserAndToken reads the
challenge from one_time_tokens instead of the users.*_token columns.
A lookup miss is rejected as an expired or invalid token; there is no
fallback to the users columns.
Covers verifyUserAndToken against both the legacy users.*_token path
and the new one_time_tokens path with EnableOTTAsSourceOfTruth on,
across every token type.
@annabkr
annabkr force-pushed the annabaker/auth-1553-switch-one_time_tokens-table-to-source-of-truth branch from 8b451ac to 69d423c Compare September 18, 2026 14:56
Comment thread internal/api/verify_ott.go Resolved
The token type mapping returned both email change token types whatever
the config. With secure email change off, a leftover code for the
current address then completed the change, because emailChangeVerify
skips its two-party branch when the flag is off. The legacy path rejects
this, as FindUserForEmailChange looks up the current address token only
when the flag is on.

Read the flag through the API receiver and accept the new address token
alone when secure email change is off. Add a parity case for a leftover
current address code.
@blacksmith-sh

This comment has been minimized.

@annabkr
annabkr merged commit 2c2acf6 into master Sep 18, 2026
13 of 14 checks passed
@annabkr
annabkr deleted the annabaker/auth-1553-switch-one_time_tokens-table-to-source-of-truth branch September 18, 2026 16:25
annabkr added a commit that referenced this pull request Sep 18, 2026
…path (#2798)

Implementing the TestOTP + Twilio Verify logic that were intentionally
deferred in #2788.

## What kind of change does this PR introduce?
Feat

## What is the current behavior?
The `config.Experimental.EnableOTTAsSourceOfTruth` code path does not
support Test OTPs or Twilio Verify.

## What is the new behavior?
It does 🥳 

## Additional context
Closes AUTH-1553
cstockton pushed a commit that referenced this pull request Nov 16, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.198.0](v2.197.0...v2.198.0)
(2026-11-13)


### Features

* clear existing password on recover
([#2887](#2887))
([a7e97d6](a7e97d6))
* **mfa:** add recovery codes unenroll guards
([#2787](#2787))
([4b5069b](4b5069b))
* min password length uses runes, not bytes
([#2879](#2879))
([d7955e9](d7955e9))
* **openapi:** document mfa recovery codes endpoints
([2773ca5](2773ca5))
* **otp:** add link_token_hash column to one_time_tokens table
([#2800](#2800))
([4148d39](4148d39))
* **otp:** add one_time_tokens query helpers
([#2797](#2797))
([f8520b4](f8520b4))
* **otp:** handle test OTPs and Twilio Verify on the one_time_tokens
path ([#2798](#2798))
([2e9ce6c](2e9ce6c))
* **otp:** switch one_time_tokens table to source of truth
([#2788](#2788))
([2c2acf6](2c2acf6))
* **otp:** write `expires_at` when creating `one_time_tokens`
([#2766](#2766))
([d7d6afd](d7d6afd))
* **saml:** add dedicated_scope option for SAML providers
([#2893](#2893))
([bfbe078](bfbe078))


### Bug Fixes

* allow OAuth client tokens on GET /user, keep modifying actions blocked
([#2926](#2926))
([3e79d85](3e79d85))
* assert password is rejected after magic link/OTP
([#2896](#2896))
([9eb0924](9eb0924))
* **deps:** bump go to 1.27.3 to distrust compromised x509 intermediates
([a8d7070](a8d7070))
* **deps:** bump go to 1.27.4 to fix net/http server crash
([#2922](#2922))
([8872586](8872586))
* **deps:** bump google.golang.org/grpc to v1.83.1 for vulncheck
([#2818](#2818))
([8861440](8861440))
* **deps:** bump otel to v1.45.0 for vulncheck
([946e3e3](946e3e3))
* **deps:** bump x/net to v0.60.0 for http2 vulns
([c3348e8](c3348e8))
* **linkedin:** avoid panic when the email response has no elements
([6311d50](6311d50))
* make password re-encryption on sign-in conditional
([#2906](#2906))
([84ff0c0](84ff0c0))
* **mfa:** ignore verify-disabled factors in recovery codes guard
([#2824](#2824))
([79ad7b2](79ad7b2))
* **mfa:** regenerate duplicate recovery codes
([#2793](#2793))
([8be2691](8be2691))
* **models:** exclude oauth client sessions from mfa step-up
invalidation ([#2801](#2801))
([#2802](#2802))
([ae468ca](ae468ca))
* only trigger after-user-created hook on account creation
([#2656](#2656))
([64cfdf2](64cfdf2))
* **openapi:** use ErrorSchema for identity unlink 401/403 responses
([60d4bb6](60d4bb6))
* **passkeys:** count friendly_name length by runes, not bytes
([ce9a8ee](ce9a8ee))
* restrict OAuth client access tokens to OAuth endpoints
([#2898](#2898))
([384d83a](384d83a))
* **sessions:** invalidate legacy sessions with null aal
([#2792](#2792))
([8977629](8977629))
* **tools:** bump staticcheck to read go 1.27.3 export data
([9e4f25b](9e4f25b))
* Update user password on each valid signup attempt
([#2868](#2868))
([004f767](004f767))
* Update user password on each valid signup attempt (fixed)
([#2918](#2918))
([2550341](2550341))
* **vulncheck:** ignore GO-2026-6909 (crewjam/saml, no fix available)
([#2909](#2909))
([bc90ec9](bc90ec9))


### Reverts

* Update user password on each valid signup attempt
([#2912](#2912))
([35307ce](35307ce))
* Update user password on each valid signup attempt (fixed)
[#2918](#2918)
([#2921](#2921))
([1357a5b](1357a5b))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants