fix: reject zero/negative JWT expiration at startup - #1172
Open
ShradhaGupta31 wants to merge 1 commit into
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1172 +/- ##
==========================================
+ Coverage 44.45% 44.47% +0.01%
==========================================
Files 144 144
Lines 13732 13741 +9
==========================================
+ Hits 6105 6111 +6
- Misses 7054 7056 +2
- Partials 573 574 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents a misconfigured auth.jwtExpiration / auth.redirectionJWTExpiration (zero or negative durations) from allowing the server to start and then immediately issuing already-expired JWTs, which effectively denies access to legitimate users.
Changes:
- Adds startup-time config validation for JWT expiration durations.
- Introduces sentinel errors for invalid JWT expiration settings.
- Adds unit tests covering zero/negative durations and valid defaults.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
config/config.go |
Adds Config.validate() and calls it from NewConfig() to fail fast on non-positive JWT expirations. |
config/config_test.go |
Adds tests ensuring validation rejects zero/negative expirations and accepts defaults. |
Suppressed comments (3)
config/config_test.go:133
- The test asserts via substring matching on the error string. Since validate() returns a sentinel error, use require.ErrorIs so the test remains stable if the message wording changes.
err := cfg.validate()
require.Error(t, err)
assert.Contains(t, err.Error(), "auth.jwtExpiration")
}
config/config_test.go:144
- The test asserts via substring matching on the error string. Since validate() returns a sentinel error, use require.ErrorIs so the test remains stable if the message wording changes.
err := cfg.validate()
require.Error(t, err)
assert.Contains(t, err.Error(), "auth.redirectionJWTExpiration")
}
config/config_test.go:155
- The test asserts via substring matching on the error string. Since validate() returns a sentinel error, use require.ErrorIs so the test remains stable if the message wording changes.
err := cfg.validate()
require.Error(t, err)
assert.Contains(t, err.Error(), "auth.redirectionJWTExpiration")
}
ShradhaGupta31
force-pushed
the
fix-CM-334-jwt-expiration
branch
2 times, most recently
from
August 4, 2026 15:42
b8d9299 to
e990ba4
Compare
- Modified config.go to validate jwtExpiration while console startup - Reject non-positive values of jwtExpiration Signed-off-by: ShradhaGupta31 <shradha.gupta@intel.com>
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.
Changes Done:
Description:
config.ymlacceptsjwtExpiration: 0swhich is a syntactically valid zero duration that the YAML parser accepts without error. At runtime, every issued JWT hasexp = time.Now(), so all tokens expire at the moment of issuance and every subsequent API call is rejected.Before fix : Server starts silently with jwtExpiration 0s, login returns an already-expired token:
After fix : Server would fail to start if jwtExpiration is set to 0s