Repository navigation
Return invalid_target when token exchange refuses an audience - #7050
Merged
ChrisJBurns merged 2 commits intoNov 5, 2026
Merged
ChrisJBurns merged 2 commits into
ChrisJBurns merged 2 commits into
Conversation
RFC 8693 section 2.2.2 says invalid_target SHOULD be returned when the authorization server refuses a requested resource or audience. The token exchange handler surfaced fosite's invalid_request instead. Map a refused audience or resource to invalid_target with a hint naming the offending value. Unparsable audience URIs and the default-audience path keep invalid_request, since no valid target was requested there. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: Alex Castillo <[email protected]>
pcbeingused333
requested review from
ChrisJBurns,
JAORMX,
amirejaz,
jhrozek,
rdimitrov and
tgrunnagle
as code owners
November 4, 2026 08:58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: Alex Castillo <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7050 +/- ##
==========================================
+ Coverage 80.62% 80.76% +0.13%
==========================================
Files 857 859 +2
Lines 87455 87925 +470
==========================================
+ Hits 70512 71012 +500
+ Misses 16938 16908 -30
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ChrisJBurns
approved these changes
Nov 5, 2026
Collaborator
|
Thank you @pcbeingused333 !! 🚀 |
This was referenced Nov 6, 2026
Merged
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.
Summary
RFC 8693 §2.2.2 says
invalid_targetSHOULD be returned when the authorization server refuses a requestedresourceoraudience. The token exchange handler already did this forresource, but foraudienceit passed fosite's audience-matching error through unchanged, and that error isinvalid_request. A client that branches on the error code saw a different code depending on which parameter it used.server.ErrAudienceNotPermitted(audience), next toerrResourceNotPermitted:ErrInvalidTargetwith a hint naming the refused value. Like theresourcehint, it does not say which list refused it.grantAudiencesreturns it when the audience strategy refuses a requested audience. When several are requested, the hint names the first refused one.audiencethat is not a parseable URI keepsinvalid_request, because that is a malformed request.grantDefaultAudience): when the request names no target and the server's sole default audience is not one of the client's audiences, the refusal staysinvalid_request. The client did not request a target, and the existing hint already tells it to send an explicitresourceoraudience. This case is tested and documented.resource=Xoutside the client's audiences is stillinvalid_target. That is unchanged and now covered in the same test.docs/arch/17-token-exchange-delegation.md.Before (
audience=https://other.example, which is not one of the client's audiences):After:
Fixes #7027
Type of change
Test plan
go test ./pkg/authserver/server/..., plusgo vetandgofmt -lon the package; not the fulltask test)task test-e2e)golangci-lint run ./pkg/authserver/server/..., v2.15.0 with the repo.golangci.yml: 0 issues)The new
TestTokenExchangeHandler_AudienceRefusalErrorCodehas 5 cases: refused audience, second of two audiences refused, refused resource, unparsable audience, and refused default audience. The two audience cases fail without the fix. The audience rows inhandler_test.goandhandler_source_policy_test.goasserted the oldinvalid_request. They are updated, and they also fail without the fix.Does this introduce a user-facing change?
Yes. A token exchange request whose
audienceis outside the client's audiences now getsinvalid_targetinstead ofinvalid_request, the same asresource.This change was prepared with the help of an AI coding assistant (Claude); the submitter is responsible for it.