Repository navigation
Don't attach a stale client-assertion error description to unrelated token errors - #896
Merged
Merged
Conversation
…token errors UdapJwtSecretValidator records an error description in HttpContext.Items when a client assertion fails UDAP validation, and UdapTokenResponseMiddleware injects it into any 400 token response that lacks one. When another ISecretValidator then authenticates the client (e.g. private_key_jwt against a registered JWKS), that text was attached to unrelated errors, so a revoked refresh token came back as invalid_grant "Client assertion JWT validation failed". - UdapJwtSecretValidator declines an assertion with no x5c header without recording a description, since it is not a UDAP client assertion. - UdapTokenResponseMiddleware injects the stored description only on invalid_client. Error extensions are still injected as before. Co-Authored-By: Claude Opus 5.5 <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.
Problem
When a client assertion fails UDAP validation,
UdapJwtSecretValidatorrecords an error description inHttpContext.Items.UdapTokenResponseMiddlewarethen injects that description into any 400 token response that has none of its own.Duende runs secret validators as a composite, so another
ISecretValidatorcan still authenticate the client afterwards (for example,private_key_jwtagainst a registered JWKS, with nox5c). The stale description then leaks into unrelated errors. A revoked refresh token, for instance, comes back as:{ "error": "invalid_grant", "error_description": "Client assertion JWT validation failed" }That points the client at its authentication, which was fine, rather than at the grant.
Fix
UdapJwtSecretValidator: an assertion with nox5cheader is not a UDAP client assertion. The validator now declines it quietly, without recording a description, and leaves the decision to the next validator.UdapTokenResponseMiddleware: the stored description is injected only when the error isinvalid_client. Injection of authorization-extensionextensionsis unchanged.Tests
New tests in
AuthorizationExtensionEnforcementTests:invalid_grantwith no description. Without the fix, this test fails with"Client assertion JWT validation failed".invalid_grantwith error extensions. The response still carries itserror_descriptionandextensions.The existing
TokenRequest_TamperedJwt_Returns_InvalidClient_With_ErrorDescriptiontest still shows that a real UDAP assertion failure returnsinvalid_clientwith the description.UdapServer.Tests: 369 passed, 3 skipped.🤖 Generated with Claude Code