high · M3 · MASVS-AUTH-1 · PTKD-BACKEND-SUPABASE-EDGE-NO-AUTH
Supabase Edge Function uses the service-role key without checking the caller
An Edge Function creates a Supabase client with the service-role key, which skips Row Level Security, and nowhere checks who is calling (no auth.getUser / getClaims, no webhook signature, no shared secret). The platform's verify_jwt only checks that the request carries a project JWT, and the public anon key in the app is one, so anyone who has the app can call the function and act on any user's data. With verify_jwt = false not even that is needed.
How it is exploited
delete-account/index.ts does `const { userId } = await req.json(); await admin.auth.admin.deleteUser(userId)` with the service-role client. The app sends the user's own id, but anyone can POST to /functions/v1/delete-account with the anon key from the app bundle and any other user's id.
Why it matters
Any visitor reads, changes or deletes any user's data (or the account itself) through the function, with Row Level Security switched off.
How to fix it
- Read the caller: `const token = req.headers.get('Authorization')?.replace('Bearer ', ''); const { data: { user } } = await supabase.auth.getUser(token); if (!user) return new Response('unauthorized', { status: 401 });`.
- Use `user.id`, never an id from the body or query string.
- Keep verify_jwt on, and for webhook functions verify the provider signature (Stripe constructEvent, RevenueCat authorization header).
supabase/functions/delete-account/index.ts
const token = req.headers.get("Authorization")?.replace("Bearer ", "");
const { data: { user } } = await anon.auth.getUser(token);
if (!user) return new Response("unauthorized", { status: 401 });
await admin.auth.admin.deleteUser(user.id);Does your app have this?
PTKD checks your build or your source project for PTKD-BACKEND-SUPABASE-EDGE-NO-AUTH and every other check in this knowledge base.
Scan your appReferences
Related checks (M3)
- Permissive CORS with credentials
- State-changing request succeeded without authentication
- Weak JWT observed on the wire
- Biometric authentication not bound to a cryptographic key
- Premium access is stored on the phone and trusted (heuristic)
- Firebase rules trust an email address nobody verified
- Firebase security rules open to everyone
- Users can make themselves admin or premium in Firestore