Skip to content

feat(server): Cloudflare Access identity pairing (fork trial) - #1

Merged
spk-alex merged 2 commits into
mainfrom
cursor/cloudflare-access-identity-pairing-fcdf
Nov 7, 2026
Merged

spk-alex merged 2 commits into
mainfrom
cursor/cloudflare-access-identity-pairing-fcdf

Conversation

@spk-alex

@spk-alex spk-alex commented Nov 7, 2026 •

Copy link
Copy Markdown

Problem

When T3 Code sits behind Cloudflare Access, every new browser still needs a one-time pairing code even after the user has already proven who they are through Access. Operators also had no way to revoke someone’s Access-bound identity separately from a single browser session.

Change

  • Settings (off by default): Connections → Access adds a toggle plus team domain and application AUD. Only operators with access write can change them.
  • Server: Verifies Cf-Access-Jwt-Assertion against Cloudflare JWKS (human identities only; service tokens rejected). After first successful pair, the verified Access subject is stored and later browsers with the same identity can auto-resume with standard client scopes. Migrations add identity storage and a session column for the bound key.
  • Revoke UX: If a listed client was paired through Access, revoke opens a dialog: This browser only (stock revoke) or All browsers for this person (revokes every session sharing that identity and deletes the stored identity so pairing is required again).
  • Contract: revokeCloudflareAccessIdentity on revoke RPC; cloudflareAccessIdentityPaired on client session records for the UI.
  • Layer: CloudflareAccessIdentityPairing.layer now provideMerges SessionStore.layer so the live host matches unit-test wiring and avoids Service not found: t3/auth/SessionStore after migrations.

Scope and approval

Fork-only trial on smartphonekey/t3code — no upstream pingdotgg/t3code issue or PR. Toggle defaults off; no listen-address or secrets changes.

Verification

  • vp test run on CloudflareAccessIdentityPairing.test.ts, CloudflareAccessJwt.test.ts, and EnvironmentAuth.test.ts (CF stubbed in auth suite; full stack covered in pairing tests).
  • Manual UX: AlertDialog wired in ConnectionsSettings.tsx; CloudflareAccessIdentitySettings.tsx under Access when the operator can write access settings.

Composer (cloud agent)

Open in Web Open in Cursor 

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…gs toggle

Verify Cf-Access-Jwt-Assertion via JWKS, remember human identities after first
pair, and resume trusted browsers without a new pairing code. Operators can
revoke a single session or drop the stored Access identity from Connections.
Default off; no service-token shortcut.

Co-authored-by: spk-alex <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T04:18:18.860959Z d268343 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d268343ab4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +160 to +164
const session = yield* sessions.issue({
method: "browser-session-cookie",
subject: "cloudflare-access-identity",
scopes: AuthStandardClientScopes,
cloudflareAccessIdentityKey: identity.value.identityKey,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve the paired grant's scopes when resuming an identity

When a user pairs with a restricted-scope credential, EnvironmentAuth.createBrowserSession correctly issues only grant.scopes, but the browser-session handler records that identity regardless of its scopes. Opening a fresh browser then reaches this code and receives AuthStandardClientScopes, including terminal, filesystem-write, and access-management permissions. The identity record stores no grant scopes, so resuming silently escalates a restricted pairing into full control of the environment. Persist the authorized scopes with the identity and use those when issuing resumed sessions.

Useful? React with 👍 / 👎.

Comment on lines +14 to +16
const settings = useScopedSettings();
const updateSettings = useUpdateScopedSettings();
const session = useEnvironmentSessionState(environmentId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Target Cloudflare settings at the selected access environment

With multiple connected environments, the Access page's “Showing access for” picker changes environmentId, but these hooks read and mutate the unrelated outer SettingsScopeProvider. With the default empty settings search, that scope is all, and planScopedSettingsPatch writes to every connected environment; a retained machine scope can instead target a different machine. Consequently, changing the selected server's Access toggle, team domain, or AUD can overwrite other servers' authentication configuration while displaying another server's values. Read settings and execute updates explicitly against the supplied environmentId.

AGENTS.md reference: AGENTS.md:L75-L75

Useful? React with 👍 / 👎.

Comment on lines +86 to +87
const http = yield* HttpClient.HttpClient;
let keySet: { readonly keys: Jwks.KeySet; readonly expiresAt: number } | undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retain the JWKS cache across verification calls

For production verification, keySet is initialized inside each invocation of verifyCloudflareAccessJwt, so every call starts with an empty cache and fetches Cloudflare's certificates again. The ten-minute TTL and stale-key fallback therefore never work across requests. Every pairing or identity resume incurs an external network request, and even a brief certificate-endpoint outage prevents previously verified identities from reconnecting. Keep the cache in a longer-lived service or closure, keyed by the configured JWKS endpoint.

Useful? React with 👍 / 👎.

@spk-alex
spk-alex merged commit 8d99e2d into main Nov 7, 2026
4 checks passed
spk-alex added a commit that referenced this pull request Nov 23, 2026
Squashed from the fork's history before rebasing onto upstream:

- 11d10fd feat: default signed-in users to their own chats
- c6d9960 feat: prefer personal subscriptions and share until weekly reset
- 8d99e2d feat(server): Cloudflare Access identity pairing (fork trial) (#1)
- aca7d4b fix: integrate current main and repair auth check failures
- 26328e0 test: include current migrations in preview upgrade expectations
- 70489b6 fix(server): preserve account ownership through queued and background work
- f8851d8 feat(server): Cloudflare Access identity pairing skip after first pair
- 10098bd fix(server): unify Cloudflare identity pairing and preserve granted access
- 5d4bdd9 test(server): retain forged Cloudflare email header coverage
- da6ac9e fix(server): accept human Cloudflare application tokens
- 86bbfb6 fix(auth): use Cloudflare Access identity for My chats

Folded in afterwards: subscription owner checks read settings only when they must (88c0082), the notes on two upstream tests changed for fork access checks (5522d41), and gt()/<T> wrapping of this feature's UI copy (from db8f6fb).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JLQGRKNn8mKpTc44SCwRT2
spk-alex added a commit that referenced this pull request Nov 23, 2026
Squashed from the fork's history before rebasing onto upstream:

- 11d10fd feat: default signed-in users to their own chats
- c6d9960 feat: prefer personal subscriptions and share until weekly reset
- 8d99e2d feat(server): Cloudflare Access identity pairing (fork trial) (#1)
- aca7d4b fix: integrate current main and repair auth check failures
- 26328e0 test: include current migrations in preview upgrade expectations
- 70489b6 fix(server): preserve account ownership through queued and background work
- f8851d8 feat(server): Cloudflare Access identity pairing skip after first pair
- 10098bd fix(server): unify Cloudflare identity pairing and preserve granted access
- 5d4bdd9 test(server): retain forged Cloudflare email header coverage
- da6ac9e fix(server): accept human Cloudflare application tokens
- 86bbfb6 fix(auth): use Cloudflare Access identity for My chats

Folded in afterwards: subscription owner checks read settings only when they must (88c0082), the notes on two upstream tests changed for fork access checks (5522d41), and gt()/<T> wrapping of this feature's UI copy (from db8f6fb).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JLQGRKNn8mKpTc44SCwRT2
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.

2 participants