Skip to content

Self-hosted: gateway CORS on /functions/v1 allows every origin and overrides the function's own CORS (differs from hosted) #52346

Closed

Description

@yousan
  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord. (Searched issues and Discussions; not Discord.)

Describe the bug

TL;DR

  • docker/volumes/api/envoy/lds.template.yaml sets a CORS policy on the whole virtual host that allows every origin (safe_regex: ".*"). The functions-v1-all route does not override it.
  • So for /functions/v1/*, Envoy answers CORS preflights itself and adds Access-Control-Allow-Origin for any origin. A function that only allows certain origins never gets a say.
  • On the hosted platform, the function decides: the docs ask functions to handle CORS themselves, and the function's response is returned as-is. The same function behaves differently when self-hosted, and nothing points to it.
  • The Kong overlay looks the same: functions-v1 has the cors plugin with no origins set, which Kong treats as *. (We only tested Envoy.)

We hit this while moving a project from the hosted platform to the self-hosted stack. Its functions only allow the project's own sites. After the move, every origin was accepted.

To Reproduce

  1. Add a function that only allows one origin, e.g. volumes/functions/cors-test/index.ts:
const ALLOWED = "https://app.example.com";

Deno.serve((req) => {
  const origin = req.headers.get("Origin") ?? "";
  const headers: Record<string, string> = { Vary: "Origin" };
  if (origin === ALLOWED) {
    headers["Access-Control-Allow-Origin"] = ALLOWED;
    headers["Access-Control-Allow-Headers"] = "authorization, x-client-info, apikey, content-type";
  }
  if (req.method === "OPTIONS") {
    return new Response(null, { status: origin === ALLOWED ? 204 : 403, headers });
  }
  return new Response("ok", { headers });
});
  1. Send a preflight from another origin:
curl -si -X OPTIONS http://localhost:8000/functions/v1/cors-test \
  -H 'Origin: https://evil.example' \
  -H 'Access-Control-Request-Method: POST' \
  | grep -i -E '^HTTP|^access-control-allow-origin'

Actual: access-control-allow-origin: https://evil.example comes back. Envoy answers the preflight and the function is not called. Non-preflight requests from that origin also get Access-Control-Allow-Origin added by Envoy.

Expected behavior

The function's own answer (here 403 with no Access-Control-Allow-Origin), as on the hosted platform.

The README asks self-hosters to "Review and update CORS settings", but it is not obvious that the gateway's CORS takes over from the function's own CORS for /functions/v1.

Suggested fix

Leave CORS for /functions/v1 to the function, as on the hosted platform. In lds.template.yaml, add under functions-v1-all → typed_per_filter_config:

                          envoy.filters.http.cors:
                            '@type': >-
                              type.googleapis.com/envoy.config.route.v3.FilterConfig
                            disabled: true

and drop the cors plugin from functions-v1 in kong.yml. We run the Envoy change in our deployment: allowed origins still work from the browser, and other origins get the function's answer.

Functions that don't handle CORS themselves would then fail from the browser, the same as on hosted. If that is a concern for existing self-hosters, an env flag or a note in the self-hosting docs would also help.

System information

  • Self-hosted Docker stack with the default Envoy gateway, supabase/supabase at 5bdb7399
  • The relevant lines of lds.template.yaml and kong.yml are unchanged on master (eec2d0f9)

Additional context

On the hosted platform, a preflight from any origin to /rest/v1, /auth/v1 and /storage/v1 returns Access-Control-Allow-Origin: * (we checked these three), so the catch-all policy matches hosted there. /functions/v1 is where the two differ.

Activity

  1. added
    external-issue
    on Oct 27, 2026
  2. dave-otf commented on Oct 27, 2026

    @dave-otf

    The untested path is the risky one: Envoy is reproduced, while Kong is still inferred from config.

    Could the regression test run allowed and unlisted-Origin preflights against each default self-hosted gateway and assert the function's status plus exact Access-Control-Allow-Origin value are preserved? That would expose a Kong plugin that still short-circuits OPTIONS before the change is described as matching hosted behavior.

  3. self-assigned this
    on Oct 27, 2026
  4. added
    self-hosted
    on Oct 27, 2026
  5. added
    pr-opened
    and removed on Oct 27, 2026
  6. solvionholdings commented on Oct 29, 2026

    @solvionholdings

    Until there's a fix, a workaround is to turn gateway CORS off for the functions route so preflights reach the function. The Envoy template already disables filters per route with FilterConfig (basic_auth on this same route), so the same pattern on functions-v1-all in volumes/api/envoy/lds.template.yaml should work:

    typed_per_filter_config:
      envoy.filters.http.cors:
        '@type': >-
          type.googleapis.com/envoy.config.route.v3.FilterConfig
        disabled: true
      # existing basic_auth and rbac entries unchanged

    For the Kong overlay, either remove - name: cors from the functions-v1 plugins in volumes/api/kong.yml, or restrict it and pass preflights through:

    - name: cors
      config:
        origins: ["https://app.example.com"]
        preflight_continue: true

    I haven't run the Envoy change myself, so check it with your curl repro after restarting the gateway: an unlisted Origin should get the function's 403 with no Access-Control-Allow-Origin, and the allowed origin should get exactly that value back.

    For anyone else landing here: CORS only controls which browser pages can read the response. It isn't access control, so functions that should only serve certain callers still need auth (verify_jwt or their own check) whatever the gateway does.

  7. aantti commented on Nov 2, 2026

    @aantti
    Contributor

    A historical glitch that got into the recent Envoy upgrade/config, apologies - will address this. Appreciate the detailed reporting 🙏

  8. solvionholdings commented on Nov 2, 2026

    @solvionholdings

    Thanks for confirming! Happy to test the fix on a self-hosted setup once there's a PR or image tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

external-issuepr-openedself-hosted

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions