Skip to content

Judge OAuth consent by every registered redirect URI and cap redirect lookups #810

Done

Description

@HMarzban

Summary

/oauth/consent currently judges a connected app's trust from the single active redirect_uri on the authorize request (appTrust(details.redirect_uri)), ignoring any other redirect_uris registered on the same OAuth client. Because Supabase Auth allows open Dynamic Client Registration (DCR) and auto-approves subsequent authorize requests for an existing (user, client_id, scopes) grant, an attacker can register one client with both a verified callback (for example https://claude.ai/api/mcp/auth_callback) and an attacker callback (https://evil.example/cb), earn a verified brand badge on the first authorize request, and silently receive an authorization code on the second request.

In the same module, GET /api/connected-apps/redirects fans out unbounded Promise.all calls to supabase.auth.admin.oauth.getClient (which can saturate Bun's 256-fetch cap for users with many DCR grants) and sends serviceRoleKey instead of anonKey on the user-token grants read.

Parent: #230. Execution type: HITL (one small UX confirmation on Cursor loopback consent below), then AFK.

Where

  • apps/webapp/src/pages/oauth/consent.tsx (getAuthorizationDetails, isRedirect, appTrust)
  • apps/webapp/src/utils/appTrust.ts (appTrust, clientTrust)
  • apps/hocuspocus.server/src/modules/mcp/http/connectedApps.ts
  • apps/hocuspocus.server/src/modules/mcp/infra/grantRedirects.ts
  • apps/hocuspocus.server/src/index.ts (wiring grantRedirects key)
  • apps/webapp/CLAUDE.md:444 (Cursor loopback consent note)

What to build

  1. Pre-consent client redirect lookup endpoint (connectedApps.ts):
    • Add GET /api/connected-apps/clients/:clientId/redirects behind requireUser (rejecting anonymous users and connected-app tokens).
    • Validate clientId with z.string().uuid() (houseEnvelopeHook).
    • Protect with a dedicated tight per-user rate limit (e.g. 30 / min keyed on userId) so it cannot amplify calls to the Supabase Admin API.
    • Call supabase.auth.admin.oauth.getClient(clientId) and return only { redirects: string[] }. Return { redirects: [] } on 404 or lookup error so the route is not a loud client-existence oracle.
    • Do not re-call /auth/v1/oauth/authorizations/:id from the backend (Supabase answers 400 on a second call).
  2. Await and enforce clientTrust on /oauth/consent (consent.tsx):
    • On the details branch, await the GET /api/connected-apps/clients/:clientId/redirects fetch (8 s timeout, matching useConnectedApps.ts) before setting the details view state so a verified brand logo never flashes before downgrading.
    • Combine details.redirect_uri with the returned redirects and judge with clientTrust(allUris).
    • Fail closed without broken copy: If the lookup fails, times out, or returns empty, demote to { kind: 'unknown', origin: originOf(details.redirect_uri) } — never pass [] into clientTrust directly (which yields empty origin: '' and breaks "It returns you to .").
    • When the client registers additional origins beyond details.redirect_uri, show the active destination origin and explicitly list the extra registered origin(s) (for example, "This app can also send your sign-in to https://…").
  3. Defense-in-depth on auto-approval (isRedirect(data)):
    • @supabase/auth-js OAuthRedirect returns only { redirect_url } (no client_id).
    • Run appTrust(data.redirect_url) before calling window.location.assign: keep known and local silent so existing Claude, ChatGPT, Cursor, and CLI re-auth stays frictionless; for unknown, show a 1-click confirmation card naming the destination origin (Continue / Cancel) instead of blindly redirecting (protects pre-fix grants).
  4. Harden grantRedirects.ts:
    • Deduplicate clientIds and bound supabase.auth.admin.oauth.getClient concurrency (for example, concurrency 8 with a reasonable cap) instead of unbounded Promise.all.
    • Pass anonKey (not serviceRoleKey) as the apikey header on the user-token /auth/v1/user/oauth/grants call.
  5. HITL confirmation — Cursor loopback consent copy:
    • Production Cursor DCR clients register both https://www.cursor.com/agents/mcp/oauth/callback and http://localhost:8787/callback (apps/webapp/CLAUDE.md:444, appTrust.ts:23-28).
    • Strict clientTrust(allUris) will downgrade Cursor on /oauth/consent from verified "Cursor" to "On this computer". This is security-correct (exempting localhost would let an attacker pair claude.ai + http://localhost:...). Confirm this UX trade-off and update apps/webapp/CLAUDE.md:444 and appTrust.ts:24-25 to match.

Acceptance criteria

  • GET /api/connected-apps/clients/:clientId/redirects requires a non-anonymous user session, refuses connected-app tokens, validates UUIDs, enforces a per-user rate limit, and returns only { redirects: string[] } ([] on 404/error).
  • A client registered with both a known callback (claude.ai) and an untrusted callback (evil.example) renders as unverified on /oauth/consent, never flashes the verified badge, and lists the additional registered origin.
  • When the redirect lookup fails or times out, /oauth/consent fails closed to unverified while keeping a non-empty origin from details.redirect_uri.
  • On isRedirect(data) auto-approval, known and local redirect silently while unknown requires a 1-click confirmation naming the destination origin.
  • grantRedirects.ts deduplicates client IDs, caps outbound getClient concurrency, and uses anonKey on the user-token grants fetch.
  • Maintainer confirms the Cursor loopback consent ruling and apps/webapp/CLAUDE.md:444 / appTrust.ts are updated.
  • Unit tests pin multi-URI downgrade, lookup-failure fallback, isRedirect unknown-origin gating, and grantRedirects concurrency/dedup.

Verify

  • cd apps/hocuspocus.server && bun run typecheck && bun test
  • cd apps/webapp && bun run typecheck && bun test
  • Manual check on local stack: simulate a client with ["https://claude.ai/api/mcp/auth_callback", "https://evil.example/cb"] and confirm /oauth/consent renders unverified and lists https://evil.example.

Blocked by

None — can start immediately (confirm the Cursor consent ruling before merging).

Activity

  1. added this to the v2.3.8 milestone on Nov 23, 2026
  2. added
    bug
    Security
    on Nov 23, 2026
  3. HMarzban commented on Nov 24, 2026

    @HMarzban
    CollaboratorAuthor

    Implemented and verified on main (b4ca4c9e3, 2a82a9b9f):

    • Backend: added GET /api/connected-apps/clients/:clientId/redirects (per-user rate-limited), plus grant-redirect dedup, concurrency cap, and anonKey handling.
    • Webapp (/oauth/consent): classified OAuth clients across all registered redirect URIs via clientTrust(allUris), added fail-closed fallback on redirect lookup failure and unknown-origin redirect confirmation.
    • Maintainer ruling recorded: confirmed downgrading Cursor loopback DCR clients on /oauth/consent to "On this computer" (local) and synced appTrust.ts and apps/webapp/CLAUDE.md.
    • Verified with backend unit/integration suites (1,400 pass), webapp Jest (655 pass), typecheck, eslint, prettier, and check:agent-docs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    AuthCriticalSecuritybug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions