Short answer
An edge function is a small piece of server-side code that runs on a provider’s global network, close to the user. Supabase Edge Functions are TypeScript functions on Deno, used for webhooks, calls to paid APIs and anything that needs a secret. They run on the server, so they can hold keys the browser must not see, but every one of them is a public HTTPS endpoint that must check who is calling.
Ask an AI about this page:ChatGPTClaude
On this page
An edge function is server-side code that a platform runs on its global network, close to the user, instead of on one server you manage. Supabase Edge Functions are TypeScript functions running on Deno; Supabase describes them as distributed globally at the edge. Each one answers HTTP requests at a URL under your project, such as https://<project>.supabase.co/functions/v1/send-invoice.
Edge functions in an AI-built app
Apps built with Lovable or Bolt have no back end of their own, so edge functions are where server work goes: receiving a Stripe webhook, calling OpenAI with a key the browser must not see, sending e-mails, or doing admin work with the service role key. Supabase provides the project’s keys to every function as built-in secrets, and you add your own with supabase secrets set.
That power is also the risk. A function is reachable by anyone who knows its URL, and three gaps show up again and again:
- No caller check. The function turns off
verify_jwtand never verifies who is calling, so anyone can trigger an expensive AI call or an admin action. - Trusting the body. The function reads
userIdfrom the JSON body and uses the admin client with it. The caller can name any user. - Leaking the secret. A function returns the API key to the browser (“so the frontend can call OpenAI directly”) or logs it.
How to check your app
- Open
supabase/config.tomland list every function withverify_jwt = false. Each needs another check in code: a webhook signature, a shared secret or a deliberate public purpose. - In each function, find where the user ID comes from. It must come from the verified token, not from
req.json(). - Find every client created with the secret or service role key. Each query through it must be filtered by the verified caller’s ID, or be work that really must cross users.
- Search the responses and
console.logcalls for anything read withDeno.env.get. - For functions that call paid APIs, check for a rate limit and a spend cap.
How to fix or prevent it
Keep verify_jwt on for user-facing functions, read the user from the verified token, and use a client that runs as that user so RLS keeps applying. Use the admin client only where you must, filtered by the caller’s ID. The full walkthrough is in Securing Supabase Edge Functions; the two most common fixes are Edge function without auth check and Edge function trusts user_id from the body.
Frequently asked questions
Is an edge function private because it is not linked in my app?
No. Every deployed function has a public URL under your project. Anyone who finds the name can call it, so it must check the caller itself or rely on verify_jwt.
When is verify_jwt = false okay?
Supabase’s docs name service-to-service calls, deliberately public functions and external webhooks. A webhook must then verify the sender’s signature in code; a user-facing function should keep the check on.
Can I keep my OpenAI or Stripe key in an edge function?
Yes, that is one of the main reasons to have one. Store it as an Edge Function secret and read it with Deno.env.get. Never return it in a response or log it.
Sources
- 1.Edge Functions — Supabase Docs
- 2.Securing Edge Functions — Supabase Docs
- 3.Environment variables (secrets) — Supabase Docs
- 4.Understanding API keys — Supabase Docs