Skip to content

Require the issuer as the only client assertion aud - #7213

Merged
jhrozek merged 1 commit into
mainfrom
as2-client-assertion-issuer-aud
Nov 22, 2026
Merged

jhrozek merged 1 commit into
mainfrom
as2-client-assertion-issuer-aud

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A private_key_jwt client assertion was accepted when its aud was the token endpoint URL, or an array that merely contained the issuer, because fosite only checks that one accepted value is among the aud values. RFC 10070 section 4 closes the audience injection attack (Hosseyni, Küsters and Würtele) by requiring the issuer identifier as the sole aud value and forbidding the token endpoint URL. The issuer is the only metadata value a client can validate (RFC 8414 section 3.3). A malicious server can publish our token endpoint URL as one of its own endpoints, get a client to sign an assertion with that URL as aud, and replay it here. An array such as ["<issuer>", "https://other-as.example"] can be replayed the same way.

  • Accept a client assertion only when aud holds the issuer and nothing else, as a string or as a one-element array. Refuse everything else with 401 invalid_client.
  • The check is its own strategy, newClientAssertionAudienceStrategy, wired in provider.go above the clock skew strategy. It covers fosite's path, the 60-second clock skew recovery path, and a caller-supplied strategy. The recovery path no longer checks aud itself.
  • Refuse an assertion that go-jose v4 cannot read (for example a padded segment, or a space or tab inside it). fosite parses with go-jose v3, which tolerates those, so leaving such a token to fosite would let an aud array past the check.
  • Log the refusal at WARN with the reason and client_id.
  • Update docs/arch/17-token-exchange-delegation.md, docs/arch/11-auth-server-storage.md and the TokenEndpointPath comment.

Closes #7039

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests: go test -race ./pkg/authserver/server/ ./pkg/authserver/
  • E2E tests (task test-e2e)
  • Linting: golangci-lint run ./pkg/authserver/...
  • Manual testing (describe below)

New and changed tests:

  • TestClientAssertionAudience runs every aud shape (issuer as a string and in a one-element array, token URL, extra values, empty array, null, missing, empty string, numbers) on fosite's path and on the clock skew path, and asserts the hint and that no jti is reserved for a refused assertion.
  • TestClientAssertionAudienceStrategy pins that a refused assertion never reaches the strategy below, which stands in for a caller-supplied one, and that requests without a client assertion pass through untouched.
  • TestClientAssertionAudience_UnreadableEncodings pins that padded, space and tab variants are refused.
  • The wrong_subject and expired rows in TestIntegration_PrivateKeyJWTDCRTokenExchange now use the issuer as aud, so each fails for the reason in its name rather than on aud.

Does this introduce a user-facing change?

Yes, and it is a breaking change for clients that send the token endpoint URL as aud.

  • Before: a private_key_jwt client assertion was accepted with aud set to the issuer or to the token endpoint URL ({issuer}/oauth/token), as a string or inside an array with other values.
  • After: aud must hold the issuer and nothing else, as "<issuer>" or ["<issuer>"]. Anything else gets 401 invalid_client and the server logs a WARN line naming the cause.

This applies at every endpoint that authenticates clients (token, token exchange, revocation, introspection, PAR). SPIFFE JWT-SVID client authentication and the aud checks on JWT-bearer and ID-JAG grant assertions are unchanged.

Migration: switch clients to send the issuer as aud before upgrading the server. The issuer form is accepted by earlier releases too, so this order needs no downtime. Spring Security and authlib use the token endpoint URL by default, so their clients need configuring. During a rolling upgrade of a deployment that shares Redis, replicas still on the old release accept the token URL and upgraded ones refuse it, so a client that has not switched sees intermittent 401s until the rollout finishes. The architecture docs have described the token URL form as deprecated, to be refused in a later release, since v0.58.0.

Special notes for reviewers

  • The issue asked for an opt-in setting. There is none: the check always applies. A sole token-URL aud is the case RFC 10070 was written for, not only a conformance gap, so a grace period would keep the attack open for another release. The deprecation has been documented since v0.58.0.
  • The issue said "as a single string". A one-element array holding only the issuer is accepted too: RFC 7519 section 4.1.3 makes the array the general form, the RFC 10070 working group decided to allow a single-member array (draft-11 document history, entry for -03), and golang-jwt serializes a single audience as an array by default.
  • The audience strategy applies to a caller-supplied ClientAuthenticationStrategy on purpose, the same way the JWS guard does. No code in this repo or in Mecatl supplies one.
  • The refusal logs at WARN on purpose, as the request-shape exception in the logging rules. It is reachable by unauthenticated callers, but it is the only signal an operator gets when a client that worked before the upgrade starts failing.
  • The check reads the claims without verifying the signature. That is safe because it can only refuse; the strategy below still verifies the signature on everything that passes.

@jhrozek
jhrozek requested a review from ChrisJBurns as a code owner November 22, 2026 09:26
@github-actions github-actions Bot added the size/M Medium PR: 300-599 lines changed label Nov 22, 2026

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The check is correct and in the right place, but it is an unconditional breaking change that the PR and issue #7039 don't agree on.

Design: Enforcing the audience in front of fosite's client-authentication strategy is the right layer. Every client-authenticating endpoint goes through it, and narrowing GetTokenURLs to the issuer has no other consumer in this repo. The extra go-jose v4 "unreadable" refusal is needed because fosite parses with v3. The concern is the rollout: after upgrade, any client that sends the token URL as aud (Spring Security and authlib default to it) gets 401 invalid_client, and there is no switch to turn that off.

  1. private_key_jwt_client_auth.go:50-55, :120: the behaviour change contradicts #7039, which says "with it off, behavior is unchanged" and asks what the default is so existing clients can migrate. The PR drops the option and rejects the token URL everywhere in one release. Your point about the replay hole is right for multi-value aud, which is the real exploit. It is much weaker for a sole token-URL aud, which is a spec-conformance issue, and the old doc text promised a deprecation period. Suggested fix: always refuse multi-value aud, and keep accepting a sole token-URL aud for one more release with a deprecation WARN. Alternatively, get maintainer agreement that the hard break is intended and add an explicit breaking-change and migration note to the PR body and release notes. Also mention that during a rolling upgrade on shared Redis, old replicas accept the token URL and new ones refuse it, so clients can see intermittent 401s.

  2. private_key_jwt_client_auth.go:107-121, provider.go:746-755: the audience check now runs before next even when recoverTimeErrors is false, which is the path where a caller-supplied ClientAuthenticationStrategy is preserved. An embedder that sets its own strategy previously chose its own audience rules. Now every private_key_jwt request is refused unless aud is the issuer alone, before that strategy's client lookup runs. I found no in-repo setter, so this is a risk for embedders only. Suggested fix: apply the check only when recoverTimeErrors is true, or say in the PR that this is deliberate. Moving it into its own small decorator wired in provider.go would make that choice explicit and leave the skew function's signature alone.

🤖 Reviewed with Claude Code

@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.64%. Comparing base (2d33d6b) to head (f852ed3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7213      +/-   ##
==========================================
+ Coverage   81.58%   81.64%   +0.06%     
==========================================
  Files         898      898              
  Lines       91550    91601      +51     
==========================================
+ Hits        74692    74790      +98     
+ Misses      16853    16806      -47     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

A private_key_jwt client assertion could carry the token endpoint URL
as aud, or an array holding the issuer plus other values, because
fosite only checks that one accepted value is among the aud values.
RFC 10070 section 4 requires the issuer identifier as the sole aud
value and forbids the token endpoint URL, so a client assertion made
for one endpoint could be replayed at another.

Accept only an aud that holds the issuer and nothing else, as a string
or as a one-element array, which RFC 7519 and RFC 10070 both allow.
Refuse everything else with 401 invalid_client, and log the refusal at
WARN so operators can see why a client that worked before now fails.
The check runs before fosite so it covers both the normal path and the
clock skew recovery path, and it refuses an assertion that go-jose v4
cannot read, because fosite's go-jose v3 parser accepts encodings that
v4 rejects. There is no setting.

Closes #7039

Co-authored-by: Mecatl <noreply@mecatl.dev>
@jhrozek
jhrozek force-pushed the as2-client-assertion-issuer-aud branch from 5ecd7a2 to f852ed3 Compare November 22, 2026 10:16
@github-actions github-actions Bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Nov 22, 2026
@jhrozek

jhrozek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

On the hard break: I'd like to keep it, but I disagree that a sole token-URL aud is only a conformance issue. It's actually the case RFC 10070 was written for. The audience injection attack works because a client can't validate endpoint URLs from another server's metadata, only the issuer (RFC 8414 section 3.3). So a malicious AS publishes our token endpoint URL as one of its own endpoints, the client signs an assertion with that URL as aud and sends it to the attacker, and the attacker replays it here. Section 1 of the RFC says this directly: "Other endpoint values of the metadata cannot be directly validated and, if used as the audience when sent to a different endpoint, can open an attack vector." Keeping the token URL for another release would keep exactly that open. Also, the deprecation period already happened, at least on paper: docs/arch/17 has said "Both are deprecated. A later release will require the issuer as the sole value" since v0.58.0.

You're right that the PR didn't say enough about migration, so I've updated the body. It now marks this as a breaking change, says to switch clients to the issuer before upgrading (the issuer form works on old releases too), names Spring Security and authlib as defaulting to the token URL, and mentions the intermittent 401s during a rolling upgrade on shared Redis.

On the caller-supplied strategy: applying the check there is deliberate, same as the JWS guard, and nothing in this repo or in Mecatl sets one. I took your decorator suggestion though, because it makes that choice visible. The check now lives in its own newClientAssertionAudienceStrategy, wired in provider.go above the clock skew strategy, and the skew strategy's signature is back to what it was on main. There's a new TestClientAssertionAudienceStrategy with a stub next strategy that pins that a refused assertion never reaches it. It also covers the line Codecov flagged.

@github-actions github-actions Bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Nov 22, 2026

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-review of f852ed3: approve. Both earlier findings are settled.

  1. Unconditional breaking change vs #7039: withdrawn. A sole token-URL aud is the audience-injection case the spec describes, so a grace period would keep the hole open, and the arch doc has called both forms deprecated since v0.58.0. The PR body now carries the breaking-change and migration note, including the rolling-upgrade 401 caveat.
  2. Audience check running with a caller-supplied strategy: resolved. The check is its own decorator in provider.go, the clock-skew function's signature is back to main's, and the PR and code comment state that it deliberately applies to a caller-supplied strategy, like the JWS guard. That was the alternative we offered. No in-repo code sets that strategy, and TestClientAssertionAudienceStrategy pins that a refused assertion never reaches the inner strategy.

Non-blocking follow-ups:

  • The "audience strategy must stay above the clock-skew strategy" rule is enforced only by a comment (provider.go:~758), and the test harness rebuilds the wrapping by hand, so reordering in provider.go would not fail a test. An integration case through NewAuthorizationServer with a skewed assertion and aud: [issuer, "other"] would pin it.
  • Flag this as breaking in the release notes when the release is cut.

🤖 Reviewed with Claude Code

@jhrozek
jhrozek merged commit 112147d into main Nov 22, 2026
49 checks passed
@jhrozek
jhrozek deleted the as2-client-assertion-issuer-aud branch November 22, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Authorization server: require the issuer as the only aud of a private_key_jwt client assertion

3 participants