Skip to content

fix(den): record the shared callback mode for isolated MCP rows with shared registrations - #4663

Merged
yomgui merged 1 commit into
devfrom
fix/mcp-callback-mode-consistency-0908
Sep 9, 2026
Merged

yomgui merged 1 commit into
devfrom
fix/mcp-callback-mode-consistency-0908

Conversation

@yomgui

@yomgui yomgui commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Problem

Callback isolation (#2868, July) moved qualifying OAuth connections to isolated-v1 and deleted SDK-registered clients, but kept administrator-supplied (pre-registered) clients together with the shared callback recorded as their registeredRedirectUri (#2771). Since #4039 made the recorded redirect authoritative, such a row sends the shared redirect_uri to the provider while connect/start signs the row's isolated-v1 mode. After provider consent, the shared callback route rejects the transaction:

This authorization callback must use the shared callback selected when authorization started.

Every sign-in on an affected connection fails at OpenWork's own callback. No supported surface creates this state today; only rows from the July window carry it.

Change

  • connect/start: when a row is not shared-v1 and its pre-registered client recorded a redirect on the shared callback route (/v1/mcp-connections/oauth/callback on any public host or base path Den emitted), record shared-v1 on that row inside a FOR UPDATE transaction before signing state, and log external_mcp_oauth_registered_shared_callback_adopted.
  • The redirect sent to the provider does not change (it was already the shared URL). Client id/secret, registeredRedirectUri, tokens, grants, and plugin bindings are untouched. The reconciled row gets the posture a newly created connection for the same provider has today (pinned-transaction mix-up defense without RFC 9207 iss, response-issuer with it).
  • Callback route validation is unchanged: the shared route still requires shared-v1, the scoped route still rejects it, and stale transactions signed with the old mode keep failing closed on both routes. SDK-registered clients, rows whose registered redirect is their own scoped callback, and rows with no registered redirect are not touched.
  • docs/external-mcp-oauth.md: one paragraph describing the exception.

Out of scope: broad start-time diagnostics for unrelated registered redirects, CORS on error responses, provider approval policies, and the docs hostname for the hosted callback URL (separate follow-up).

Verification

Verdict: Passed. Exact-head assertion evidence for all seven tests is published inline. Head 26fcf20525f79e67e72ce6bde6d02d3613ac0bdf (base 4d7727740d222f2291ebb2e6e9005c8bd86b2e16). Direct Vitest PR lane, local cold-boot Den with an isolated MySQL database and the synthetic OAuth+MCP mock; no attached Den, no real provider.

  • pnpm evals:pr specs/mcp-oauth-response-issuer.test.ts — 7 passed, 0 failed, 0 skipped (108 s). The new journey Den member sign-in recovers an isolated connection whose pre-registered client uses the shared callback seeds the historical state (pre-registered client via POST /v1/mcp-connections, row flipped to isolated-v1 through the testkit database), then asserts: admin detail shows isolated-v1 with the shared callback URL; a granted member's connect/start sends the registered shared redirect_uri with the same client id and the detail now reads shared-v1 with an unchanged client; the provider redirect lands on the shared route and the callback returns HTTP 200 with exactly one token exchange; the member lists tools with the new credential; replaying the callback is rejected without another exchange. The same spec fails on the base commit at the post-start detail assertion (mode stays isolated-v1).
  • Boundary suite ee/apps/den-api/test/mcp-connections-connect-start.test.ts — 22 pass, 0 fail (bun test --conditions development). New test reproduces the historical sequence through isolateExternalMcpOAuthCallback itself, asserts the stale-mode state is rejected by the shared route with the exact message before and after reconciliation and by the scoped route with "connection changed", verifies the token exchange used the shared redirect with the preserved client secret, and keeps a legacy row whose pre-registered client recorded its own scoped callback on legacy-v1. On the base commit this test fails at the signed state (callbackMode: "isolated-v1").
  • pnpm --filter @openwork-ee/den-api exec tsc --noEmit -p . — clean. pnpm --filter @openwork-ee/den-api test — 24 pass.
  • Pre-existing, unrelated on the same base: mcp-connections-edit.test.ts › "marketplace bindings protect identity…" (identityManagedBy provenance) and the Den-as-authorization-server refresh suites fail identically with this change stashed; evals boundary/channel ratchets and lint:layers report the same pre-existing debt on base.

Live provider behaviour after deployment (consent, token issuance, reviewed-client policy) remains a separate gate; this PR only makes Den's stored callback mode agree with the redirect it already sends.

…shared registrations

Callback isolation (July) kept administrator-supplied OAuth clients while
flipping rows to isolated-v1. Since registered redirects became authoritative,
such a row sends its client's shared redirect but signs the isolated mode, so
the shared callback route rejects every transaction after provider consent.

connect/start now records shared-v1 on a non-shared row whose pre-registered
client recorded the shared callback route as its redirect. The redirect sent to
the provider, client registration, credentials, grants, and bindings are
unchanged; stale transactions keep failing closed on both routes.
@vercel

vercel Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openwork-app Ready Ready Preview Sep 9, 2026 4:20am UTC
openwork-den Ready Ready Preview Sep 9, 2026 4:20am UTC
openwork-diagnostics Building Building Preview Sep 9, 2026 4:20am UTC
openwork-landing Ready Ready Preview, v0 Sep 9, 2026 4:20am UTC

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Passed · 1/1 tests · 2/2 assertions · 0 images

Commit 26fcf20525f79e67e72ce6bde6d02d3613ac0bdf · selected evidence

Open review report

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (26fcf20525f79e67e72ce6bde6d02d3613ac0bdf). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@yomgui

yomgui commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

Test evidence — pnpm evals:pr specs/mcp-oauth-response-issuer.test.ts — Passed (7 passed, 0 failed, 0 skipped)

PR head 26fcf20525f79e67e72ce6bde6d02d3613ac0bdf · direct Vitest PR lane, local cold-boot Den with isolated MySQL database and the synthetic OAuth+MCP mock · exit 0 · 107.9 s. The review-app uploader is unavailable here (OPENWORK_REVIEW_URL unset), so the repository renderer's per-test sections follow inline. Redo: pnpm evals:pr specs/mcp-oauth-response-issuer.test.ts then pnpm evals:e2e --publish --pr 4663 --all.

Test evidence — local OAuth (issuer support true) validates callbacks and preserves usable credentials — ✅ passed

SHA 26fcf20 · engine v1

✅ passed · 6 expectations passed · 0 failed · 0 pending

Rendered locally from the stored run (no screenshots in this HTTP-boundary spec).

verdict passed · 0 user observations · 0 probes · steps 0/0

ℹ️ ASSERTION — 1. Reject mismatch callback before token exchange

HTTP 500; zero token requests; connection is not connected.

  • ✅ PASS Reject mismatch callback before token exchange — HTTP 500; zero token requests; connection is not connected.

ℹ️ ASSERTION — 2. Reject missing callback before token exchange

HTTP 500; zero token requests; connection is not connected.

  • ✅ PASS Reject missing callback before token exchange — HTTP 500; zero token requests; connection is not connected.

ℹ️ ASSERTION — 3. Reject empty callback before token exchange

HTTP 500; zero token requests; connection is not connected.

  • ✅ PASS Reject empty callback before token exchange — HTTP 500; zero token requests; connection is not connected.

ℹ️ ASSERTION — 4. Reject state callback before token exchange

HTTP 400; zero token requests; connection is not connected.

  • ✅ PASS Reject state callback before token exchange — HTTP 400; zero token requests; connection is not connected.

ℹ️ ASSERTION — 5. Sign-in supports true issuer-support metadata with PKCE

Verified advertised metadata and callback issuer presence; provider required S256 and accepted exactly one code exchange; callback and server report connected.

  • ✅ PASS Sign-in supports true issuer-support metadata with PKCE — Verified advertised metadata and callback issuer presence; provider required S256 and accepted exactly one code exchange; callback and server report connected.

ℹ️ ASSERTION — 6. Replay preserves usable credentials

Replay rejected without another token exchange; connecting again reused persisted credentials and passed authenticated tool discovery without OAuth.

  • ✅ PASS Replay preserves usable credentials — Replay rejected without another token exchange; connecting again reused persisted credentials and passed authenticated tool discovery without OAuth.

Test run created 2026-09-09T04:20:13.103Z · Source: evals/results/test-runs/2026-09-09T04-20-13-102Z-local-oauth-issuer-support-true-validates-callbacks-and-preserves-usable-credent/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr <n> --test-run 2026-09-09T04-20-13-102Z-local-oauth-issuer-support-true-validates-callbacks-and-preserves-usable-credent

Test evidence — Den OAuth (issuer support true) validates callbacks and preserves usable credentials — ✅ passed

SHA 26fcf20 · engine v1

✅ passed · 5 expectations passed · 0 failed · 0 pending

Rendered locally from the stored run (no screenshots in this HTTP-boundary spec).

verdict passed · 0 user observations · 0 probes · steps 0/0

ℹ️ ASSERTION — 1. Den rejects a mismatched issuer before exchange

Callback returned HTTP 400; provider observed zero token requests.

  • ✅ PASS Den rejects a mismatched issuer before exchange — Callback returned HTTP 400; provider observed zero token requests.

ℹ️ ASSERTION — 2. Den completes sign-in with true issuer-support metadata

Callback returned HTTP 200; provider observed exactly one token requests.

  • ✅ PASS Den completes sign-in with true issuer-support metadata — Callback returned HTTP 200; provider observed exactly one token requests.

ℹ️ ASSERTION — 3. Den replay preserves usable credentials

Replay rejected; a subsequent connection check reused saved credentials and remained connected without another token exchange.

  • ✅ PASS Den replay preserves usable credentials — Replay rejected; a subsequent connection check reused saved credentials and remained connected without another token exchange.

ℹ️ ASSERTION — 4. Den preserves renewed per_member credentials after a late rejection

Two requests used the same refresh grant. The successful rotation completed before the held invalid_grant was released. A subsequent authenticated tools request succeeded, zero deletion events were logged, and one skipped invalidation named different loaded/current revisions.

  • ✅ PASS Den preserves renewed per_member credentials after a late rejection — Two requests used the same refresh grant. The successful rotation completed before the held invalid_grant was released. A subsequent authenticated tools request succeeded, zero deletion events were logged, and one skipped invalidation named different loaded/current revisions.

ℹ️ ASSERTION — 5. Den logs committed per_member SDK credential invalidation

One rejected refresh cleared the connection and produced exactly one structured log with provider error, member scope, and matching loaded/current revisions. Healthy reuse produced no invalidation log; token values and OAuth secrets were absent.

  • ✅ PASS Den logs committed per_member SDK credential invalidation — One rejected refresh cleared the connection and produced exactly one structured log with provider error, member scope, and matching loaded/current revisions. Healthy reuse produced no invalidation log; token values and OAuth secrets were absent.

Test run created 2026-09-09T04:20:14.019Z · Source: evals/results/test-runs/2026-09-09T04-20-14-019Z-den-oauth-issuer-support-true-validates-callbacks-and-preserves-usable-credentia/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr <n> --test-run 2026-09-09T04-20-14-019Z-den-oauth-issuer-support-true-validates-callbacks-and-preserves-usable-credentia

Test evidence — local OAuth (issuer support false) validates callbacks and preserves usable credentials — ✅ passed

SHA 26fcf20 · engine v1

✅ passed · 3 expectations passed · 0 failed · 0 pending

Rendered locally from the stored run (no screenshots in this HTTP-boundary spec).

verdict passed · 0 user observations · 0 probes · steps 0/0

ℹ️ ASSERTION — 1. Reject state callback before token exchange

HTTP 400; zero token requests; connection is not connected.

  • ✅ PASS Reject state callback before token exchange — HTTP 400; zero token requests; connection is not connected.

ℹ️ ASSERTION — 2. Sign-in supports false issuer-support metadata with PKCE

Verified advertised metadata and callback issuer presence; provider required S256 and accepted exactly one code exchange; callback and server report connected.

  • ✅ PASS Sign-in supports false issuer-support metadata with PKCE — Verified advertised metadata and callback issuer presence; provider required S256 and accepted exactly one code exchange; callback and server report connected.

ℹ️ ASSERTION — 3. Replay preserves usable credentials

Replay rejected without another token exchange; connecting again reused persisted credentials and passed authenticated tool discovery without OAuth.

  • ✅ PASS Replay preserves usable credentials — Replay rejected without another token exchange; connecting again reused persisted credentials and passed authenticated tool discovery without OAuth.

Test run created 2026-09-09T04:20:40.621Z · Source: evals/results/test-runs/2026-09-09T04-20-40-621Z-local-oauth-issuer-support-false-validates-callbacks-and-preserves-usable-creden/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr <n> --test-run 2026-09-09T04-20-40-621Z-local-oauth-issuer-support-false-validates-callbacks-and-preserves-usable-creden

Test evidence — Den OAuth (issuer support false) validates callbacks and preserves usable credentials — ✅ passed

SHA 26fcf20 · engine v1

✅ passed · 4 expectations passed · 0 failed · 0 pending

Rendered locally from the stored run (no screenshots in this HTTP-boundary spec).

verdict passed · 0 user observations · 0 probes · steps 0/0

ℹ️ ASSERTION — 1. Den completes sign-in with false issuer-support metadata

Callback returned HTTP 200; provider observed exactly one token requests.

  • ✅ PASS Den completes sign-in with false issuer-support metadata — Callback returned HTTP 200; provider observed exactly one token requests.

ℹ️ ASSERTION — 2. Den replay preserves usable credentials

Replay rejected; a subsequent connection check reused saved credentials and remained connected without another token exchange.

  • ✅ PASS Den replay preserves usable credentials — Replay rejected; a subsequent connection check reused saved credentials and remained connected without another token exchange.

ℹ️ ASSERTION — 3. Den preserves renewed shared credentials after a late rejection

Two requests used the same refresh grant. The successful rotation completed before the held invalid_grant was released. A subsequent authenticated tools request succeeded, zero deletion events were logged, and one skipped invalidation named different loaded/current revisions.

  • ✅ PASS Den preserves renewed shared credentials after a late rejection — Two requests used the same refresh grant. The successful rotation completed before the held invalid_grant was released. A subsequent authenticated tools request succeeded, zero deletion events were logged, and one skipped invalidation named different loaded/current revisions.

ℹ️ ASSERTION — 4. Den logs committed shared SDK credential invalidation

One rejected refresh cleared the connection and produced exactly one structured log with provider error, member scope, and matching loaded/current revisions. Healthy reuse produced no invalidation log; token values and OAuth secrets were absent.

  • ✅ PASS Den logs committed shared SDK credential invalidation — One rejected refresh cleared the connection and produced exactly one structured log with provider error, member scope, and matching loaded/current revisions. Healthy reuse produced no invalidation log; token values and OAuth secrets were absent.

Test run created 2026-09-09T04:20:41.512Z · Source: evals/results/test-runs/2026-09-09T04-20-41-512Z-den-oauth-issuer-support-false-validates-callbacks-and-preserves-usable-credenti/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr <n> --test-run 2026-09-09T04-20-41-512Z-den-oauth-issuer-support-false-validates-callbacks-and-preserves-usable-credenti

Test evidence — local OAuth (issuer support absent) validates callbacks and preserves usable credentials — ✅ passed

SHA 26fcf20 · engine v1

✅ passed · 3 expectations passed · 0 failed · 0 pending

Rendered locally from the stored run (no screenshots in this HTTP-boundary spec).

verdict passed · 0 user observations · 0 probes · steps 0/0

ℹ️ ASSERTION — 1. Reject state callback before token exchange

HTTP 400; zero token requests; connection is not connected.

  • ✅ PASS Reject state callback before token exchange — HTTP 400; zero token requests; connection is not connected.

ℹ️ ASSERTION — 2. Sign-in supports absent issuer-support metadata with PKCE

Verified advertised metadata and callback issuer presence; provider required S256 and accepted exactly one code exchange; callback and server report connected.

  • ✅ PASS Sign-in supports absent issuer-support metadata with PKCE — Verified advertised metadata and callback issuer presence; provider required S256 and accepted exactly one code exchange; callback and server report connected.

ℹ️ ASSERTION — 3. Replay preserves usable credentials

Replay rejected without another token exchange; connecting again reused persisted credentials and passed authenticated tool discovery without OAuth.

  • ✅ PASS Replay preserves usable credentials — Replay rejected without another token exchange; connecting again reused persisted credentials and passed authenticated tool discovery without OAuth.

Test run created 2026-09-09T04:21:07.118Z · Source: evals/results/test-runs/2026-09-09T04-21-07-118Z-local-oauth-issuer-support-absent-validates-callbacks-and-preserves-usable-crede/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr <n> --test-run 2026-09-09T04-21-07-118Z-local-oauth-issuer-support-absent-validates-callbacks-and-preserves-usable-crede

Test evidence — Den OAuth (issuer support absent) validates callbacks and preserves usable credentials — ✅ passed

SHA 26fcf20 · engine v1

✅ passed · 4 expectations passed · 0 failed · 0 pending

Rendered locally from the stored run (no screenshots in this HTTP-boundary spec).

verdict passed · 0 user observations · 0 probes · steps 0/0

ℹ️ ASSERTION — 1. Den completes sign-in with absent issuer-support metadata

Callback returned HTTP 200; provider observed exactly one token requests.

  • ✅ PASS Den completes sign-in with absent issuer-support metadata — Callback returned HTTP 200; provider observed exactly one token requests.

ℹ️ ASSERTION — 2. Den replay preserves usable credentials

Replay rejected; a subsequent connection check reused saved credentials and remained connected without another token exchange.

  • ✅ PASS Den replay preserves usable credentials — Replay rejected; a subsequent connection check reused saved credentials and remained connected without another token exchange.

ℹ️ ASSERTION — 3. Den preserves renewed shared credentials after a late rejection

Two requests used the same refresh grant. The successful rotation completed before the held invalid_grant was released. A subsequent authenticated tools request succeeded, zero deletion events were logged, and one skipped invalidation named different loaded/current revisions.

  • ✅ PASS Den preserves renewed shared credentials after a late rejection — Two requests used the same refresh grant. The successful rotation completed before the held invalid_grant was released. A subsequent authenticated tools request succeeded, zero deletion events were logged, and one skipped invalidation named different loaded/current revisions.

ℹ️ ASSERTION — 4. Den logs committed shared SDK credential invalidation

One rejected refresh cleared the connection and produced exactly one structured log with provider error, member scope, and matching loaded/current revisions. Healthy reuse produced no invalidation log; token values and OAuth secrets were absent.

  • ✅ PASS Den logs committed shared SDK credential invalidation — One rejected refresh cleared the connection and produced exactly one structured log with provider error, member scope, and matching loaded/current revisions. Healthy reuse produced no invalidation log; token values and OAuth secrets were absent.

Test run created 2026-09-09T04:21:08.017Z · Source: evals/results/test-runs/2026-09-09T04-21-08-017Z-den-oauth-issuer-support-absent-validates-callbacks-and-preserves-usable-credent/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr <n> --test-run 2026-09-09T04-21-08-017Z-den-oauth-issuer-support-absent-validates-callbacks-and-preserves-usable-credent

Test evidence — Den member sign-in recovers an isolated connection whose pre-registered client uses the shared callback — ✅ passed

SHA 26fcf20 · engine v1

✅ passed · 3 expectations passed · 0 failed · 0 pending

Rendered locally from the stored run (no screenshots in this HTTP-boundary spec).

verdict passed · 0 user observations · 0 probes · steps 0/0

ℹ️ ASSERTION — 1. Stored callback mode disagrees with the registered redirect

Admin detail reported an isolated-v1 callback mode while the effective callback URL was the shared route.

  • ✅ PASS Stored callback mode disagrees with the registered redirect — Admin detail reported an isolated-v1 callback mode while the effective callback URL was the shared route.

ℹ️ ASSERTION — 2. Member sign-in records the shared callback mode without changing the registration

connect/start sent the registered shared redirect with the same pre-registered client id; the stored mode now reads shared-v1 and nothing is connected yet.

  • ✅ PASS Member sign-in records the shared callback mode without changing the registration — connect/start sent the registered shared redirect with the same pre-registered client id; the stored mode now reads shared-v1 and nothing is connected yet.

ℹ️ ASSERTION — 3. Shared callback completes sign-in and authenticated discovery after recovery

The provider redirected to the shared route; the callback returned HTTP 200 with exactly one token exchange, the member listed tools with the new credential, and replaying the callback was rejected without another exchange.

  • ✅ PASS Shared callback completes sign-in and authenticated discovery after recovery — The provider redirected to the shared route; the callback returned HTTP 200 with exactly one token exchange, the member listed tools with the new credential, and replaying the callback was rejected without another exchange.

Test run created 2026-09-09T04:21:33.967Z · Source: evals/results/test-runs/2026-09-09T04-21-33-967Z-den-member-sign-in-recovers-an-isolated-connection-whose-pre-registered-client-u/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr <n> --test-run 2026-09-09T04-21-33-967Z-den-member-sign-in-recovers-an-isolated-connection-whose-pre-registered-client-u

@yomgui
yomgui merged commit 41679c2 into dev Sep 9, 2026
36 checks passed

This branch was successfully deployed

4 active deployments
Preview – openwork-landing — 26fcf205 Deployed Sep 9, 2026 by vercel[bot]
Preview – openwork-den — 26fcf205 Deployed Sep 9, 2026 by vercel[bot]
Preview – openwork-app — 26fcf205 Deployed Sep 9, 2026 by vercel[bot]
Preview – openwork-diagnostics — 26fcf205 Deployed Sep 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant