Repository navigation
Description
- 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.yamlsets a CORS policy on the whole virtual host that allows every origin (safe_regex: ".*"). Thefunctions-v1-allroute does not override it.- So for
/functions/v1/*, Envoy answers CORS preflights itself and addsAccess-Control-Allow-Originfor 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-v1has thecorsplugin with nooriginsset, 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
- 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 });
});- 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: trueand 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/supabaseat5bdb7399 - The relevant lines of
lds.template.yamlandkong.ymlare 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.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dave-otf commentedon Oct 27, 2026
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-Originvalue are preserved? That would expose a Kong plugin that still short-circuitsOPTIONSbefore the change is described as matching hosted behavior.solvionholdings commentedon Oct 29, 2026
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 onfunctions-v1-allinvolumes/api/envoy/lds.template.yamlshould work:For the Kong overlay, either remove
- name: corsfrom thefunctions-v1plugins involumes/api/kong.yml, or restrict it and pass preflights through: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.
aantti commentedon Nov 2, 2026
A historical glitch that got into the recent Envoy upgrade/config, apologies - will address this. Appreciate the detailed reporting 🙏
solvionholdings commentedon Nov 2, 2026
Thanks for confirming! Happy to test the fix on a self-hosted setup once there's a PR or image tag.