Skip to content

fix(stack): align gateway CORS with the platform - #7485

Merged
avallete merged 7 commits into
developfrom
avallete/cli-2923-gateway-cors-parity
Nov 5, 2026
Merged

avallete merged 7 commits into
developfrom
avallete/cli-2923-gateway-cors-parity

Conversation

@avallete

@avallete avallete commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

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):

  • Preflights return 200 (was 204), list GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS,TRACE,CONNECT, and echo Access-Control-Request-Headers, defaulting to accept-profile,apikey,authorization,x-client-info.
  • Proxied responses keep the upstream's CORS headers and set Access-Control-Allow-Origin to the request origin; the gateway no longer adds allow-methods/allow-headers to them.
  • Responses the gateway generates itself (404, 502) carry * and the methods list.

Live parity test

start.gateway-cors.live.test.ts deploys an origin-restricted function (and a verify_jwt = true copy) to the live suite's project, serves the same functions from stack 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" is GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS,TRACE,CONNECT. Self-hosted row 7 uses FUNCTIONS_VERIFY_JWT=true, the other rows false.

Probe Staging (oracle) Dev stack (this PR) Self-hosted (52709+52710)
OPTIONS function, blocked origin 403 / – / true / – / – / – match match
OPTIONS function, allowed origin 204 / app origin / true / – / – / – match match
POST function, blocked origin 200 / – / true / – / – / – match match
POST function, allowed origin 200 / app origin / true / – / – / – match match
POST missing function 404 / * / – / – / authorization, x-client-info, apikey / sb-error-code match match
OPTIONS missing function 404 / * / – / – / authorization, x-client-info, apikey / sb-error-code match match
POST verify_jwt function, invalid Bearer 401 / * / – / – / authorization, x-client-info, apikey / sb-error-code match match
OPTIONS /rest/v1/, foreign origin 200 / * / – / methods list / accept-profile,apikey,authorization,x-client-info / – match 200 / request origin / – / GET,POST,PUT,PATCH,DELETE,OPTIONS,HEAD,CONNECT,TRACE / (empty) / *
OPTIONS /rest/v1/ with request headers, foreign origin 200 / * / – / methods list / authorization, x-custom-header / – match 200 / request origin / – / GET,POST,PUT,PATCH,DELETE,OPTIONS,HEAD,CONNECT,TRACE / authorization, x-custom-header / *
GET missing table, foreign origin 404 / request origin / – / – / – / PostgREST list match 404 / 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

avallete and others added 3 commits November 3, 2026 18:33
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]>
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]>
@avallete
avallete requested a review from a team as a code owner November 4, 2026 09:33
@avallete
avallete requested review from kanadgupta and removed request for a team November 4, 2026 09:33

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread packages/stack/src/HttpProxy.ts Resolved
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]>
@avallete

avallete commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

/ai-review

@avallete
avallete changed the base branch from avallete/cli-2923-httpproxy-functions-cors to develop November 4, 2026 10:55
…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
@avallete

avallete commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

/ai-review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 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.

Comment thread packages/stack/src/HttpProxy.ts Resolved
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]>
@avallete

avallete commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

/ai-review

1 similar comment
@avallete

avallete commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

/ai-review

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

CLI benchmark (Lightweight Commands): no changes found

Commit dd71b64 against develop at db30ec9 · 10 runs each · report only, never blocks merging

Command Workload Before After Change
supabase --version version 177 ms 182 ms no real change
supabase --help help 188 ms 186 ms no real change
supabase init init 218 ms 212 ms no real change
supabase migration new bench migration-new 213 ms 207 ms no real change
supabase gen types --lang typescript --project-id replayfixtureprojref gen-types 248 ms 249 ms no real change
supabase projects list projects-list 225 ms 214 ms no real change
supabase functions list --project-ref replayfixtureprojref functions-list 218 ms 218 ms no real change

API calls: unchanged for all 7 commands.

Binary size: 134.1 MB, unchanged.

Details: timing ranges, API calls per command, slowest phases

Timing ranges

Command Workload Before range After range Change Verdict
supabase --version version 161-248 ms 160-224 ms +5 ms (+3%) within noise
supabase --help help 173-202 ms 176-198 ms -2 ms (-1%) within noise
supabase init init 196-246 ms 189-230 ms -5 ms (-2%) within noise
supabase migration new bench migration-new 198-271 ms 187-238 ms -6 ms (-3%) within noise
supabase gen types --lang typescript --project-id replayfixtureprojref gen-types 229-419 ms 225-342 ms +0 ms (+0%) within noise
supabase projects list projects-list 214-282 ms 203-261 ms -11 ms (-5%) within noise
supabase functions list --project-ref replayfixtureprojref functions-list 197-258 ms 199-244 ms +0 ms (+0%) within noise

API calls per command

Command Workload Before After Endpoint changes
supabase --version version 0 0
supabase --help help 0 0
supabase init init 0 0
supabase migration new bench migration-new 0 0
supabase gen types --lang typescript --project-id replayfixtureprojref gen-types 2 2
supabase projects list projects-list 1 1
supabase functions list --project-ref replayfixtureprojref functions-list 2 2

Slowest phases

No command moved beyond noise, so there are no phase deltas.

Workflow run

Comment /bench to run the lightweight benchmark (this comment) again on the latest commit, or /bench full to also run the integration-heavy benchmark, which posts in its own comment.

@kanadgupta kanadgupta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.ts end to end at dd71b64: preflights answer 200 with the methods list and echoed request headers; proxied non-functions responses keep upstream headers, echo Origin, and always merge Vary: Origin; gateway-generated 404/502 carry * plus the methods list; /functions/v1 is untouched.
  • The stack's main worker (serve.main.ts) already sends * / authorization, x-client-info, apikey / sb-error-code on its own 404 and 401, so the functions rows of the matrix are served by code already on develop.
  • Local: HttpProxy.integration.test.ts 39/39 pass, tsc clean for packages/stack and apps/cli, oxlint and oxfmt --check clean 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.yml only triggers on push to develop, nightly, or manual dispatch, and I have no staging token or Docker locally. Its first real run is the next push to develop. Two things to watch there are in the inline comments: the cold Docker image pulls against the 20-minute step budget, and the PostgREST expose-headers comparison.

@avallete
avallete added this pull request to the merge queue Nov 5, 2026
Merged via the queue into develop with commit 88602ae Nov 5, 2026
61 checks passed
@avallete
avallete deleted the avallete/cli-2923-gateway-cors-parity branch November 5, 2026 09:29
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