Skip to content

Enforce audience presence in JWT-SVID validation - #407

Open
bcleenders wants to merge 1 commit into
spiffe:mainfrom
bcleenders:reject-empty-audience
Open

Enforce audience presence in JWT-SVID validation#407
bcleenders wants to merge 1 commit into
spiffe:mainfrom
bcleenders:reject-empty-audience

Conversation

@bcleenders

Copy link
Copy Markdown

JWT-SVID §3.2 requires that tokens carry an aud claim 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 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:

  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.

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>
Comment thread svid/jwtsvid/svid_test.go
},
{
name: "success",
name: "invalid typ",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

small drive-by fix; this test was incorrectly named, as you see generateToken gets "invalid" passed as its fourth argument (typ).

@bcleenders
bcleenders marked this pull request as ready for review July 24, 2026 08:01
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.

1 participant