Repository navigation
Description
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.tsapps/hocuspocus.server/src/modules/mcp/infra/grantRedirects.tsapps/hocuspocus.server/src/index.ts(wiringgrantRedirectskey)apps/webapp/CLAUDE.md:444(Cursor loopback consent note)
What to build
- Pre-consent client redirect lookup endpoint (
connectedApps.ts):- Add
GET /api/connected-apps/clients/:clientId/redirectsbehindrequireUser(rejecting anonymous users and connected-app tokens). - Validate
clientIdwithz.string().uuid()(houseEnvelopeHook). - Protect with a dedicated tight per-user rate limit (e.g.
30 / minkeyed onuserId) 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/:idfrom the backend (Supabase answers400on a second call).
- Add
- Await and enforce
clientTruston/oauth/consent(consent.tsx):- On the
detailsbranch, await theGET /api/connected-apps/clients/:clientId/redirectsfetch (8 s timeout, matchinguseConnectedApps.ts) before setting thedetailsview state so a verified brand logo never flashes before downgrading. - Combine
details.redirect_uriwith the returnedredirectsand judge withclientTrust(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[]intoclientTrustdirectly (which yields emptyorigin: ''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://…").
- On the
- Defense-in-depth on auto-approval (
isRedirect(data)):@supabase/auth-jsOAuthRedirectreturns only{ redirect_url }(noclient_id).- Run
appTrust(data.redirect_url)before callingwindow.location.assign: keepknownandlocalsilent so existing Claude, ChatGPT, Cursor, and CLI re-auth stays frictionless; forunknown, show a 1-click confirmation card naming the destination origin (Continue/Cancel) instead of blindly redirecting (protects pre-fix grants).
- Harden
grantRedirects.ts:- Deduplicate
clientIdsand boundsupabase.auth.admin.oauth.getClientconcurrency (for example, concurrency 8 with a reasonable cap) instead of unboundedPromise.all. - Pass
anonKey(notserviceRoleKey) as theapikeyheader on the user-token/auth/v1/user/oauth/grantscall.
- Deduplicate
- HITL confirmation — Cursor loopback consent copy:
- Production Cursor DCR clients register both
https://www.cursor.com/agents/mcp/oauth/callbackandhttp://localhost:8787/callback(apps/webapp/CLAUDE.md:444,appTrust.ts:23-28). - Strict
clientTrust(allUris)will downgrade Cursor on/oauth/consentfrom verified"Cursor"to"On this computer". This is security-correct (exemptinglocalhostwould let an attacker pairclaude.ai+http://localhost:...). Confirm this UX trade-off and updateapps/webapp/CLAUDE.md:444andappTrust.ts:24-25to match.
- Production Cursor DCR clients register both
Acceptance criteria
-
GET /api/connected-apps/clients/:clientId/redirectsrequires 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/consentfails closed to unverified while keeping a non-emptyoriginfromdetails.redirect_uri. - On
isRedirect(data)auto-approval,knownandlocalredirect silently whileunknownrequires a 1-click confirmation naming the destination origin. -
grantRedirects.tsdeduplicates client IDs, caps outboundgetClientconcurrency, and usesanonKeyon the user-token grants fetch. - Maintainer confirms the Cursor loopback consent ruling and
apps/webapp/CLAUDE.md:444/appTrust.tsare updated. - Unit tests pin multi-URI downgrade, lookup-failure fallback,
isRedirectunknown-origin gating, andgrantRedirectsconcurrency/dedup.
Verify
cd apps/hocuspocus.server && bun run typecheck && bun testcd 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/consentrenders unverified and listshttps://evil.example.
Blocked by
None — can start immediately (confirm the Cursor consent ruling before merging).
Activity
HMarzban commentedon Nov 24, 2026
Implemented and verified on
main(b4ca4c9e3,2a82a9b9f):GET /api/connected-apps/clients/:clientId/redirects(per-user rate-limited), plus grant-redirect dedup, concurrency cap, andanonKeyhandling./oauth/consent): classified OAuth clients across all registered redirect URIs viaclientTrust(allUris), added fail-closed fallback on redirect lookup failure and unknown-origin redirect confirmation./oauth/consentto"On this computer"(local) and syncedappTrust.tsandapps/webapp/CLAUDE.md.1,400pass), webapp Jest (655pass), typecheck, eslint, prettier, andcheck:agent-docs.