SecuritySep 26, 2026·7 min read

Why Your Edge Functions Run Admin Tasks for Anyone Who Knows the URL

I tested a client's serverless edge function: one unauthenticated curl request deleted a test account in 110ms. Here is why AI tools initialize service roles without checking caller JWTs.

#Edge Functions#Supabase#Serverless#JWT Verification#Security Audit

01Run this check right now

Diagnostic Test

The Unauthenticated Function Curl Test

Send a POST request to your edge function without passing an Authorization header. If the endpoint returns an HTTP 200 response or attempts to execute database logic, the function is accessible to anyone on the internet.

curl -i -X POST "https://<PROJECT_ID>.supabase.co/functions/v1/delete-user" -H "Content-Type: application/json" -d '{"userId":"test"}'

Findings from the Field

  • /01I fired a curl POST request with no Authorization header to a live edge function, and it executed an administrative user deletion in 110ms.
  • /02AI models initialize edge functions with SUPABASE_SERVICE_ROLE_KEY to bypass Row Level Security errors during development.
  • /03Edge function URLs are public HTTPS routes: unless gateway JWT verification is explicitly enabled, anyone who discovers the slug can invoke it.
  • /04How to set verify_jwt = true in config.toml to drop anonymous requests before execution.
  • /05How to verify the caller's specific administrative role inside Deno / Node.js handler code.

The 110-millisecond admin curl call

While reviewing an AI-built marketplace prototype, I noticed an edge function in their repository named `delete-user`. It was designed to allow administrators to ban fraudulent accounts from a dashboard.

Curious how the function verified permissions, I opened my terminal and sent a raw POST request directly to the function's public URL without passing any authentication headers or session cookies:

In 110 milliseconds, the server returned `HTTP/2 200 OK` with `{"success": true}`. The test account was gone. Anyone on the internet who guessed or discovered the function URL could delete arbitrary user profiles with a curl one-liner.

Terminal unauthenticated curl checkbash
curl -i -X POST "https://<PROJECT_ID>.supabase.co/functions/v1/delete-user" \
  -H "Content-Type: application/json" \
  -d '{"targetUserId": "user_sandbox_99"}'

Why AI tools reach for service role keys

When an AI coding assistant writes an administrative feature, it encounters permission errors during early testing. Deleting a user account or modifying paid billing plans requires elevated privileges that standard user tokens do not possess.

To make the feature work, the assistant reaches for the master administrative key: `SUPABASE_SERVICE_ROLE_KEY`. This key bypasses all PostgreSQL Row Level Security policies.

The problem is that the model treats the edge function as an internal, private helper. In reality, edge functions hosted on Supabase, Vercel, or Cloudflare are public HTTP endpoints sitting on the open internet.

The lobby security guard analogy

Think of it like hiring a security guard and handing them a master skeleton key that unlocks every office door in the building. That is the service role key.

Now imagine you place that guard in the open public lobby. Anyone walking down the street can tap the guard on the shoulder and say: 'Walk up to office 304 and shred all the documents inside.' If the guard blindly follows instructions without asking for an employee badge, having a secure lock on the office door does not matter.

Step 1: Enforce gateway verification in config.toml

Supabase provides an API gateway layer that can block unauthenticated requests before your function code even spins up.

In your project's `supabase/config.toml`, verify that `verify_jwt` is set to `true` for all non-public functions:

With `verify_jwt = true`, any request lacking a valid bearer token receives an immediate HTTP 401 response from the edge router in 12ms.

supabase/config.tomltoml
[functions.delete-user]
verify_jwt = true

Step 2: Verify caller role inside the function

Gateway verification proves that the caller is logged in, but you must also verify that the caller is an administrator before executing destructive actions. Validate the caller's session token and role before initializing the admin client:

Secure edge function with caller role check (Deno)typescript
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
import { createClient } from "https://esm.sh/@supabase/supabase-js@2";

serve(async (req) => {
  const authHeader = req.headers.get("Authorization");
  if (!authHeader) {
    return new Response(JSON.stringify({ error: "Missing token" }), { status: 401 });
  }

  // Create client scoped to incoming user's token
  const userClient = createClient(
    Deno.env.get("SUPABASE_URL")!,
    Deno.env.get("SUPABASE_ANON_KEY")!,
    { global: { headers: { Authorization: authHeader } } }
  );

  const { data: { user }, error } = await userClient.auth.getUser();
  if (error || !user) {
    return new Response(JSON.stringify({ error: "Invalid session" }), { status: 401 });
  }

  // Confirm user has administrative privileges
  if (user.app_metadata?.role !== "admin") {
    return new Response(JSON.stringify({ error: "Admin role required" }), { status: 403 });
  }

  // Safe to execute admin logic
  const { targetUserId } = await req.json();
  const adminClient = createClient(
    Deno.env.get("SUPABASE_URL")!,
    Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!
  );
  await adminClient.auth.admin.deleteUser(targetUserId);

  return new Response(JSON.stringify({ success: true }));
});

Reflections: public URLs demand strict gates

After applying `verify_jwt = true` and adding the role check, I re-ran the unauthenticated curl request. The gateway dropped it instantly with a 401 status. When I tested with a regular user token, the function returned 403 Forbidden. Only a verified admin token could trigger deletion.

Every edge function is an open door until you put a lock on the gateway and check badges at the door. Now back to building, because yolo.

Production Hardening & Audits

Stuck on prompt regressions, leaked keys, or database scaling in an AI-built app? Explore our platform-specific teardowns:

Diagnostic & Rescue

1 business day reply

Think your prototype is vulnerable or hitting scale limits?

Send us a note with your repository, Supabase link, or project details. A senior engineer will review your policies and reply within one business day.