fix: parse aud claim from []interface{} in JWTClaims.FromMap - #887
fix: parse aud claim from []interface{} in JWTClaims.FromMap#887vincentluan wants to merge 2 commits into
Conversation
When a JWT is decoded into MapClaims (map[string]interface{}), a
multi-value `aud` claim arrives as []interface{}, not []string —
JSON arrays always decode to []interface{}. FromMap only handled
string and []string, so it silently dropped an array-encoded
audience, leaving JWTClaims.Audience empty after introspection.
Handle []interface{} the same way the `scp` claim already does,
so an audience round-trips through introspection intact.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesJWT audience claim decoding
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
JWTClaims.FromMapdrops theaudclaim when it is encoded as a JSON array, leavingJWTClaims.Audienceempty.Details
When a JWT is decoded into
MapClaims(map[string]interface{}) — which is whatDefaultSigner.Decodeproduces and what stateless JWT introspection (AccessTokenJWTToRequest→FromMapClaims→FromMap) feeds back in — a multi-valueaudclaim arrives as[]interface{}, because JSON arrays never unmarshal to[]string. The currentcase "aud"only handlesstringand[]string:So a token issued with
aud: ["foo"]round-trips through introspection with an emptyAudience(and, viaAccessTokenJWTToRequest, an emptyGrantedAudience/RequestedAudience). Any resource server that classifies or authorizes a token by reading the introspected session's audience silently sees no audience.Note
ToMapalways emitsaudas an array (ret["aud"] = c.Audience), so the array form is the common case on the wire — this isn't an edge case.Fix
Handle
[]interface{}in theaudcase, exactly as the neighbouringscpcase already does:Tests
Added
TestClaimsFromMapAudienceInterfaceSlice(the[]interface{}round-trip) andTestClaimsFromMapAudienceString(bare-stringaudper RFC 7519) intoken/jwt/claims_jwt_test.go. Existing tests still cover the[]stringpath.No behaviour change for
stringor[]stringinputs; this only recovers audiences that were previously dropped.Summary by CodeRabbit
Bug Fixes
Tests