Skip to content

jwt: Settings rejects out-of-range NumericDate precision - #2092

Merged
lestrrat merged 1 commit into
develop/v4from
fix-v4-settings-precision-out-of-range
Apr 29, 2026
Merged

lestrrat merged 1 commit into
develop/v4from
fix-v4-settings-precision-out-of-range

Conversation

@lestrrat

Copy link
Copy Markdown
Collaborator

jwt.Settings() previously silently swallowed out-of-range values for WithNumericDateParsePrecision and WithNumericDateFormatPrecision — the option loop guarded v >= 0 && v <= MaxPrecision and dropped non-matching values, then Settings always returned nil. A caller mis-typing the precision got no signal; the global state stayed at its previous value, and parsing/formatting proceeded with the old (possibly default) precision.

Replace the silent-ignore with an explicit error returned before the mutex is acquired, naming the offending option and the valid range. Out-of-range values no longer mutate global state under any circumstances. Valid values still succeed unchanged.

Regression test in jwt/jwt_test.go:TestSettingsRejectsOutOfRangePrecision covers parse-precision, format-precision, both above-MaxPrecision and negative values, plus a positive case that valid values still succeed.

Settings() previously silently swallowed out-of-range values for
WithNumericDateParsePrecision and WithNumericDateFormatPrecision —
the option-loop guarded `v >= 0 && v <= MaxPrecision` and dropped
non-matching values, then Settings always returned nil. A caller
mis-typing the precision got no signal; the global state stayed at
its previous value, and parsing/formatting proceeded with the old
(possibly default) precision.

Replace the silent-ignore with an explicit error returned before
the mutex is acquired, naming the offending option and the valid
range. Out-of-range values no longer mutate global state under any
circumstances. Valid values still succeed unchanged.
@lestrrat
lestrrat merged commit 9b854d2 into develop/v4 Apr 29, 2026
7 checks passed
@lestrrat
lestrrat deleted the fix-v4-settings-precision-out-of-range branch April 29, 2026 12:08
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.

1 participant