high · M3 · MASVS-AUTH-1 · PTKD-BACKEND-SUPABASE-SELF-UPGRADE

    Users can give themselves premium, credits or admin in Supabase

    A table has columns that decide what a user may do or has paid for (premium flag, plan, credits, role), and its Row Level Security lets each user insert or update their own row with no limit on those columns. RLS checks rows, not columns: the user calls supabase.from(...).update({ is_premium: true }) with their own session and the app unlocks everything. Hiding the button in the app does not stop the call.

    How it is exploited

    profiles has is_premium and credits, and the policy is `for update using (auth.uid() = id)`. In the app the Upgrade button opens the paywall, but a user with a proxy (or a few lines of JavaScript and the anon key) sends `supabase.from('profiles').update({ is_premium: true, credits: 999999 }).eq('id', myId)` and RLS lets it through.

    Why it matters

    Free premium for anyone who tries, unlimited credits for paid AI features, or admin rights when the column is a role.

    How to fix it

    1. Revoke table-wide writes and grant only harmless columns: `revoke update on public.profiles from authenticated; grant update (display_name, avatar_url) on public.profiles to authenticated;`.
    2. Do the same for insert, or set privileged columns with defaults and a trigger on insert.
    3. Write premium, plan and credits only from a webhook or Edge Function that verifies the purchase (RevenueCat, Stripe, App Store Server Notifications).

    migration

    revoke update on public.profiles from authenticated;
    grant update (display_name, avatar_url) on public.profiles to authenticated;
    -- is_premium and credits are written only by the purchase webhook (service role)

    Does your app have this?

    PTKD checks your build or your source project for PTKD-BACKEND-SUPABASE-SELF-UPGRADE and every other check in this knowledge base.

    Scan your app

    References

    Related checks (M3)