Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds production-grade JWT verification using EdDSA (Ed25519) with JWKS key discovery, while retaining an HMAC (HS256) fallback for development. This replaces the previous gin-jwt-based middleware with a custom Gin handler that performs explicit claim validation, IdP/JWKS verification, and (in EdDSA mode) in-process replay detection.
Changes:
- Replace
gin-jwtmiddleware with a custom JWT verifier supporting HS256 (dev) and EdDSA+JWKS (prod). - Add EdDSA-focused tests (issuer, kid, alg downgrade, expiry, replay) and HMAC regression tests.
- Add runtime configuration for JWKS/issuer/audience selection and update documentation/dependencies accordingly.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/middleware/jwt.go | New JWT middleware implementation supporting HS256 + EdDSA/JWKS, plus header parsing and error responses. |
| src/middleware/jwt_test.go | New middleware-level tests for both modes, including replay and clock-skew scenarios. |
| src/middleware/jti_cache.go | Adds an in-process JTI replay cache with periodic sweeping. |
| src/main.go | Adds env-driven JWT mode selection and JWKS wiring via keyfunc. |
| src/go.mod | Drops gin-jwt, upgrades to golang-jwt/jwt/v5, adds keyfunc/v3. |
| src/go.sum | Dependency checksum updates consistent with module changes. |
| README.md | Documents new JWT modes/env vars and token requirements. |
| ### HMAC (development) | ||
|
|
||
| Active when `FMSG_JWT_JWKS_URL` is unset. Tokens must be HS256-signed with the | ||
| shared secret in `FMSG_API_JWT_SECRET`. Required claims are `sub` and `exp`; |
Comment on lines
+51
to
+57
| if len(c.entries) >= jtiCacheMaxEntries { | ||
| c.sweepLocked(now) | ||
| if len(c.entries) >= jtiCacheMaxEntries { | ||
| // Cache full of unexpired entries; refuse to grow but do not | ||
| // falsely flag the token as a replay. | ||
| return false | ||
| } |
| fmsg IdP and signed with Ed25519. The JWKS endpoint is polled on a schedule; | ||
| the IdP can rotate keys by adding a new JWK with a fresh `kid`. | ||
|
|
||
| Required token header: `alg: EdDSA`, `kid: <known to JWKS>`, `typ: JWT`. |
Comment on lines
+73
to
+80
| c, _ := gin.CreateTestContext(w) | ||
| c.Request = httptest.NewRequest(http.MethodGet, "/fmsg", nil) | ||
| if token != "" { | ||
| c.Request.Header.Set("Authorization", "Bearer "+token) | ||
| } | ||
| called := false | ||
| c.Set("__test_next__", &called) | ||
| mw(c) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.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.
Closes #11