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

    1. Require a user: `const { data: { user } } = await supabase.auth.getUser(token); if (!user) return new Response('unauthorized', { status: 401 });`.
    2. Count use per user per day and return 429 above the limit.
    3. 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 app

    References

    Related checks (M3)