Skip to content

docs(auth): explain why MCP OAuth secrets/tokens aren't app-encrypted#2968

Closed
tofikwest wants to merge 2 commits into
mainfrom
fix/mcp-oauth-secret-encryption
Closed

docs(auth): explain why MCP OAuth secrets/tokens aren't app-encrypted#2968
tofikwest wants to merge 2 commits into
mainfrom
fix/mcp-oauth-secret-encryption

Conversation

@tofikwest
Copy link
Copy Markdown
Contributor

@tofikwest tofikwest commented May 29, 2026

TL;DR

My first attempt (storeClientSecret: 'encrypted') would have broken the Gram OAuth flow — caught in review. This PR replaces it with a warning comment only (zero behavior change). The honest finding: cubic's P1 has no safe app-level fix for our setup.

Why storeClientSecret breaks things

Verified in the locked better-auth 1.4.22 source:

  • getClient() returns a config trustedClient directly, with clientSecret = the plaintext GRAM_OAUTH_CLIENT_SECRET.
  • The token endpoint calls verifyStoredClientSecret() for every confidential client — no trusted-client bypass.
  • Under 'encrypted', that does symmetricDecrypt(plaintext_config_secret) === presented → fails/throws → invalid_client. 'hashed' fails identically.

Why there's nothing to encrypt anyway

  • The Gram client is a config-only trustedClient (secret in env, never in the DB).
  • DCR is disabledoauth_application has no rows. No client secrets are persisted.

The access/refresh tokens (what cubic pointed at)

oauth_access_token.accessToken/refreshToken are generated and looked up by raw value by better-auth, so they can't be hashed/encrypted at our layer without breaking token validation. They rely on DB encryption-at-rest + short access-token TTLs.

What this PR does

Leaves a comment in auth.server.ts documenting all of the above, so nobody (human or bot) re-introduces the breaking storeClientSecret change. No code behavior changes.

Alternative: if a doc-only PR isn't wanted, close this — the knowledge is captured here and in the investigation.

🤖 Generated with Claude Code

@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

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

Project Deployment Actions Updated (UTC)
comp-framework-editor Ready Ready Preview, Comment May 29, 2026 5:33pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
app Skipped Skipped May 29, 2026 5:33pm
portal Skipped Skipped May 29, 2026 5:33pm

Request Review

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

Replaces the breaking attempt to set `storeClientSecret: 'encrypted'` (cubic P1
on PR #2956) with a warning comment. That option would have broken the Gram
OAuth flow: better-auth verifies every confidential client through the same
decrypt/hash path, including config `trustedClients` whose secret is the
plaintext GRAM_OAUTH_CLIENT_SECRET, so verification would fail (`invalid_client`).

There is also nothing to encrypt: the Gram client is config-only and DCR is
disabled, so no client secrets are persisted to `oauth_application`. The
`accessToken`/`refreshToken` in `oauth_access_token` are generated and looked up
by raw value by better-auth, so they can't be hashed/encrypted at our layer
without breaking token validation; they rely on DB encryption-at-rest + short
TTLs. Net: no safe app-level fix exists; documented to prevent re-introduction.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tofikwest tofikwest force-pushed the fix/mcp-oauth-secret-encryption branch from 26054f3 to 55821f9 Compare May 29, 2026 17:29
@tofikwest tofikwest changed the title fix(auth): encrypt OAuth client secrets at rest for hosted MCP docs(auth): explain why MCP OAuth secrets/tokens aren't app-encrypted May 29, 2026
@vercel vercel Bot temporarily deployed to Preview – app May 29, 2026 17:29 Inactive
@vercel vercel Bot temporarily deployed to Preview – portal May 29, 2026 17:29 Inactive
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