Guide: secret keys
Supabase service role key exposed: what the check shows and what to rotate
When the check finds a Supabase service role key written in your code, it reports “Your database's master key (Supabase service role) is written in your code”, as a high finding. That key skips every row-level rule: whoever has it can read and change everything. The key must be replaced, in Supabase, under Project Settings → API.
Last updated
What the check shows
- The finding. “Your database's master key (Supabase service role) is written in your code”, with the file and the line. Newer secret keys that start with sb_secret_ are reported as “Your database's secret key (Supabase)”.
- Why it matters. Anyone who can see your code can use it. It skips every row-level rule: whoever has it can read and change everything.
- What it never does. The check never tries a key and never keeps one. A finding carries the kind of key and the file, not the key.
- A key meant to be public. A public key is not reported. Supabase's local demo key is told apart and read as low, with its own advice.
What to do
- 1. Move it out of the code. Into a secret setting. The fix does this on a copy and waits for your yes.
- 2. Replace the key. The key has been seen, so it must be replaced, and only you can do that: in Supabase, under Project Settings → API (for an sb_secret_ key, under Project Settings → API Keys).
What the study found
Of 200 public AI-built apps the study read, 5 had a string with the shape of a Supabase service role key in a file that is not a test or an example (read on 28 October 2026). A string with a key's shape is not proof that the key works.