chore(otp): clamp OtpExp to the max safe duration - #2781
Open
annabkr wants to merge 1 commit into
Open
Conversation
`time.Duration` counts nanoseconds in an int64, so converting an OtpExp above math.MaxInt64 / time.Second wraps to a negative duration. That would make `isOtpExpired` treat every token as already expired. This is defensive, not a fix for an observed bug. Hosted projects are capped at 2147483647 by the platform's int4 config column, roughly 4x below the overflow threshold, so the clamp cannot trigger for them. It guards self-hosted deployments, where GOTRUE_MAILER_OTP_EXP and GOTRUE_SMS_OTP_EXP are unbounded, and it lets the #nosec G115 annotation at verify.go:792 be justified from within this repo.
annabkr
force-pushed
the
annabaker/auth-1572-clamp-otp-exp
branch
from
September 2, 2026 20:46
7c351a2 to
4d8405b
Compare
annabkr
marked this pull request as ready for review
September 2, 2026 20:51
annabkr
commented
Sep 2, 2026
xlgmokha
reviewed
Sep 2, 2026
xlgmokha
approved these changes
Sep 2, 2026
xlgmokha
reviewed
Sep 2, 2026
fadymak
approved these changes
Sep 3, 2026
hf
approved these changes
Sep 4, 2026
Contributor
|
Yea title should be |
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.
The platform caps
*_OTP_EXPvalues between(0, POSTGRES_MAX_INT)which is below the max threshold.However, this isn't enforced on our end. @fadymak raised a question about it on another PR, so it felt like adding clamping logic would help make the answer to the question more direct next time.
What kind of change does this PR introduce?
Feat ?
What is the current behavior?
No maximum values are enforced.
ApplyDefaultsonly converts0to the defaults, otherwise the values get passed through as configured.If a value too large is configured by a self-hosted user, it will overflow and mark tokens as expired upon creation.
What is the new behavior?
There is an enforced max value.
ApplyDefaultsclamps both SMS and email OTP expiration config values to:This means that values above the ceiling would reduce to it instead of becoming negative.
Additional context
Add any other context or screenshots.