Skip to content
VibeSafeDaily

Publishing

Your Supabase Edge Function fails CORS on localhost after CLI v3.1.0

Cataloged November 10, 2026 · Supabase · Cursor · Bolt · Replit

Symptom

The browser call to your Edge Function worked yesterday. After the Supabase CLI is upgraded to v3.1.0, the browser's CORS check blocks it. v3.1.0 was published on GitHub on November 9, 2026 at 13:14 UTC. The release notes say: One gotcha: local CORS on /functions/v1 changed. The function is the one the local stack serves, from supabase start or supabase functions serve. The page calls it with supabase.functions.invoke, or with a fetch to http://127.0.0.1:54321/functions/v1/ and the function name. Under Improvements the same notes say: Gotcha: CORS on /functions/v1 is now handled by your function — the gateway no longer adds Access-Control-Allow-Origin: *, so a function that sends no CORS headers will be blocked by browsers. Add the headers in the function, or check your function's CORS handling if you call it from a browser. They also say: Stack CORS now matches the hosted platform — preflights return 200 instead of 204, with a wider method list.

Root cause

The local gateway used to add Access-Control-Allow-Origin: * and answer the preflight itself. supabase/cli PR #7472, fix(stack): leave CORS on /functions/v1 to the function (CLI-2923), merged November 4, 2026, states what that gateway did. The local stack's HttpProxy answered every preflight with 204 and Access-Control-Allow-Origin: *, and added * to function responses that set no Allow-Origin. A function that restricts origins never saw the preflight, and its denied responses became readable from any origin. The PR says: On the platform, and on self-hosted after supabase/supabase#52709, the function decides. The /functions/v1 route now leaves CORS to the function. Functions called from a browser must now handle CORS themselves, as on the platform. The legacy Kong path is unchanged. Router errors, which the PR lists as 404, 401, worker errors, and 500, still send Access-Control-Allow-Origin: *, Allow-Headers and Expose-Headers: sb-error-code. The same PR says: A preflight to a missing or crashing function still fails, since it is not a 2xx. A blocked preflight can mean the function is not running, or that it throws before it sends a response. Check the function logs. The v3.1.0 notes cite PR #7485 for the other half of the gateway change: Stack CORS now matches the hosted platform — preflights return 200 instead of 204, with a wider method list. If a function sends no CORS headers, a browser call to the hosted version is blocked too, because on the platform the function decides. The old local behavior was hiding that. Local now tells the truth. Pinning the CLI at v3.0.x puts the old gateway back. That is a stopgap, and it keeps hiding the hosted problem. The Supabase docs page CORS (Cross-Origin Resource Sharing) support for Invoking from the browser says: To invoke edge functions from the browser, you need to handle CORS Preflight requests. The withSupabase wrapper from npm:@supabase/server@^1 handles CORS and the OPTIONS preflight. On @supabase/supabase-js v2.95.0 and later, the same page says to import { corsHeaders } from 'npm:@supabase/supabase-js@^2/cors', answer req.method === 'OPTIONS' with Response.json({ ok: true }, { headers: corsHeaders }), and include headers: corsHeaders on every response, including errors. The doc's example returns a 400 with corsHeaders in the catch. Before v2.95.0, the page shows a _shared/cors.ts that sets Access-Control-Allow-Origin to '*', Access-Control-Allow-Headers to 'authorization, x-client-info, apikey, content-type, x-retry-count, traceparent, tracestate, baggage', and Access-Control-Allow-Methods to 'GET, POST, PUT, PATCH, DELETE, OPTIONS'. The header table on that page says authorization, apikey, and x-client-info are sent on every request, content-type is sent on requests with a body, x-retry-count is sent only on automatic retries, and traceparent, tracestate, and baggage are sent only when trace propagation is explicitly enabled. As of supabase-js v2.112.3 the SDK list includes the trace headers. A function deployed with an older version needs a redeploy before browsers can call it with trace propagation enabled. A function that only serves your own app can list your app's origin instead of *. Do not set Access-Control-Allow-Origin to * on a function that relies on cookies.

Before and after

The before line returns Response.json(data) and has no OPTIONS branch. The v3.1.0 release notes say the local gateway no longer adds Access-Control-Allow-Origin: *, so a browser blocks a function that sends no CORS headers. The after lines are the docs' pattern for @supabase/supabase-js v2.95.0 and later: import { corsHeaders } from 'npm:@supabase/supabase-js@^2/cors', answer OPTIONS first, and pass headers: corsHeaders on the response. That page also puts corsHeaders on error responses, including a 400 in the catch.

Before

return Response.json(data);

After

import { corsHeaders } from 'npm:@supabase/supabase-js@^2/cors';

if (req.method === 'OPTIONS') {
  return Response.json({ ok: true }, { headers: corsHeaders });
}

return Response.json(data, { headers: corsHeaders });

Fix prompt

In this project only. Do not scan or test anyone else's app. Do not print keys, tokens, passwords, or environment variable values. When you mention a variable, print the name only.

1. List the files at supabase/functions/*/index.ts in this project. For each one, search this project's own code for functions.invoke and for /functions/v1/, and say whether browser code calls that function. If none of them are called from the browser, say so and stop.

2. For each function the browser calls, report whether the file handles OPTIONS and whether it sends CORS headers on success responses and on error responses, including catch, 400, and 401. Name the file and the lines. Do not print keys or env values.

3. If this project already uses @supabase/server, prefer the withSupabase wrapper from npm:@supabase/server@^1. The Supabase docs say that wrapper handles CORS and the OPTIONS preflight. Show me the diff. Do not change auth checks. Do not add @supabase/server if this project does not already use it.

4. Otherwise, if this project can use @supabase/supabase-js v2.95.0 or later, add import { corsHeaders } from 'npm:@supabase/supabase-js@^2/cors'. Put the OPTIONS branch first. When req.method === 'OPTIONS', return Response.json({ ok: true }, { headers: corsHeaders }) before any other work. Add headers: corsHeaders to every Response in that function, including catch, 400, and 401. The docs' example returns a 400 with corsHeaders in the catch. Show me the diff. Do not change auth checks.

5. If this project is on supabase-js older than v2.95.0, add supabase/functions/_shared/cors.ts the way the docs show it for that range. That file sets Access-Control-Allow-Origin to '*', Access-Control-Allow-Headers to 'authorization, x-client-info, apikey, content-type, x-retry-count, traceparent, tracestate, baggage', and Access-Control-Allow-Methods to 'GET, POST, PUT, PATCH, DELETE, OPTIONS'. If this function only serves this project's own app, you may set Access-Control-Allow-Origin to this app's origin instead of '*'. Do not set Access-Control-Allow-Origin to '*' on a function that relies on cookies. Answer OPTIONS first with a 2xx that includes those headers, and add the headers to every Response, including errors. Show me the diff. Do not change auth checks.

6. Do not pin the CLI, and do not downgrade it, as the fix. Pinning v3.0.x only brings the old local gateway back, and that keeps hiding the same failure on the hosted project. When the diff is in, tell me to rerun supabase functions serve, retest the call in my own browser, and redeploy the hosted function. If trace propagation is enabled and the deployed function was built before supabase-js v2.112.3, the docs say that redeploy is required before browsers can call it, because v2.112.3 is when the SDK list includes the trace headers.

Do not print keys. Do not edit unrelated files.

Paste this into the coding tool that has your own project open.

2-minute self-check

These steps are for an app you own. Do not run them against someone else's project.

  1. In your own project, run supabase --version. Supabase CLI v3.1.0 was published on GitHub on November 9, 2026 at 13:14 UTC, and the release notes say local CORS on /functions/v1 changed in that version. Do not run this in anyone else's project.
  2. Open your own app locally. In your own browser's devtools, open the Network tab and find the OPTIONS request to /functions/v1/ and your function's name. Check that it returns a 2xx and that the response includes Access-Control-Allow-Origin. The v3.1.0 notes say stack preflights return 200 instead of 204. Do not open anyone else's app.
  3. In your own supabase/functions files, search for OPTIONS and for corsHeaders. The docs say the OPTIONS response carries corsHeaders, and that headers: corsHeaders is also on error responses, including the 400 in the catch example. Confirm an error path in your own function sends the CORS headers too.
  4. If that OPTIONS request is not a 2xx, PR #7472 says a preflight to a missing or crashing function still fails, since it is not a 2xx. Check your own function logs. The function may not be running, or it may throw before it responds. Do not read anyone else's logs.

Common questions

It worked yesterday. Did I break something?

The function can be unchanged. Supabase CLI v3.1.0 was published on GitHub on November 9, 2026 at 13:14 UTC, and the release notes say: One gotcha: local CORS on /functions/v1 changed. Under Improvements they say the gateway no longer adds Access-Control-Allow-Origin: *, so a function that sends no CORS headers will be blocked by browsers. PR #7472, merged November 4, 2026, says the local stack's HttpProxy used to answer every preflight with 204 and Access-Control-Allow-Origin: *, and to add * to function responses that set no Allow-Origin. The same PR says: On the platform, and on self-hosted after supabase/supabase#52709, the function decides. A function with no CORS headers was already blocked when a browser called the hosted version. The old local gateway was hiding that.

Should I just downgrade the CLI?

Pinning v3.0.x puts the old local gateway back. That is a stopgap, and it keeps hiding the hosted problem. PR #7472 says functions called from a browser must now handle CORS themselves, as on the platform. The fix is in the function. The docs page on CORS for invoking from the browser says the withSupabase wrapper from npm:@supabase/server@^1 handles CORS and the OPTIONS preflight. On @supabase/supabase-js v2.95.0 and later, the same page says to import { corsHeaders } from 'npm:@supabase/supabase-js@^2/cors', answer OPTIONS with Response.json({ ok: true }, { headers: corsHeaders }), and include headers: corsHeaders on every response, including errors.

I added corsHeaders and it still fails.

The docs answer req.method === 'OPTIONS' before the rest of the handler, with Response.json({ ok: true }, { headers: corsHeaders }), and they put headers: corsHeaders on error responses too. The doc's example returns a 400 with corsHeaders in the catch. PR #7472 says a preflight to a missing or crashing function still fails, since it is not a 2xx, so check the function logs. The header table on the docs page says traceparent, tracestate, and baggage are sent only when trace propagation is explicitly enabled. As of supabase-js v2.112.3 the SDK list includes those trace headers, and a function deployed with an older version needs a redeploy before browsers can call it with trace propagation enabled.

Sources

Same symptom

Same platform