Please treat this as an incident, today.
- Anything prefixed
NEXT_PUBLIC_is copied into the JavaScript every visitor downloads. Open your site, DevTools → Sources, search forservice_roleor the start of the key. It's there. - The service role key skips RLS completely. Anyone who has it can read, change and delete every row in every table, including your customers' orders.
Steps:
- Rename back to the anon/publishable key in the client.
- Rotate the service role key in Supabase (API settings). Assume it's been copied.
- Fix the actual RLS problem. For an insert error it's usually a missing
INSERTpolicy, e.g.
create policy "users insert own orders" on orders
for insert to authenticated
with check (user_id = auth.uid());- If you really need admin powers, use the service key only in server code (Route Handler / Server Action / Edge Function), in an env var without
NEXT_PUBLIC_.
Then check the Supabase logs for unusual requests since the day this was deployed.