Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Harden session JWT revocation#64

Merged
haasonsaas merged 3 commits intomainfrom
codex/asb-session-jwt-hardening
Apr 15, 2026
Merged

Harden session JWT revocation#64
haasonsaas merged 3 commits intomainfrom
codex/asb-session-jwt-hardening

Conversation

@haasonsaas
Copy link
Copy Markdown
Collaborator

Summary

  • add jti, nbf, and iss claims to ASB session JWTs and validate them on verify
  • persist the session token ID, add memory/Redis token revocation stores, and revoke token IDs when sessions are revoked
  • reject revoked token IDs during authenticated request handling and add coverage for JWT claim validation and runtime-backed revocation

Closes #6

Validation

  • go test ./internal/crypto/sessionjwt ./internal/store/memory ./internal/store/redis ./internal/app -count=1
  • go test ./... -count=1
  • go test ./... -race -count=1
  • GOTOOLCHAIN=go1.26.0 go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.11.3 run --timeout=5m ./...
  • go run github.com/securego/gosec/v2/cmd/gosec@v2.22.4 ./cmd/... ./internal/...

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 15, 2026

PR Summary

Medium Risk
Touches session-token signing/verification and request authentication paths; misconfiguration (issuer/clock skew) or revocation-store issues could block valid sessions or fail to revoke promptly.

Overview
Hardens session authentication by introducing a distinct TokenID for session JWTs (stored in DB) and adding strict JWT standard-claim handling (jti, nbf, iss) with configurable issuer and clock skew.

Adds runtime-backed session-token revocation: sessions now generate/persist token_id, RevokeSession records token revocation in the runtime store (memory/Redis), and authenticated request handling rejects revoked tokens before loading the session. Includes new migration for sessions.token_id plus tests covering JWT claim validation and revocation enforcement.

Reviewed by Cursor Bugbot for commit 03b97ea. Bugbot is set up for automated code reviews on this repo. Configure here.

RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(session.ExpiresAt),
IssuedAt: jwt.NewNumericDate(session.CreatedAt),
NotBefore: jwt.NewNumericDate(session.CreatedAt.Add(-m.clockSkew)),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Double clock skew applied to nbf claim

Low Severity

The nbf claim in Sign is set to session.CreatedAt.Add(-m.clockSkew), which already subtracts the clock skew. Then Verify applies jwt.WithLeeway(m.clockSkew), which adds another clockSkew tolerance to the nbf check. The golang-jwt library validates nbf as now >= nbf - leeway, so the effective check becomes now >= CreatedAt - 2*clockSkew. With the default 30-second clockSkew, tokens are accepted starting 60 seconds before creation rather than the intended 30. The nbf value passed to Sign likely just needs to be session.CreatedAt, letting the leeway handle clock skew uniformly across all time claims.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c85cb17. Configure here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bugbot Autofix determined this is a false positive.

Verify also enforces iat with the same leeway, so tokens still cannot be accepted before CreatedAt - clockSkew even though nbf is backdated.

You can send follow-ups to the cloud agent here.

@haasonsaas haasonsaas marked this pull request as ready for review April 15, 2026 22:52
@haasonsaas haasonsaas merged commit d06830b into main Apr 15, 2026
7 checks passed
@haasonsaas haasonsaas deleted the codex/asb-session-jwt-hardening branch April 15, 2026 22:52
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Reviewed by Cursor Bugbot for commit 03b97ea. Configure here.

manager.clockSkew = clockSkew
}
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Exported WithClockSkew option is never used

Low Severity

WithClockSkew is an exported Option function that is defined but never called anywhere in the codebase — not in production code, bootstrap wiring, or tests. It's dead code introduced in this PR.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 03b97ea. Configure here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Harden JWT tokens with jti, nbf, iss claims and revocation tracking

2 participants