From 6f797a139202170a68a2141695aaa24210d5870c Mon Sep 17 00:00:00 2001 From: Lily Shen <115414357+lilyshen0722@users.noreply.github.com> Date: Sun, 1 Nov 2026 01:35:56 -0700 Subject: [PATCH 1/2] fix(hosted-mcp): revoke only at the endpoint the issuer advertises (TASK-252) The RFC 7009 revoke request carries the token and, for a registered client, the client secret. It was POSTed to the entry's pinned `revoke.endpoint`, which was never compared with anything the issuer says. The authorize, token and registration endpoints already come only from the issuer's RFC 8414 metadata after an exact issuer match; the revoke endpoint was the one credential-bearing URL that did not. `revokeTokenAtVendor` now reads the issuer's metadata for every client kind and refuses, sending nothing, unless the pin equals the advertised `revocation_endpoint` exactly. A refusal surfaces as provider_revoke_failed: the row stays disconnected and retryable, the material is kept, and the person is handed the revoke page. Every live pin matched its issuer's revocation_endpoint when measured on 2026-11-01 (atlassian, google, gitlab, sentry, notion), so no entry stops revoking. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015AKgpQ2pr6xRMhN5mcfoHF --- .../unit/services/connectionRemoval.test.js | 62 ++++++++++++++++--- backend/services/connectionRemovalService.ts | 19 ++++-- 2 files changed, 68 insertions(+), 13 deletions(-) diff --git a/backend/__tests__/unit/services/connectionRemoval.test.js b/backend/__tests__/unit/services/connectionRemoval.test.js index 716a7f254c..573fe2fbf4 100644 --- a/backend/__tests__/unit/services/connectionRemoval.test.js +++ b/backend/__tests__/unit/services/connectionRemoval.test.js @@ -539,11 +539,29 @@ describe('a row whose entry is gone', () => { }); describe('revokeTokenAtVendor (RFC 7009)', () => { + // TASK-252: every revoke first reads the issuer's RFC 8414 metadata, and the + // request goes out only when the entry's pinned endpoint is the one the issuer + // advertises. `vendor` answers that GET and hands every other request to `answer`. + const metadataFor = (entry, over = {}) => ({ + issuer: entry.issuer, + authorization_endpoint: `${entry.issuer}/authorize`, + token_endpoint: `${entry.issuer}/token`, + revocation_endpoint: entry.revoke.endpoint, + ...over, + }); + const vendor = (entry, answer, metadata = metadataFor(entry)) => jest.fn(async (url, init) => ( + String(url).includes('/.well-known/oauth-authorization-server') + ? { ok: true, status: 200, json: async () => metadata } + : answer(url, init) + )); + const revokeCalls = (fetchImpl) => fetchImpl.mock.calls + .filter(([url]) => !String(url).includes('/.well-known/')); + it('marks only the refused DCR client when the vendor returns invalid_client', async () => { const registry = require('../../../services/hostedMcpDcrRegistry'); const refuse = jest.spyOn(registry, 'refuseDcrClient').mockResolvedValue(); const dcrEntry = { ...ENTRY, client: 'dcr' }; - const fetchImpl = jest.fn(async () => ({ + const fetchImpl = vendor(dcrEntry, async () => ({ ok: false, status: 401, json: async () => ({ error: 'invalid_client' }), })); try { @@ -552,15 +570,15 @@ describe('revokeTokenAtVendor (RFC 7009)', () => { tokenTypeHint: 'refresh_token', }, fetchImpl)).rejects.toMatchObject({ code: 'invalid_client' }); expect(refuse).toHaveBeenCalledWith(dcrEntry, 'retired-client'); - expect(new URLSearchParams(fetchImpl.mock.calls[0][1].body).get('client_id')) + expect(new URLSearchParams(revokeCalls(fetchImpl)[0][1].body).get('client_id')) .toBe('retired-client'); } finally { refuse.mockRestore(); } }); - it('a post-registered DCR client revokes with post, though a dcr removal reads no metadata', async () => { + it('a post-registered DCR client revokes with post', async () => { const dcrEntry = { ...ENTRY, client: 'dcr' }; - const fetchImpl = jest.fn(async () => ({ ok: true, status: 200, json: async () => ({}) })); + const fetchImpl = vendor(dcrEntry, async () => ({ ok: true, status: 200, json: async () => ({}) })); await revokeTokenAtVendor({ entry: dcrEntry, clientId: 'conf-1', @@ -569,16 +587,16 @@ describe('revokeTokenAtVendor (RFC 7009)', () => { token: 'held-token', tokenTypeHint: 'refresh_token', }, fetchImpl); - expect(fetchImpl).toHaveBeenCalledTimes(1); - const [, init] = fetchImpl.mock.calls[0]; + expect(revokeCalls(fetchImpl)).toHaveLength(1); + const [, init] = revokeCalls(fetchImpl)[0]; expect(init.headers.Authorization).toBeUndefined(); const body = new URLSearchParams(init.body); expect(body.get('client_id')).toBe('conf-1'); expect(body.get('client_secret')).toBe('registered-secret'); }); - const call = (response) => { - const fetchImpl = jest.fn(async () => response); + const call = (response, metadata = metadataFor(ENTRY)) => { + const fetchImpl = vendor(ENTRY, async () => response, metadata); return { fetchImpl, run: () => revokeTokenAtVendor({ @@ -593,7 +611,7 @@ describe('revokeTokenAtVendor (RFC 7009)', () => { it("the provider revoke sends the token to the entry's revocation endpoint", async () => { const { fetchImpl, run } = call({ ok: true, status: 200, json: async () => ({}) }); await run(); - const [url, init] = fetchImpl.mock.calls[0]; + const [url, init] = revokeCalls(fetchImpl)[0]; expect(url).toBe(ENDPOINT); expect(init.method).toBe('POST'); expect(init.headers['Content-Type']).toBe('application/x-www-form-urlencoded'); @@ -685,6 +703,32 @@ describe('revokeTokenAtVendor (RFC 7009)', () => { await expect(run()).rejects.toThrow(/HTTP 502/); }); + it('sends nothing when the issuer advertises a different revocation endpoint than the entry pins', async () => { + const { fetchImpl, run } = call( + { ok: true, status: 200, json: async () => ({}) }, + metadataFor(ENTRY, { revocation_endpoint: 'https://mcp.linear.app/oauth/revoke' }), + ); + await expect(run()).rejects.toThrow(/not the revocation_endpoint .* advertises/); + expect(revokeCalls(fetchImpl)).toHaveLength(0); + }); + + it('sends nothing when the issuer advertises no revocation endpoint at all', async () => { + const metadata = metadataFor(ENTRY); + delete metadata.revocation_endpoint; + const { fetchImpl, run } = call({ ok: true, status: 200, json: async () => ({}) }, metadata); + await expect(run()).rejects.toThrow(/not the revocation_endpoint/); + expect(revokeCalls(fetchImpl)).toHaveLength(0); + }); + + it('sends nothing when the metadata is written for another issuer', async () => { + const { fetchImpl, run } = call( + { ok: true, status: 200, json: async () => ({}) }, + metadataFor(ENTRY, { issuer: 'https://elsewhere.example' }), + ); + await expect(run()).rejects.toMatchObject({ code: 'issuer_mismatch' }); + expect(revokeCalls(fetchImpl)).toHaveLength(0); + }); + it('refuses an entry that names no endpoint rather than guessing from the page', async () => { const fetchImpl = jest.fn(async () => ({ ok: true, status: 200, json: async () => ({}) })); await expect(revokeTokenAtVendor({ diff --git a/backend/services/connectionRemovalService.ts b/backend/services/connectionRemovalService.ts index b70bccbb71..9887e26da5 100644 --- a/backend/services/connectionRemovalService.ts +++ b/backend/services/connectionRemovalService.ts @@ -182,12 +182,23 @@ export const revokeTokenAtVendor = async (input: { // would answer the empty string 200 for a request that revoked nothing. throw new Error('provider revoke refused: no token to revoke'); } - const metadata = input.entry.client === 'pre-registered' - ? await discoverAuthorizationServer(input.entry.issuer, fetchImpl) - : {}; + // TASK-252: this request carries the token and, for a registered client, its + // secret, so it goes only to the endpoint the issuer itself advertises. The + // pin is reviewed by PR, but a vendor can move its endpoint, and an unchecked + // pin would keep sending credentials to the old host. The metadata is read + // with its identity checked (`discoverAuthorizationServer`), and the compare is + // exact, as the issuer's is. Every pin equalled its issuer's + // `revocation_endpoint` when this landed (measured 2026-11-01). + const metadata = await discoverAuthorizationServer(input.entry.issuer, fetchImpl); + if (metadata.revocation_endpoint !== target.endpoint) { + throw new Error( + `provider revoke refused: ${target.endpoint} is not the revocation_endpoint ${input.entry.issuer} advertises`, + ); + } const request = buildRevocationRequest( input.entry, - metadata, + // Only a registered client reads its auth method from the metadata. + input.entry.client === 'pre-registered' ? metadata : {}, { clientId: input.clientId, ...(input.clientSecret ? { clientSecret: input.clientSecret } : {}), From ea88ab7302e55d49ef023edd886c29e71a1fc756 Mon Sep 17 00:00:00 2001 From: Lily Shen <115414357+lilyshen0722@users.noreply.github.com> Date: Sun, 1 Nov 2026 01:50:31 -0700 Subject: [PATCH 2/2] test(hosted-mcp): the callback's discovery stub advertises the revoke endpoint (TASK-252) A revoke now goes only to the revocation_endpoint the issuer advertises, and the callback test's discovery stub advertised none, so its six revoking arms were refused before the revoke. The stub now advertises the endpoint those arms pin, as every real vendor pin does. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015AKgpQ2pr6xRMhN5mcfoHF --- .../__tests__/unit/routes/hostedMcpConnect.callback.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/__tests__/unit/routes/hostedMcpConnect.callback.test.js b/backend/__tests__/unit/routes/hostedMcpConnect.callback.test.js index 845a6d3e96..181dfd92cd 100644 --- a/backend/__tests__/unit/routes/hostedMcpConnect.callback.test.js +++ b/backend/__tests__/unit/routes/hostedMcpConnect.callback.test.js @@ -160,6 +160,9 @@ beforeEach(() => { issuer: 'https://mcp.linear.app', authorization_endpoint: 'https://mcp.linear.app/authorize', token_endpoint: TOKEN_ENDPOINT, + // A revoke goes only to the endpoint the issuer advertises (TASK-252), so the + // stub advertises the one the revoking arms pin, as the real vendors do. + revocation_endpoint: 'https://mcp.linear.app/revoke', }); connectorSecrets.put.mockResolvedValueOnce('ref-access').mockResolvedValueOnce('ref-refresh'); global.fetch = jest.fn().mockResolvedValue(okTokenResponse);