Skip to content

fix: empty or malformed JWTs now produce a zero expiration without dereferencing a nil token - #1097

Merged
oliverbaehler merged 4 commits into
projectcapsule:mainfrom
oliverbaehler:fix/nil-bearer
Aug 27, 2026
Merged

fix: empty or malformed JWTs now produce a zero expiration without dereferencing a nil token#1097
oliverbaehler merged 4 commits into
projectcapsule:mainfrom
oliverbaehler:fix/nil-bearer

Conversation

@oliverbaehler

@oliverbaehler oliverbaehler commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Reported via #1095

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
…referencing a nil token

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
Copilot AI lite review requested due to automatic review settings August 27, 2026 11:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 bearerExpirationTime by checking parse errors / nil tokens and validating claim types.
  • Updates BearerToken() to return the configured in-memory token when bearerTokenFile is empty.
  • Fixes the --allowed-paths flag to populate allowedPaths (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

  • bearerExpirationTime can still panic when the JWT is missing an exp claim (or it is null) because claims["exp"].(type) will type-assert on a nil interface. Also, when exp is absent/invalid the current code falls back to mil=0 and returns time.Unix(0,0) (1970-01-01) instead of a zero time.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.

Comment thread internal/webserver/webserver.go Outdated

@Svarrogh1337 Svarrogh1337 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

…referencing a nil token

Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
@oliverbaehler
oliverbaehler merged commit 81e0930 into projectcapsule:main Aug 27, 2026
12 checks passed
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.

3 participants