Skip to content

Return invalid_target when token exchange refuses an audience parameter #7027

Closed

Description

@jhrozek

Found while working out the fix for #7026.

Problem

When token exchange refuses a requested audience because it is not in the client's audiences, the error code depends on which parameter the client used (pkg/authserver/server/tokenexchange/handler.go at v0.60.0):

Request Check Error today
resource=X grantResourceAudience → ValidateClientAudience invalid_target
audience=X grantAudiences → fosite DefaultAudienceMatchingStrategy invalid_request, "Requested audience 'X' has not been whitelisted by the OAuth 2.0 Client."
neither, sole default audience not in audiences grantDefaultAudience invalid_request

RFC 8693 §2.2.2 says invalid_target SHOULD be used when the authorization server is unwilling or unable to issue a token for the requested resource or audience. Only the resource path does that.

Change

Map the audience-strategy refusal in grantAudiences to invalid_target, with a hint that does not say which list refused it, as errResourceNotPermitted does in pkg/authserver/server/audience.go. Decide in the same change whether grantDefaultAudience maps too. Its refusal is arguably a missing-parameter case rather than a target refusal, so either answer is fine, but write down which one and why.

Map only the audience check failure, not every invalid_request from that function (an unparsable audience URI is still a malformed request).

User-facing change

Every client type sees this, including delegate clients configured through the CRDs: a token-exchange request with audience= for an audience the client may not have gets invalid_target instead of invalid_request. The HTTP status stays 400. No test in the repo asserts the current code, but a client that branches on the error code would notice. Note it before/after in the PR body and in docs/arch/17-token-exchange-delegation.md.

Acceptance

  • Token exchange with audience=X, X not in the client's audiences: invalid_target.
  • Same with resource=X: invalid_target, as today.
  • The chosen behaviour for the default-audience refusal is tested and documented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions