Skip to content

fix(stack): leave CORS on /functions/v1 to the function (CLI-2923) - #7472

Merged
avallete merged 3 commits into
developfrom
avallete/cli-2923-httpproxy-functions-cors
Nov 4, 2026
Merged

avallete merged 3 commits into
developfrom
avallete/cli-2923-httpproxy-functions-cors

Conversation

@avallete

@avallete avallete commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Problem

The stack's HttpProxy answers every preflight with 204 and Access-Control-Allow-Origin: *, and adds * to function responses that set no Allow-Origin. A function that restricts origins never sees the preflight, and its denied responses become readable from any origin. On the platform, and on self-hosted after supabase/supabase#52709, the function decides.

Resolves CLI-2923.

Solution

  1. HttpRoute.upstreamCors: the proxy skips its CORS headers and preflight shortcut on that route. The proxy's own 502 keeps *.
  2. The /functions/v1 shared route sets it.
  3. serve.main.ts: router errors (404, 401, worker errors, 500) send Access-Control-Allow-Origin: *, Allow-Headers and Expose-Headers: sb-error-code, matching fix(self-hosted): add CORS headers to Edge Functions router errors supabase#52710, so browsers can read them on requests that skip the preflight. A preflight to a missing or crashing function still fails, since it is not a 2xx.

Functions called from a browser must now handle CORS themselves, as on the platform. The legacy Kong path is unchanged.

🤖 Generated with Claude Code

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]>
@avallete
avallete requested a review from a team as a code owner November 3, 2026 17:33
@avallete
avallete requested a review from Prashansa-K November 3, 2026 17:33
@avallete

avallete commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

/ai-review

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

CLI benchmark (Lightweight Commands): no changes found

Commit 947d796 against develop at 0a245f2 · 10 runs each · report only, never blocks merging

Command Workload Before After Change
supabase --version version 357 ms 371 ms no real change
supabase --help help 329 ms 352 ms no real change (+7%, within normal variation)
supabase init init 337 ms 338 ms no real change
supabase migration new bench migration-new 381 ms 365 ms no real change
supabase gen types --lang typescript --project-id replayfixtureprojref gen-types 438 ms 447 ms no real change
supabase projects list projects-list 372 ms 427 ms no real change (+15%, within normal variation)
supabase functions list --project-ref replayfixtureprojref functions-list 474 ms 471 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 330-455 ms 332-407 ms +14 ms (+4%) within noise
supabase --help help 291-394 ms 301-433 ms +22 ms (+7%) within noise
supabase init init 305-390 ms 299-374 ms +1 ms (+0%) within noise
supabase migration new bench migration-new 299-447 ms 317-428 ms -16 ms (-4%) within noise
supabase gen types --lang typescript --project-id replayfixtureprojref gen-types 373-510 ms 387-468 ms +9 ms (+2%) within noise
supabase projects list projects-list 322-704 ms 324-704 ms +55 ms (+15%) within noise
supabase functions list --project-ref replayfixtureprojref functions-list 373-649 ms 365-596 ms -3 ms (-1%) 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.

@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

Confirmed one minor test-coverage gap. No functional defect was verified. Codex reported no findings. Verification used the checked-out source and tests; tests were not run.

Findings

Severity Location Category Sources Claim
🟡 MINOR packages/stack/src/functions/serve.main.ts:212 test-coverage claude Tests do not verify the new CORS headers on Functions router errors or the production Functions route's CORS delegation. The new proxy test supplies upstreamCors: true manually, so removing the production flag or router-error headers would escape this coverage.

Stats

Claude findings: 1 · Codex findings: 0 · Confirmed: 1 · 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.

@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

Both independent reviews were available. Confirmed Claude's minor test-coverage finding; Codex reported no findings. The CORS implementation and route wiring appear correct, but their integration lacks regression coverage. Runtime tests were not run.

Findings

Severity Location Category Sources Claim
🟡 MINOR packages/stack/src/functions/serve.main.ts:212 test-coverage claude Tests do not verify the stack bootstrap's router-error CORS headers or that the real functions shared route delegates CORS upstream. Regressions in either behavior could pass the current tests.

Stats

Claude findings: 1 · Codex findings: 0 · Confirmed: 1 · 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.

@7ttp 7ttp 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.

😄 gave this a first pass and tested it end to end alongside supabase/supabase#52709 and supabase/supabase#52710 on self-host and the cors lines up...

tho i've got a couple of super smol (non-blocking) suggestions below:

@avallete
avallete added this pull request to the merge queue Nov 4, 2026
Merged via the queue into develop with commit bb34a18 Nov 4, 2026
69 of 70 checks passed
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.

4 participants