Enforce audience presence in JWT-SVID validation - #407
Open
bcleenders wants to merge 1 commit into
Open
Conversation
JWT-SVID §3.2 requires that tokens carry an `aud` claim and §7.2 requires validators to check it: - https://github.com/spiffe/spiffe/blob/main/standards/JWT-SVID.md#32-token-format - https://github.com/spiffe/spiffe/blob/main/standards/JWT-SVID.md#72-audience `parse()` already asserted `sub` and `exp` but not `aud`. It relied on go-jose's `claims.Validate` to enforce audience, but go-jose v4 skips the audience check when `Expected.AnyAudience` is empty: https://github.com/go-jose/go-jose/blob/8d4e64dd6193f330ff4babb4038c99c56974abff/jwt/validation.go#L92-L104 This means a nil or empty `audience` argument silently disabled all audience validation, and tokens without an `aud` claim were accepted. Fix both gaps: 1. Reject empty `audience` argument at the top of parse(), before any token processing. All internal callers already pass non-empty slices. 2. Reject tokens with no `aud` claim in the same switch that checks `sub` and `exp`, so the check is independent of go-jose behavior. Signed-off-by: bcleenders <bcleenders@spotify.com>
bcleenders
commented
Jul 24, 2026
| }, | ||
| { | ||
| name: "success", | ||
| name: "invalid typ", |
Author
There was a problem hiding this comment.
small drive-by fix; this test was incorrectly named, as you see generateToken gets "invalid" passed as its fourth argument (typ).
bcleenders
marked this pull request as ready for review
July 24, 2026 08:01
bcleenders
requested review from
MarcosDY,
amartinezfayo,
azdagron and
evan2645
as code owners
July 24, 2026 08:01
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.
JWT-SVID §3.2 requires that tokens carry an
audclaim and §7.2 requires validators to check it: "The aud claim MUST be present, containing one or more values. Validators MUST reject tokens without an aud claim set, [...]"parse()already assertedsubandexpbut notaud. It relied on go-jose'sclaims.Validateto enforce audience, but go-jose v4 skips the audience check whenExpected.AnyAudienceis empty:https://github.com/go-jose/go-jose/blob/8d4e64dd6193f330ff4babb4038c99c56974abff/jwt/validation.go#L92-L104
This means a nil or empty
audienceargument silently disabled all audience validation, and tokens without anaudclaim were accepted.Fix:
audienceargument at the top of parse(), before any token processing. All internal callers already pass non-empty slices.audclaim in the same switch that checkssubandexp, so the check is independent of go-jose behavior.