Skip to content

Add Cloudflare Access auth for /internal and harden Sentry config#2

Open
sergical wants to merge 3 commits into
mainfrom
feat/oauth-cowork
Open

Add Cloudflare Access auth for /internal and harden Sentry config#2
sergical wants to merge 3 commits into
mainfrom
feat/oauth-cowork

Conversation

@sergical
Copy link
Copy Markdown
Member

@sergical sergical commented Apr 10, 2026

Summary

  • Adds /internal endpoint protected by Cloudflare Access JWT validation (Sentry Google SSO, @sentry.io only)
  • /internal uses a shared team Plausible API key — no per-user key needed
  • /mcp remains unchanged for direct Bearer token users
  • Hardens Sentry config and adds security headers per SEC-1266 review

What changed

  • src/worker.ts: two-route architecture — /internal (CF Access JWT) and /mcp (Bearer token)
  • src/worker.ts: verifyCloudflareAccessJwt() validates signature via JWKS, audience, expiry, and @sentry.io email
  • src/worker.ts: sendDefaultPii: false + beforeSendSpan scrubber for Authorization/cookie headers
  • src/worker.ts: Sentry.setUser({ email }) on /internal for attribution on shared key
  • src/worker.ts: security headers (X-Frame-Options: DENY, Strict-Transport-Security, Referrer-Policy)
  • src/tools/*: manual Sentry spans with tool-specific attributes on each handler
  • src/server.ts: uses plain McpServer (tools have their own spans, avoids double error capture)

SEC-1266 review

Reviewed sentry-mcp PRs 164, 485, 625, 930 for hardening patterns. Applied security headers from PR 485. OAuth-specific patterns (consent dialog, HMAC state, redirect URI validation) are not applicable — Cloudflare Access handles the auth flow.

Architecture

Worker (Sentry.withSentry)
├── /internal/*  → CF Access JWT validation → shared PLAUSIBLE_API_KEY
└── /mcp/*       → Bearer token → caller's own API key

Deploy checklist

  • Configure Cloudflare Access application for plausible-mcp.sentry.dev/internal/* with Sentry Google SSO IdP
  • Set worker secrets: CF_ACCESS_TEAM_DOMAIN, CF_ACCESS_AUD, PLAUSIBLE_API_KEY
  • Deploy with bun run deploy
  • Verify /mcp Bearer flow still works
  • Test /internal with CF Access auth

Test plan

  • Build passes (TypeScript compilation)
  • All 53 tests pass
  • Deploy and test /internal with Cloudflare Access configured
  • Verify /mcp direct Bearer flow unaffected
  • End-to-end Cowork connector test

🤖 Generated with Claude Code

@sergical sergical marked this pull request as ready for review April 10, 2026 23:32
Comment thread wrangler.toml Outdated
Comment thread src/auth-handler.ts Outdated
Comment thread src/worker.ts Outdated
Comment thread src/worker.ts Outdated
@sergical sergical changed the title Add OAuth 2.1 for Cowork connector support Replace custom OAuth with Cloudflare Access for /internal auth May 25, 2026
sergical and others added 2 commits May 25, 2026 16:29
Adds /internal as an OAuth-protected MCP endpoint for Claude Desktop/Cowork
users, authenticated via Google SSO restricted to @sentry.io emails. Uses
a shared team Plausible API key for OAuth users.

- New src/auth-handler.ts: Google OAuth flow with @sentry.io domain check
- worker.ts: OAuthProvider wraps /internal (OAuth) while /mcp stays as
  direct Bearer token for CLI users (backward compatible)
- wrangler.toml: KV namespace for OAuth state, pinned dev port
- New dependency: @cloudflare/workers-oauth-provider

Deploy requires: GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, PLAUSIBLE_API_KEY
secrets and a KV namespace for OAUTH_KV.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Wrap internalApiHandler and defaultHandler with Sentry.withSentry()
since OAuthProvider export can't be wrapped directly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sergical sergical force-pushed the feat/oauth-cowork branch from 532c54f to 59f8e3f Compare May 25, 2026 20:30
@sergical sergical changed the title Replace custom OAuth with Cloudflare Access for /internal auth Add Cloudflare Access auth for /internal and harden Sentry config May 25, 2026
Comment thread src/worker.ts Outdated
Comment thread src/worker.ts Outdated
@sergical sergical force-pushed the feat/oauth-cowork branch from 59f8e3f to c32fa9e Compare May 25, 2026 20:33
Comment thread src/worker.ts Outdated
@sergical sergical force-pushed the feat/oauth-cowork branch from c32fa9e to da1ebe0 Compare May 25, 2026 20:37
Comment thread src/cf-access.ts Outdated
Comment thread src/worker.ts
@sergical sergical force-pushed the feat/oauth-cowork branch from da1ebe0 to d05ca83 Compare May 25, 2026 20:47
Comment thread src/cf-access.ts Outdated
@sergical sergical force-pushed the feat/oauth-cowork branch from d05ca83 to bf7b33e Compare May 25, 2026 20:55
Comment thread src/cf-access.ts Outdated
Comment thread src/cf-access.ts Outdated
Comment thread .gitignore Outdated
@sergical sergical force-pushed the feat/oauth-cowork branch from bf7b33e to 391f7af Compare May 25, 2026 22:45
Comment thread src/cf-access.ts Outdated
@sergical sergical force-pushed the feat/oauth-cowork branch from 391f7af to 86b69f3 Compare May 26, 2026 02:15
Comment thread src/cf-access.ts
@sergical sergical force-pushed the feat/oauth-cowork branch 2 times, most recently from 8b9b7f9 to b22eb5b Compare May 26, 2026 14:22
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b22eb5b. Configure here.

Comment thread src/cf-access.ts
@sergical sergical force-pushed the feat/oauth-cowork branch from b22eb5b to d53c4d2 Compare May 26, 2026 14:59
Comment thread src/worker.ts
Per security review (SEC-1266), simplify auth by dropping the custom
OAuth provider in favor of Cloudflare Access. /internal validates
Cf-Access-Jwt-Assertion with signature, audience, and @sentry.io check.
/mcp remains unchanged for direct Bearer token users.

- Delete auth-handler.ts (Google SSO flow)
- Remove @cloudflare/workers-oauth-provider, OAUTH_KV, Google creds
- Fix sendDefaultPii: false + beforeSendSpan scrubber for auth headers
- Add security headers (X-Frame-Options, HSTS, Referrer-Policy)
- Add Sentry.setUser for attribution on /internal calls

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sergical sergical force-pushed the feat/oauth-cowork branch from d53c4d2 to 2c5b563 Compare May 26, 2026 16:34
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