Merged
Conversation
blkt
added a commit
that referenced
this pull request
Apr 14, 2026
An explicit empty `resource=` parameter was hitting the
`len(resources) == 1` branch and calling `GrantAudience("")`, producing
`aud:[""]` instead of the intended default. The fix is to treat an empty
string the same as an absent parameter by adding `&& resources[0] != ""`
to the condition, so an explicit empty value falls through to the
defaulting `else if` branch. A test covering this case is also added.
The comment on the defaulting branch overstated the invariant by
attributing safety to config-validation-time enforcement. The actual
safety comes from the `len == 1` guard on the same line; the comment is
updated to reflect that.
The `TokenHandler` only granted an audience claim when the client included the RFC 8707 `resource` parameter. Clients that omit this optional parameter received a token with an empty `aud`, which caused `VirtualMCPServer` to reject every token its own auth server issued: the incoming OIDC validator requires `audience` to be set and rejects tokens that do not carry a matching claim. When no `resource` parameter is present and `AllowedAudiences` contains exactly one entry, the handler now defaults to granting that audience. The intended audience is unambiguous in that case, and `AllowedAudiences` is always non-empty (enforced at config validation time). The defaulting is restricted to `authorization_code` grants; for `refresh_token` grants fosite carries the originally-granted audience forward through the stored session automatically, so re-granting would conflict with its matching strategy. Fixes #4794
An explicit empty `resource=` parameter was hitting the
`len(resources) == 1` branch and calling `GrantAudience("")`, producing
`aud:[""]` instead of the intended default. The fix is to treat an empty
string the same as an absent parameter by adding `&& resources[0] != ""`
to the condition, so an explicit empty value falls through to the
defaulting `else if` branch. A test covering this case is also added.
The comment on the defaulting branch overstated the invariant by
attributing safety to config-validation-time enforcement. The actual
safety comes from the `len == 1` guard on the same line; the comment is
updated to reflect that.
The three separate tests covering the `aud` claim behaviour of `TokenHandler` shared identical structure. Merge them into a single `TestTokenHandler_AudienceClaim` table-driven test with subtests for the explicit-resource, absent-resource, and explicit-empty-resource cases. Also upgrades the former `TestTokenHandler_ResourceParameter`, which only asserted a 200 response, to verify the `aud` claim in the issued JWT.
8f20d44 to
89a40d6
Compare
jhrozek
approved these changes
Apr 14, 2026
Contributor
Author
|
Test failures are unrelated with the change, I'll fix them anyway in a separate branch. |
jhrozek
added a commit
that referenced
this pull request
Apr 14, 2026
The fix in #4805 defaults the aud claim to the sole AllowedAudiences entry when clients omit the RFC 8707 resource parameter, but only included unit tests. Add an end-to-end integration test that verifies the full OAuth flow (authorize -> callback -> token exchange -> JWT validation) produces the correct audience when resource is omitted. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4 tasks
jhrozek
added a commit
that referenced
this pull request
Apr 14, 2026
…4818) The fix in #4805 defaults the aud claim to the sole AllowedAudiences entry when clients omit the RFC 8707 resource parameter, but only included unit tests. Add an end-to-end integration test that verifies the full OAuth flow (authorize -> callback -> token exchange -> JWT validation) produces the correct audience when resource is omitted. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
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.
The
TokenHandleronly granted an audience claim when the client included the RFC 8707resourceparameter. Clients that omit this optional parameter received a token with an emptyaud, which causedVirtualMCPServerto reject every token its own auth server issued: the incoming OIDC validator requiresaudienceto be set and rejects tokens that do not carry a matching claim.When no
resourceparameter is present andAllowedAudiencescontains exactly one entry, the handler now defaults to granting that audience. The intended audience is unambiguous in that case, andAllowedAudiencesis always non-empty (enforced at config validation time). The defaulting is restricted toauthorization_codegrants; forrefresh_tokengrants fosite carries the originally-granted audience forward through the stored session automatically, so re-granting would conflict with its matching strategy.Fixes #4794