fix: empty or malformed JWTs now produce a zero expiration without dereferencing a nil token - #1097
Merged
Merged
Conversation
Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
…referencing a nil token Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves robustness around bearer token handling by preventing nil dereferences during JWT expiration parsing and by adding a fast-path for in-memory bearer tokens when no token file is configured.
Changes:
- Avoids nil dereferences in
bearerExpirationTimeby checking parse errors / nil tokens and validating claim types. - Updates
BearerToken()to return the configured in-memory token whenbearerTokenFileis empty. - Fixes the
--allowed-pathsflag to populateallowedPaths(instead of an unrelated variable) and removes the unused variable.
Reviewed changes
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
main.go |
Fixes CLI flag wiring for --allowed-paths and removes an unused slice variable. |
internal/webserver/webserver.go |
Hardens JWT expiration parsing and adjusts bearer token retrieval behavior (file vs in-memory). |
Suppressed comments (1)
internal/webserver/webserver.go:839
bearerExpirationTimecan still panic when the JWT is missing anexpclaim (or it is null) becauseclaims["exp"].(type)will type-assert on a nil interface. Also, whenexpis absent/invalid the current code falls back tomil=0and returnstime.Unix(0,0)(1970-01-01) instead of a zerotime.Time{}as intended by the PR.
var mil int64
switch iat := claims["exp"].(type) {
case float64:
mil = int64(iat)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…referencing a nil token Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
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.
Reported via #1095