[CYJ-10] agent implementation #9
<!-- review-packet -->
Review packet (stage 6 → swarm)
Machine-readable; humans can ignore.
{
"schema": "review-packet/v1",
"pr_number": 9,
"ticket_key": "CYJ-10",
"branch": "agent/CYJ-10",
"base": "main",
"proposal_comment_id": null,
"repos_touched": [
{
"repo": "chenyujielong",
"tier": 3
}
],
"modules_changed": [
"src/auth",
"src/lib/auth",
"src/screens",
"supabase/functions/auth"
],
"acceptance_criteria": [
"Clicking \"Sign in with Google\" at https://chenyujielong.vercel.app/?flags=flag-cyj-7 initiates the auth-start request via fetch (not window.location or anchor navigation), and the browser navigates to Google's consent screen \u2014 no file is downloaded",
"The auth-start request carries the Supabase anon key (apikey header) and receives a redirect-to-Google response, not a 4xx error",
"After Google consent, the user is redirected back, a session is issued, and the signed-in state is reflected in the UI",
"Tests assert the click handler calls the start endpoint programmatically and follows its redirect (behavior assertion, not shape)",
"npm test -- --run and npm run lint pass on the change"
],
"risk_tier": 3,
"ci": {
"tests": "pass",
"lint": "pass",
"secrets": "pass",
"diff_lines": 292
},
"confidence_inputs": {
"diff_lines": 292,
"modules_touched": 4,
"tier1": false,
"has_migration": false,
"behind_flag": false
}
}
[comment] The button stays enabled while startGoogleSignIn() is awaiting fetch/res.json(), so a double-click issues two /auth/google/start requests and two Set-Cookie state values (last write wins — the flow still completes, so this is benign). Consider a pending state or disabling .landing-google during the request.
Review — functional (clean-room, k3-256k)
---REVIEW-START---
persona: functional
verdict: approve
criticals: 0
comments: 1
---REVIEW-END---
Review — security (clean-room, k3-256k)
---REVIEW-START---
persona: security
verdict: comment
criticals: 0
comments: 1
---REVIEW-END---
[comment] The https:-only check blocks javascript:/data:/http: (good, and tested), but still accepts any https: host — e.g. https://evil.example would pass. The URL comes from our own Edge Function over TLS so this is low-risk today, but since this value drives a top-level navigation, consider pinning the host to the expected Google authorize origin (accounts.google.com) as defense-in-depth against a future change or misconfiguration of the auth function. Note the test at authStart.test.ts:63-68 only rejects http://evil.example, so this gap is currently invisible to the suite.
[comment] Rule 8/11 (read before you write; two patterns worse than one): this new isHttpsUrl duplicates the URL-protocol check already implemented one file away as httpsUrlOrNull in src/auth/sessionClient.ts:50 — the doc comment above even cites it as the established discipline. Extract a shared helper (e.g. an httpsUrl guard exported from one module and reused by both) instead of maintaining two near-identical implementations that can drift.
[comment] Behavior change vs. the removed code: the old buildAuthStartUrl deliberately omitted the credential when SUPABASE_ANON_KEY was unconfigured ('omitted entirely when not configured rather than left as a dangling apikey='); startGoogleSignIn now always sends apikey: SUPABASE_ANON_KEY, i.e. an empty header when the key is missing at build time, and the Landing.tsx call site guards only FUNCTIONS_URL. It does fail visibly (gateway 401 → error alert), so this is non-blocking, but consider guarding on the key being present to match the 'auth configured? guard lives in one home' pattern documented in sessionClient.ts.
Review — standards (clean-room, k3-256k)
---REVIEW-START---
persona: standards
verdict: comment
criticals: 0
comments: 2
---REVIEW-END---
Consensus passed (stage 8): CI green + zero criticals + security pass. QA evidence bundle next.
<!-- qa-evidence -->
QA evidence bundle (stage 8b)
AC verification index
Ticket: CYJ-10
Env: https://chenyujielong-ehh2u33ay-z8-2185.vercel.app?flags=flag-CYJ-10
Date: 2026-11-22
Full bundle: workflow artifacts of this run (evidence-pr9.tar.gz — upload via actions/upload-artifact in the workflow).
Approved these changes.
funcoin68
funcoin68bot
What & why
Fixes CYJ-10: clicking "Sign in with Google" (flag
flag-cyj-7) downloaded an empty file namedstartinstead of opening Google's consent screen.Root cause — verified against the live project before writing code (proposal step 0):
/auth/google/startwith the anon key as anapikeyquery param (CYJ-9 workaround). Verified:curl "…/functions/v1/auth/google/start?apikey=$KEY"→ 401UNAUTHORIZED_NO_AUTH_HEADER("Missing authorization header") from the Supabase gateway. A navigation that receives a non-navigable JSON 401 body is saved by the browser as a file namedstart— exactly the reported bug.curl -H "apikey: $KEY" "…/functions/v1/auth/google/start"→ 302Location: https://accounts.google.com/o/oauth2/v2/auth?…. The header is the accepted credential path, and a navigation cannot set headers — hence the AC's fetch requirement.The change (per the approved proposal):
src/auth/authStart.ts—buildAuthStartUrlno longer smugglesapikeyinto the query (one credential path); newstartGoogleSignIn()fetches the start endpoint with theapikeyheader +credentials: 'include', throws loudly on non-OK / missing / non-httpsredirect(rule 12; same https-only discipline ashttpsUrlOrNull), and returns the Google authorize URL. NewnavigateTo()seam wrapswindow.location.assign(jsdom'slocation.assignis non-configurable, so tests intercept the seam — flagged deviation from the proposal's literal "window.location.assign spy"; the behavior asserted is identical: where the browser navigates).src/screens/Landing.tsx—onSignInis async: flag on → fetch the start endpoint, navigate to the returned Google URL; on throw → warn + show the existingrole="alert"error UI, no silent mock-lobby fallback. Flag-off path unchanged.supabase/functions/auth/index.ts—handleStartreturns200 { redirect: "<google authorize url>" }(a cross-origin fetch cannot consume a 302:followfails CORS at accounts.google.com,manualyields an unreadable Location) with the state cookie + CORS headers unchanged; OPTIONS preflight now allows theapikeyheader andGET, OPTIONS.src/lib/auth/session.ts—serializeStateCookie:SameSite=Lax→SameSite=None(alreadySecure), because the cookie is now set from a cross-site fetch response; the top-level callback navigation still sends it. In-place edit;.tsimport extensions untouched.Test evidence
npm test -- --run: 12 test files, 91 tests, all passed (includes rewrittensrc/auth/authStart.test.ts— 7 tests — and newsrc/screens/Landing.test.tsx— 3 tests;src/lib/auth/session.test.tsupdated).npm run lint: clean (no output, exit 0).Live gateway verification (curl, this run):
GET /auth/google/start?apikey=$KEY→ 401UNAUTHORIZED_NO_AUTH_HEADER(the bug)GET /auth/google/startwithapikeyheader → 302 toaccounts.google.com/o/oauth2/v2/auth(the fix path)Behavior assertions (AC #4), not shape: the flag-on test clicks the button, asserts fetch was called with the start URL +
apikeyheader +credentials: 'include', and asserts navigation goes to the Google URL the endpoint returned (explicitly not to the start endpoint); the failure test asserts the error alert appears, navigation never happens, and the mock/lobbyfallback does not fire.Note: the new Edge Function response shape (
200 {redirect}+ preflight allowingapikey) can only be verified end-to-end after stage 9b deploys it — the pre-deploy function still 302s/limits Allow-Headers. Post-deploy manual QA per the proposal:curl -H "apikey: $ANON" "$FN/auth/google/start"returns 200 with anaccounts.google.comURL, then click-through to consent and back to/lobbysigned in (AC #1–#3).Modules
modules: [src/auth/, src/lib/auth/, src/screens/Landing.tsx, src/screens/Landing.test.tsx, supabase/functions/auth/]
Risk
apikeyinAccess-Control-Allow-Headers(verified the preflight requirement is real — the gateway's own 401 response already advertisesapikeyas an allowed header class).auth_error=state_mismatch. Same limitation class already accepted for the session cookie.Landing.test.tsxemits the same "unmount not wrapped in act" stderr warning as the establishedLobby.test.tsxpattern (rule 11 — matched, not introduced).Rollout
Entire change stays behind
flag-cyj-7(no flag → mock lobby navigate, untouched). One PR; on merge, stage9b deploys functions → frontend in order. Rollback: revert the PR and redeploy (or drop the flag from the QA URL).Follow-ups (out of scope, per proposal §7): HMAC-signed stateless OAuth state to remove the third-party-cookie dependency for Safari/Firefox; one CORRECTIONS.md line noting the gateway rejects query-param
apikey(now verified: 401UNAUTHORIZED_NO_AUTH_HEADER).🤖 Generated with Claude Code