Repository navigation
feat(auth): auto-mint browser session from verified Cloudflare Access JWT - #228
Merged
Merged
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Owner
Author
{
"reviewed_base": "6caa9994a0a4d72f057e9b6a9cf25c417dcec124",
"reviewed_head": "6a8e4a89b027624decb7744cf038921d729cceeb",
"reviewer": "Gemini 4 Neon, Antigravity",
"author_session": "t3-thread:6a6b870263499e5c3c4ceec5efb20d31b46884a74e0c45beedb1a4cddb9ac991",
"reviewer_session": "antigravity:c994b558-deac-4de7-93f6-39d0a0eb4d7b",
"fresh_context": true,
"review_kind": "full",
"round_id": "antigravity:c994b558-deac-4de7-93f6-39d0a0eb4d7b",
"prior_findings": [],
"findings": [
{
"id": "F1",
"severity": "important",
"outcome": "open",
"file": "apps/server/src/auth/EnvironmentAuth.ts",
"line": 1808,
"summary": "authenticateWebSocketUpgrade skips assertCloudflareAccessSession on the wsTicket path, allowing wsTickets minted from cf-access: sessions to bypass disabled/config-change revocation, ManagedLimits.allowsRemoteClients, and allowed-origin enforcement."
},
{
"id": "F2",
"severity": "nit",
"outcome": "open",
"file": "apps/server/src/persistence/AuthSessions.ts",
"line": 390,
"summary": "WorkOS parity hardening: AuthSessions.ts setFounderRows does not exclude cf-access:* subjects (allowing another auth:write client to overwrite cryptographically bound founder attribution), and EnvironmentAuth.ts revokePairedClientsThePolicyDisallows (line 2074) does not proactively revoke cf-access: browser sessions at startup when remote clients are disallowed."
}
]
}Independent Security & Correctness Review (
|
…founder immutability
Owner
Author
{
"reviewed_base": "6caa9994a0a4d72f057e9b6a9cf25c417dcec124",
"reviewed_head": "eb132c6b08c38eac8fcc811f43d7542107140bae",
"reviewer": "Gemini 4 Neon, Antigravity",
"author_session": "t3-thread:6a6b870263499e5c3c4ceec5efb20d31b46884a74e0c45beedb1a4cddb9ac991",
"reviewer_session": "antigravity:9da2c2a0-a67a-4507-b936-0adccb8c0770",
"fresh_context": true,
"review_kind": "focused_recheck",
"round_id": "antigravity:c994b558-deac-4de7-93f6-39d0a0eb4d7b",
"prior_findings": ["F1", "F2"],
"findings": [
{
"id": "F1",
"severity": "important",
"outcome": "confirmed",
"rechecked_head": "eb132c6b08c38eac8fcc811f43d7542107140bae",
"file": "apps/server/src/auth/EnvironmentAuth.ts",
"line": 1809,
"summary": "authenticateWebSocketUpgrade now invokes assertCloudflareAccessSession(session, request, true) on the wsTicket path right after assertWorkOsSession; regression test verifies allowed-origin upgrade succeeds and mismatched-origin upgrade fails."
},
{
"id": "F2",
"severity": "nit",
"outcome": "fixed",
"rechecked_head": "eb132c6b08c38eac8fcc811f43d7542107140bae",
"file": "apps/server/src/persistence/AuthSessions.ts",
"line": 392,
"summary": "WorkOS parity hardening applied: setFounderRows excludes CLOUDFLARE_ACCESS_SUBJECT_PREFIX + \"*\" (with regression test confirming setFounder returns false and preserves attributed founder), and revokePairedClientsThePolicyDisallows includes cf-access: browser sessions when remote clients are disallowed."
}
]
}Focused Cross-Family Re-Check (
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Eliminates the
/pairredirect when founders openhttps://t3code.closura.ai(orhttps://t3code-staging.closura.ai) after authenticating through Cloudflare Access (closura.cloudflareaccess.com), by verifying the Cloudflare Access JWT fail-closed and automatically minting a founder-attributed T3 browser session cookie onGET /api/auth/session.Key Changes
apps/server/src/auth/CloudflareAccessConfig.ts):T3CODE_CF_ACCESS_AUTH_ENABLED=trueplus complete, unambiguous configuration:T3CODE_CF_ACCESS_TEAM_DOMAIN(HTTPS origin, e.g.https://closura.cloudflareaccess.com)T3CODE_CF_ACCESS_AUD(comma-separated audience tags so a single host can serve both production and staging Access apps)T3CODE_CF_ACCESS_ALLOWED_ORIGINS(comma-separated HTTPS origins, e.g.https://t3code.closura.ai,https://t3code-staging.closura.ai)T3CODE_CF_ACCESS_KAMERON_EMAIL/T3CODE_CF_ACCESS_JEFF_EMAIL(comma-separated email aliases per founder, normalized lowercase/trimmed, strictly disjoint)apps/server/src/auth/CloudflareAccessAuth.ts):Cf-Access-Jwt-Assertionheader (withCF_Authorizationcookie fallback); never trusts unverified email headers.${teamDomain}/cdn-cgi/access/certsJWKS with 30m cache (cacheMaxAge), 30s rate-limited refresh on unknownkid(cooldownDuration), and 5s fetch timeout (timeoutDuration).iss, exactaud,iat/exp,type === "app"(rejects service tokens),ManagedLimits.allowsRemoteClients, and exact founder email allowlist.GET /api/auth/sessionrequests that omit theOriginheader by validatingHost+X-Forwarded-ProtoagainstT3CODE_CF_ACCESS_ALLOWED_ORIGINS, while rejecting cross-originOriginand cross-siteSec-Fetch-Site.browser-session-cookie(AuthStandardClientScopes,founderattributed,subject: cf-access:<sha256>, TTL capped at earlier of JWTexpand 8h).apps/server/src/auth/http.ts,apps/server/src/auth/EnvironmentAuth.ts,apps/server/src/server.ts):GET /api/auth/sessionauto-mints and sets theHttpOnly; Secure; SameSite=LaxT3 session cookie on unauthenticated requests carrying a valid CF Access JWT, returning{ authenticated: true, ... }immediately (zero/pairredirect).EnvironmentAuth.assertCloudflareAccessSessionrejects existingcf-access:sessions immediately if the feature flag is disabled, config/enrollment changes, remote clients are disallowed, or origin mismatches.Verification
pnpm exec effect-tsgo tsrs -p apps/server/tsconfig.json --noEmit— 0 errorsvp test run src/auth/CloudflareAccessAuth.test.ts src/auth/http.test.ts src/auth/WorkOsAuth.test.ts src/auth/EnvironmentAuth.test.ts— 45/45 passed (covers config validation, RS256/iss/aud/exp/iat/type/alias verification, mobileGETwithoutOrigin, cross-origin/wrong-host/header-spoof rejection, founder attribution, JWKSkidrotation refresh, andManagedPolicyremote-client enforcement).Deploy: fleet