jwt: Settings rejects out-of-range NumericDate precision - #2092
Merged
Merged
Conversation
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.
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.
jwt.Settings()previously silently swallowed out-of-range values forWithNumericDateParsePrecisionandWithNumericDateFormatPrecision— the option loop guardedv >= 0 && v <= MaxPrecisionand dropped non-matching values, thenSettingsalways returnednil. 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:TestSettingsRejectsOutOfRangePrecisioncovers parse-precision, format-precision, both above-MaxPrecisionand negative values, plus a positive case that valid values still succeed.