medium · M3 · MASVS-AUTH-1 · PTKD-BACKEND-SUPABASE-EDGE-OPEN-PROXY
Supabase Edge Function lets anyone spend your AI, email or SMS credits (heuristic)
An Edge Function calls a paid API (OpenAI, Anthropic, Gemini, Replicate, ElevenLabs, Resend, Twilio...) and checks neither who is calling nor how often. The anon key in the app is enough to call it, so a script can run up your bill or send mail and SMS in your name. Moving the API key to a function only helps when the function also checks the user and limits use.
How it is exploited
The app's chat screen calls /functions/v1/chat, which forwards the prompt to OpenAI with the project key. Someone copies the anon key from the app bundle and loops 100,000 requests with long prompts against the function overnight.
Why it matters
A provider bill in the thousands, a suspended API account, or your email domain blocklisted for spam.
How to fix it
- Require a user: `const { data: { user } } = await supabase.auth.getUser(token); if (!user) return new Response('unauthorized', { status: 401 });`.
- Count use per user per day and return 429 above the limit.
- Cap max_tokens and set a hard spend limit at the provider.
Does your app have this?
PTKD checks your build or your source project for PTKD-BACKEND-SUPABASE-EDGE-OPEN-PROXY 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