fix(oauth): pin broker redirect_uri and seal state/code on runtime OAuth MCPs

0X
12h ago
+842-270

Summary

MCPs on @decocms/runtime < 3.0.0 expose an OAuth broker (/authorize, /oauth/callback, /token) that does not validate the downstream redirect_uri and keeps state and code unsigned. Runtime 3.x validates the redirect on /authorize and the callback and seals state/code (AES-GCM), but only when the MCP configures allowedRedirectHosts and stateSecret. This is the broker's own redirect, a different layer from the IdP redirect pinning in #539/#540.

Changes

  • Bump the 21 broker MCPs to @decocms/runtime@^3.1.0 (zod pinned to 4.3.6 to match).
  • Add @decocms/mcps-shared/oauth-broker: allowedRedirectHosts (decocms.com plus EXTRA_ALLOWED_REDIRECT_HOSTS) and a required OAUTH_STATE_SECRET (≥ 32 chars). createGoogleOAuth includes it, so all Google MCPs get it in one place; airtable, dropbox, github-repo-reports, microsoft-teams, shopify and whatsapp spread it into their oauth config.
  • dropbox builds its runtime on first request so the secret is read after Workers populate env.
  • google-big-query tests pass the per-request auth context runtime 3 private tools require.
  • SECRETS.md and dropbox/teams READMEs document the new secret.

Deploy order

Set OAUTH_STATE_SECRET on every affected MCP before merging (Workers: wrangler secret put; kubernetes-bun: site state secret). Without it, Workers MCPs answer 500 and kubernetes-bun MCPs fail to start. Clients that call these MCPs directly with non-decocms or custom-scheme callbacks need their host in EXTRA_ALLOWED_REDIRECT_HOSTS; loopback http still works.

Not included

openrouter stays on 1.2.8: runtime 3 removed createStreamableTool/streamToResponse, which its LLM binding uses. Separate port to follow.

Tests

Broker regression tests for dropbox, google-gmail and microsoft-teams (5/5 each); shared 33/33; google-big-query 14/14; shopify 58/58; github-repo-reports 43/43; google-firestore 14/14. Typecheck clean in our code (remaining errors are inside the runtime's shipped source, same as before).


Summary by cubic

Hardens the OAuth broker that @decocms/runtime mounts on OAuth MCPs: it previously accepted any redirect_uri, carried state in unsigned base64, and handed the client a code that exposed the upstream token. Now the broker pins the downstream callback to decocms.com (plus EXTRA_ALLOWED_REDIRECT_HOSTS) and AES-GCM seals state and code.

Migration

  • Set OAUTH_STATE_SECRET (≥ 32 chars) on every affected MCP before merging; generate with openssl rand -hex 32.
  • Workers MCPs without it answer 500; kubernetes-bun MCPs fail to start.
  • Clients calling these MCPs directly with non-decocms callbacks need their host added to EXTRA_ALLOWED_REDIRECT_HOSTS; loopback HTTP still works.

Refactors

  • Bumps the 21 broker MCPs to @decocms/runtime@^3.1.0 and pins zod to 4.3.6, including google-analytics-sa whose withRuntime tools type no longer matched on the old runtime.
  • Adds @decocms/mcps-shared/oauth-broker, included by createGoogleOAuth so all Google MCPs get it in one place; airtable, dropbox, github-repo-reports, microsoft-teams, shopify, and whatsapp spread it manually.
  • Dropbox builds its runtime lazily so the secret is read after Workers populate env.
  • openrouter stays on 1.2.8 because runtime 3 removed the stream helpers its LLM binding uses; port tracked separately.