Deutsch
Security wikiSupabase · Server

What is an edge function?

Also known as: Supabase Edge Function, serverless function, Deno function, supabase/functions

An edge function is server-side code that runs close to your users. What Supabase Edge Functions are for in AI-built apps and how to check they are locked down.

By Tim GeithnerPublished 2 min read

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_jwt and never verifies who is calling, so anyone can trigger an expensive AI call or an admin action.
  • Trusting the body. The function reads userId from 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

  1. Open supabase/config.toml and list every function with verify_jwt = false. Each needs another check in code: a webhook signature, a shared secret or a deliberate public purpose.
  2. In each function, find where the user ID comes from. It must come from the verified token, not from req.json().
  3. 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.
  4. Search the responses and console.log calls for anything read with Deno.env.get.
  5. 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. 1.Edge Functions — Supabase Docs
  2. 2.Securing Edge Functions — Supabase Docs
  3. 3.Environment variables (secrets) — Supabase Docs
  4. 4.Understanding API keys — Supabase Docs

Find this in your own app

ShipRely reads your repository (read-only), proves each finding with file and line, and gives you a fix prompt to paste into your AI builder.

Run a demo audit
  • Read-only access to your repository
  • Every finding with file and line
  • Fix prompts for Lovable, Cursor, Claude Code and Bolt