Repository navigation
fix(stack): align gateway CORS with the platform - #7485
Conversation
The HttpProxy answered every preflight and added Access-Control-Allow-Origin: * to function responses, so a function could not restrict origins. The functions route now passes CORS through to the function, as on the platform. Router errors carry their own CORS headers so browsers can still read them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…I-2923) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Gateway preflights answer 200 with the platform's methods list and echo the requested headers; proxied responses carry the upstream's CORS with the request origin as allow-origin. A live test probes staging and the local stack with the same requests and compares the results. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Superseded by a newer AI review
🤖 AI Review
Verified all five findings against the checked-out code and trusted conventions. Merged the duplicate CORS finding into one entry, leaving four confirmed findings: three minor concerns and one maintainability nit. Suite-wide project deletion limits the cleanup issue's impact. No major or critical findings were confirmed.
Findings
| Severity | Location | Category | Sources | Claim |
|---|---|---|---|---|
| 🟡 MINOR | packages/stack/src/HttpProxy.ts:465 |
http-semantics |
claude+codex | Gateway-owned proxied responses reflect the request's Origin without ensuring Vary: Origin. A cacheable upstream response lacking that variation can be reused with another origin's Access-Control-Allow-Origin value, causing valid cross-origin requests to fail. |
| 🟡 MINOR | apps/cli/src/commands/experimental/stack/start/start.gateway-cors.live.test.ts:241 |
test-flakiness |
codex | The readiness check can accept earlier deployment-related 404 responses as the platform baseline when the function becomes ready during probe collection, producing a false parity failure. |
| 🟡 MINOR | apps/cli/src/commands/experimental/stack/start/start.gateway-cors.live.test.ts:183 |
test-robustness |
claude | Function cleanup stops after the first deletion failure, and a partially successful deployment that exits unsuccessfully never registers the release action. Functions can therefore remain on the shared project until suite teardown. |
| ⚪ NIT | apps/cli/src/commands/experimental/stack/start/start.gateway-cors.live.test.ts:242 |
test-maintainability |
claude | Readiness selects the allowed-origin POST probe by the hard-coded index rows[3], so changing probe order can silently change which request establishes readiness. |
Stats
Claude findings: 3 · Codex findings: 2 · Confirmed: 4 · Refuted: 0 · Uncertain: 0
Models: claude-opus-5-5 + gpt-6.1-sol · Trigger: auto · Workflow run
This review runs once per PR. A maintainer can request another with a /ai-review comment.
The live parity test waits for readiness before collecting the staging matrix, and registers function cleanup before deploying, deleting each slug independently. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
/ai-review |
…gateway-cors-parity # Conflicts: # packages/stack/src/HttpProxy.integration.test.ts # packages/stack/src/HttpProxy.ts # packages/stack/src/functions/serve-main-bundler.integration.test.ts # packages/stack/src/functions/serve.main.ts
|
/ai-review |
There was a problem hiding this comment.
🤖 AI Review
Confirmed both Codex findings after reading the cited code, surrounding proxy and deployment logic, and trusted conventions. Claude reported no findings. No duplicates required merging.
Findings
| Severity | Location | Category | Sources | Claim |
|---|---|---|---|---|
| 🟡 MINOR | packages/stack/src/HttpProxy.ts:478 |
correctness |
codex | Origin-dependent proxied responses omit Vary: Origin when the request has no Origin header, allowing caches to reuse the wildcard response for requests requiring an echoed origin. |
| 🟡 MINOR | apps/cli/src/commands/experimental/stack/start/start.gateway-cors.live.test.ts:247 |
test-flakiness |
codex | The readiness check waits for only one of the two deployed functions before recording platform responses, leaving the comparison vulnerable to deployment propagation delays for the JWT-protected function. |
Stats
Claude findings: 0 · Codex findings: 2 · Confirmed: 2 · Refuted: 0 · Uncertain: 0
Models: claude-opus-5-5 + gpt-6.1-sol · Trigger: manual · Workflow run
This review runs once per PR. A maintainer can request another with a /ai-review comment.
The live parity test also waits for the verify_jwt function to stop answering 404 before recording the staging matrix. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
/ai-review |
1 similar comment
|
/ai-review |
CLI benchmark (Lightweight Commands): no changes foundCommit
API calls: unchanged for all 7 commands. Binary size: 134.1 MB, unchanged. Details: timing ranges, API calls per command, slowest phasesTiming ranges
API calls per command
Slowest phasesNo command moved beyond noise, so there are no phase deltas. Comment |
kanadgupta
left a comment
There was a problem hiding this comment.
LGTM! a few notes via claude:
Verdict: looks good, minor comments only. The gateway change matches the parity matrix in the description and the merged self-hosted PRs, and the earlier AI-review threads are fixed in the code as described.
Verified
- Read
HttpProxy.tsend to end atdd71b64: preflights answer 200 with the methods list and echoed request headers; proxied non-functions responses keep upstream headers, echoOrigin, and always mergeVary: Origin; gateway-generated 404/502 carry*plus the methods list;/functions/v1is untouched.- The stack's main worker (
serve.main.ts) already sends*/authorization, x-client-info, apikey/sb-error-codeon its own 404 and 401, so the functions rows of the matrix are served by code already ondevelop.- Local:
HttpProxy.integration.test.ts39/39 pass,tscclean forpackages/stackandapps/cli,oxlintandoxfmt --checkclean on the three changed files.- CI on head is green (unit, integration, e2e shards, CodeQL, PR lint).
Not verified
- The live test has not run anywhere I can see:
live-e2e.ymlonly triggers on push todevelop, nightly, or manual dispatch, and I have no staging token or Docker locally. Its first real run is the next push todevelop. Two things to watch there are in the inline comments: the cold Docker image pulls against the 20-minute step budget, and the PostgRESTexpose-headerscomparison.
…rity probe Co-Authored-By: Claude Opus 5.5 <[email protected]>
Aligns the local stack gateway's CORS responses with the hosted platform and adds a live parity test that keeps them aligned.
Gateway changes (
packages/stack/src/HttpProxy.ts)For routes where the gateway owns CORS (everything except
/functions/v1):200(was204), listGET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS,TRACE,CONNECT, and echoAccess-Control-Request-Headers, defaulting toaccept-profile,apikey,authorization,x-client-info.Access-Control-Allow-Originto the request origin; the gateway no longer adds allow-methods/allow-headers to them.*and the methods list.Live parity test
start.gateway-cors.live.test.tsdeploys an origin-restricted function (and averify_jwt = truecopy) to the live suite's project, serves the same functions fromstack start --runtime docker, sends the same 10 probes to both, and asserts the stack's results equal staging's. Staging is the oracle; no expected headers are hard-coded. It runs in the existing live job.GET /rest/v1/is not probed: with a publishable key the platform answers 401 there and the stack 200, which is an auth difference, not a gateway CORS one.Gateway parity matrix
Same 10 probes against a staging project, this branch's local stack (
stack start --runtime docker), and self-hosted Docker with supabase/supabase#52709 and supabase/supabase#52710 applied. Cells read status / allow-origin / allow-credentials / allow-methods / allow-headers / expose-headers; "match" means identical to staging. "methods list" isGET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS,TRACE,CONNECT. Self-hosted row 7 usesFUNCTIONS_VERIFY_JWT=true, the other rowsfalse.403/ – /true/ – / – / –204/app origin/true/ – / – / –200/ – /true/ – / – / –200/app origin/true/ – / – / –404/*/ – / – /authorization, x-client-info, apikey/sb-error-code404/*/ – / – /authorization, x-client-info, apikey/sb-error-code401/*/ – / – /authorization, x-client-info, apikey/sb-error-code200/*/ – /methods list/accept-profile,apikey,authorization,x-client-info/ –200/request origin/ – /GET,POST,PUT,PATCH,DELETE,OPTIONS,HEAD,CONNECT,TRACE/ (empty) /*200/*/ – /methods list/authorization, x-custom-header/ –200/request origin/ – /GET,POST,PUT,PATCH,DELETE,OPTIONS,HEAD,CONNECT,TRACE/authorization, x-custom-header/*404/request origin/ – / – / – /PostgREST list404/request origin/ – / – / – /*The local stack matches staging on every probe. Self-hosted matches on all function probes; its REST CORS differs from staging and is outside this PR.
🤖 Generated with Claude Code