Skip to content

feat(web): OAuth consent page for the new OAuth 2.1 provider; fix mcp resource metadata#933

Draft
MaheshtheDev wants to merge 3 commits into
mainfrom
05-11-feat_web_oauth_consent_page_for_the_new_oauth_2.1_provider_fix_mcp_resource_metadata
Draft

feat(web): OAuth consent page for the new OAuth 2.1 provider; fix mcp resource metadata#933
MaheshtheDev wants to merge 3 commits into
mainfrom
05-11-feat_web_oauth_consent_page_for_the_new_oauth_2.1_provider_fix_mcp_resource_metadata

Conversation

@MaheshtheDev
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown
Member Author

MaheshtheDev commented May 12, 2026


How to use the Graphite Merge Queue

Add the label Main to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 12, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
supermemory-mcp 678c7c6 May 13 2026, 10:22 PM

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 12, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
supermemory-app 678c7c6 Commit Preview URL May 13 2026, 10:23 PM

Copy link
Copy Markdown
Contributor

@vorflux vorflux Bot left a comment

Choose a reason for hiding this comment

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

Reviewed the OAuth consent page and MCP resource metadata changes. The consent page is well-built with good error handling (HMAC expiry, signature validation). Key concerns: (1) org-switching interaction with HMAC-signed params, (2) deployment must be coordinated with mono PR #1552, (3) x-forwarded-host spoofing in dev mode.

// so it must be byte-for-byte what we were redirected with (not re-serialized).
const oauthQuery = window.location.search.replace(/^\?/, "")
if (!oauthQuery) {
setError(
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.

changeOrg calls authClient.organization.setActive but doesn't refresh the consent page's query params. After switching orgs, the HMAC-signed query string still references the original session state. Will the consent POST succeed with the new active org, or will the server reject it because the session changed mid-flow?

redirectURI?: string
redirect_uri?: string
redirect?: boolean
message?: string
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.

Sending the raw query string to preserve the HMAC signature is the right call. But if the browser ever normalizes or re-encodes query params (e.g. special characters, unicode), the HMAC will fail. The invalid_signature handling below (line 99) covers this — good.

Comment thread apps/mcp/src/index.ts

// This worker's public origin. Prefer the explicit MCP_URL binding (proxy hops can drop the
// Host header); fall back to the request host, then the prod custom domain.
const mcpBaseUrl = (c: Context<{ Bindings: Bindings }>): string => {
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.

mcpBaseUrl falls back to x-forwarded-host / host headers when MCP_URL is not set. Since this value ends up in the resource field of the OAuth protected resource metadata (line 74), a spoofed x-forwarded-host could cause MCP clients to send tokens to the wrong resource. The MCP_URL env var mitigates this in production, but in dev mode without it set, this is exploitable. Consider only using host (not x-forwarded-host) as the fallback, since CF Workers set host reliably.

p.delete("redirect")
p.delete("error")
return `${backend}/api/auth/mcp/authorize?${p.toString()}`
return `${backend}/api/auth/oauth2/authorize?${p.toString()}`
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.

Endpoint changed from /api/auth/mcp/authorize to /api/auth/oauth2/authorize. This must be deployed simultaneously with mono PR #1552 — if this PR lands first, the login page will redirect to a non-existent endpoint. If #1552 lands first, the old endpoint is removed and existing login pages break. Coordinate the deployment.

Comment thread apps/mcp/wrangler.jsonc
"vars": {
"API_URL": "https://api.supermemory.ai"
"API_URL": "https://api.supermemory.ai",
"MCP_URL": "https://mcp.supermemory.ai"
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.

The MCP_URL var is set to https://mcp.supermemory.ai here but the resource field in the mono API's /.well-known/oauth-protected-resource (PR #1552, well-known.ts) uses BETTER_AUTH_URL (i.e. https://api.supermemory.ai). These are intentionally different resources, but make sure the oauthValidAudiences in mono PR #1552 includes the MCP origin — it does via mcpServerUrl(env), so this should be fine.

Show the requesting plugin's icon + 'Connect <Name>' on the OAuth consent
page so users see exactly which first-party plugin (Claude Code, OpenCode,
OpenClaw, OpenAI Codex) is asking for access. Falls back to a generic
'An application wants to connect' for unknown/DCR-registered clients.

KNOWN_OAUTH_CLIENTS mirrors mono/packages/lib/plugins.ts; the two repos
don't share a package, so kept in sync manually (follow-up: shared lib).

Also add a 'codex' entry to PLUGIN_INFO in app/auth/connect/page.tsx for
the legacy sm_ key flow path (Codex CLI plugin).
@socket-security
Copy link
Copy Markdown

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
Obfuscated code: npm entities is 91.0% likely obfuscated

Confidence: 0.91

Location: Package overview

From: ?npm/entities@6.0.1

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/entities@6.0.1. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

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