Repository navigation
fix(auth): keep OAuth revocation fields in OIDC discovery metadata - #3214
Open
marcus-beauregard wants to merge 1 commit into
Open
marcus-beauregard wants to merge 1 commit into
marcus-beauregard wants to merge 1 commit into
Conversation
`OpenIdProviderDiscoveryMetadataSchema` spread `OpenIdProviderMetadataSchema.shape` into a plain `z.object`, which dropped the loose behaviour the source schema had: every field the discovery document published but the schema did not declare was stripped on parse. A server that publishes only OpenID discovery therefore lost `revocation_endpoint` before the client could ever read it, and the client concluded revocation was unsupported. Build the schema with `z.looseObject` again, and declare the three RFC 7009 revocation fields so they arrive typed rather than merely present. Fixes modelcontextprotocol#3213.
🦋 Changeset detectedLatest commit: 9f7dba5 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This branch has not been deployed
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.
What this fixes
OpenIdProviderDiscoveryMetadataSchemawas built by spreadingOpenIdProviderMetadataSchema.shapeinto a plainz.object:OpenIdProviderMetadataSchemais az.looseObject, but spreading its.shapeinto a plain object drops that behaviour — zod then strips every key the new schema does not declare.revocation_endpointis one of them, so for an authorization server that publishes only OpenID discovery (no RFC 8414 document) the endpoint disappeared during parse:discoverAuthorizationServerMetadata()(src/client/auth.ts:1127) parses the discovery response with this schema and hands the result on asAuthorizationServerMetadata, so a client readingrevocation_endpointfrom it sawundefinedand had no way to know the server supports revocation.The change
src/shared/auth.ts: build the schema withz.looseObjectagain, and pickrevocation_endpoint,revocation_endpoint_auth_methods_supportedandrevocation_endpoint_auth_signing_alg_values_supportedfromOAuthMetadataSchemaso they arrive typed and keep theSafeUrlSchemaguard. Nothing else is declared — other undeclared fields now survive untyped rather than being silently dropped, which is what the "mix of OpenID Connect and OAuth 2.0 metadata fields" comment on the schema already promised.test/shared/auth.test.ts: four tests — the revocation fields survive parse; a field neither schema declares survives; a document missing the requiredresponse_types_supportedstill throws; ajavascript:revocation_endpointis rejected with the same guard message as the other URL fields..changeset/oidc-discovery-keeps-oauth-fields.md: patch.With
src/shared/auth.tsreverted tov1.x, exactly three of the new tests fail (revocation fields, unknown field, unsafe URL) and the required-field test still passes.Verification
npx vitest run test/shared/auth.test.ts— 17 passednpx vitest run test/shared test/client/auth.test.ts— 461 passednpm run typecheck(tsgo --noEmit) — cleaneslint+prettier --checkon the touched files — cleanFixes #3213. Based on
v1.xper CONTRIBUTING (v1 bug fix); the same construction exists onmaininpackages/core/src/auth.ts, and I'm happy to open the mirror there if you'd rather land it on both lines in one go.