Repository navigation
fix: stop a new CIMD authorization from revoking the user's other grants - #433
Closed
matthewhenry1 wants to merge 3 commits into
Closed
matthewhenry1 wants to merge 3 commits into
matthewhenry1 wants to merge 3 commits into
Conversation
A CIMD client_id is shared by every installation and connection of the client, and so is its redirect URI: a hosted client uses one https callback for all of its connections, and a fixed loopback port or private-use scheme is the same on every device. Scoping default revocation to the redirect URI (cloudflare#299) still revoked another live connection, whose refresh then failed with 'Grant not found'. completeAuthorization() now leaves a CIMD client's existing grants alone. Pre-registered and DCR clients are unchanged.
🦋 Changeset detectedLatest commit: 0829450 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Only the default changes: a CIMD client's grants are left alone unless the application passes revokeExistingGrants: true, which keeps the 0.10.3 behavior of revoking grants from the same redirect URI.
matthewhenry1
marked this pull request as ready for review
November 25, 2026 19:02
The storage section, JSDoc and changeset now say default revocation is off for any https URL client_id, including one pre-registered in KV with CIMD fetching off, matching isClientIdMetadataDocumentUrl. The legacy-grant test now passes revokeExistingGrants: true, the only path that revokes CIMD grants. It checks that the same-redirect-URI grant is revoked and the grant without a stored redirectUri survives.
| `completeAuthorization()` stores a new grant and, by default, revokes existing grants for the same user, client, and resource after the new grant is safely stored. A grant for another registered resource is a separate authorization and is not revoked. Set `revokeExistingGrants: false` only when the application intentionally allows concurrent grants within the same resource. | ||
|
|
||
| For Client ID Metadata Document clients, whose client_id is the metadata URL shared by every installation, default revocation is additionally scoped to grants created from the same redirect URI, so one installation's re-authorization does not revoke another's. Grants created before the redirect URI was recorded are never auto-revoked by CIMD clients. | ||
| For clients whose client_id is an https URL, default revocation is off. That covers Client ID Metadata Document clients and a URL client_id pre-registered in KV with CIMD fetching off. The client_id is shared by every installation and connection, and the redirect URI doesn't tell them apart either: a hosted client uses one https callback for all of its connections, and a fixed loopback port or private-use scheme is the same on every device. So by default one authorization never revokes another's grant; grants end when they expire or when the client revokes them (RFC 7009). Passing `revokeExistingGrants: true` revokes only the CIMD client's grants created from the same redirect URI. Grants created before the redirect URI was recorded are never revoked this way. |
There was a problem hiding this comment.
🔍 Pathless HTTPS client IDs still revoke grants
A pre-registered https://client.example.com still revokes matching grants by default. The CIMD URL check requires an explicit path, which the documented exception omits.
Was this helpful? React with 👍 or 👎 to provide feedback.
Collaborator
|
Going to merge #434 which modifies this a little bit. Thank you for the quick submit though! |
sam-huckaby
pushed a commit
that referenced
this pull request
Nov 25, 2026
A new authorization from a Client ID Metadata Document client no longer revokes the user's other grants from that client. `revokeExistingGrants` now defaults to `false` for a client resolved from a metadata document, and `true` means the same for every client: revoke the user's other grants for this client and resource. Builds on #433 by @matthewhenry1 and replaces it; released as a minor because the meaning of `true` changes for CIMD clients. A CIMD `client_id` is shared by every installation and connection of the client, and nothing in the request tells them apart: - #299 limited default revocation to grants from the same redirect URI, but a hosted client uses one https callback for all its connections, so signing in a second agent revoked the first, which then failed with `invalid_grant: Grant not found` - #433 turned the default off but kept the redirect URI rule under `true`, so one option meant two things depending on the client ID - a URL `client_id` stored in KV with `clientIdMetadataDocumentEnabled` off is a registered client, so it keeps the default `true` - with the redirect URI rule gone, grant keys stop mirroring `redirectUri` into KV metadata, so a long redirect URI no longer pushes a grant over the 1,024-byte limit; the grant record and `listUserGrants()` still carry it ```ts // Default: a CIMD client's earlier grants are kept. await env.OAUTH_PROVIDER.completeAuthorization({ request, userId, scope, props, metadata }); // One grant per user and resource, for any client. For a CIMD client this signs out its other installations. await env.OAUTH_PROVIDER.completeAuthorization({ request, userId, scope, props, metadata, revokeExistingGrants: true }); ``` `npm run check` ran. I also ran cloudflare/mcp's CIMD tests against this build without the override from cloudflare/mcp#442: two sign-ins from one CIMD client keep both grants. --------- Co-authored-by: matthewhenry1 <31288868+matthewhenry1@users.noreply.github.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.
For CIMD clients,
revokeExistingGrantsnow defaults tofalse, so a new sign-in no longer revokes the user's other connections from the same client. Follows #297 / #299. mcp.cloudflare.com applies the same change directly in cloudflare/mcp#442; this PR changes the default for every other server built on the library.Problem
invalid_grant: Grant not found, and reconnecting A breaks B. Only one connection per user survives.com.example.app:/callback): the same on every device.Change
revokeExistingGrantsdefaults tofalse(option 1 from revokeExistingGrants default logs a user out of all their other devices when the client uses CIMD #297).revokeExistingGrants: truekeeps the 0.10.3 behavior: it revokes the CIMD client's grants from the same redirect URI.httpsclient ID counts as CIMD, including one pre-registered with CIMD fetching off, since a pre-registered client ID URL is shared across installations the same way (CIMD §9.2).redirectUriis still recorded on grants and returned bylistUserGrants().revokeExistingGrantsandredirectUri, anddocs/authorization-server.md, including the storage section.Tradeoffs
refreshTokenTTLruns out or the client revokes it (RFC 7009). Apps that relied on pruning can passrevokeExistingGrants: trueor callrevokeGrant().Spec alignment
Testing
In the "Grant Revocation Scoping" suite of
tests/oauth-cimd.test.ts:revokeExistingGrants: true, the only path that revokes CIMD grants. The same-redirect-URI grant is revoked and the legacy grant survives.revokeExistingGrants: true, only the grant from the same redirect URI is revoked.srcfails the changed and hosted-client tests; ignoring an explicittruefails the opt-in test; letting legacy grants match fails the legacy-grant test.npm run checkis clean (tsc, 1191/1191 tests), and the build and Prettier pass.Release
Patch, like #299: stored data doesn't change, so previously issued tokens still validate. It does change a default, so a minor bump is reasonable too.