Secrets
The service role key is in the browser bundle
Cataloged October 16, 2026 · Lovable · Bolt · Cursor · Replit · v0 · Supabase
Symptom
Data API calls from the site ignore every row policy. Searching the shipped JavaScript turns up a secret or service role key.
Root cause
Supabase's securing-your-data guide says the publishable key and the older anon key are safe to expose only when RLS and least-privilege grants are in place. The secret key and the service role key bypass RLS and are never safe in the browser. Lovable's security best practices say secrets stored in frontend code are visible to users and should be considered compromised, and that the service role bypasses RLS so server code using it must check permissions itself.
Fix prompt
In this repository only, search client components, Vite env files, and NEXT_PUBLIC_ variables for service_role, sb_secret, SUPABASE_SERVICE_ROLE_KEY, and the secret key value. 1. Remove every client use of the secret or service role key. 2. Create the browser client with the publishable (or anon) key only. 3. Move privileged work into a server route or Edge Function that reads the secret from server env, and authorize the caller before using an admin client. 4. Rotate the leaked key in the Supabase dashboard after the code no longer references the old value. Do not print the key in logs or in chat.
Paste this into the coding tool that has your own project open.
2-minute self-check
These steps are for an app you own. Do not run them against someone else's project.
- Open a production build of your own site. In DevTools, search the loaded scripts for service_role and sb_secret. Those strings should not appear.
- Search your own repo for SUPABASE_SERVICE_ROLE_KEY and confirm it is referenced only from server files.
- If you find the secret in a shipped bundle, rotate it in your own Supabase API settings after the new deploy.
Common questions
Data API calls from the site ignore every row policy. What am I searching for?
Search the shipped JavaScript of your own site for service_role and sb_secret. Supabase says the publishable key and the older anon key are safe to expose only when RLS and least-privilege grants are in place. The secret key and the service role key bypass RLS and are never safe in the browser. If the string is in the bundle, rotate it in your own API settings after the new deploy.
Is a server function that uses the service role automatically safe?
No. Lovable's best practices say the service role bypasses RLS, so server code that uses it has to check permissions itself. The browser client should be created with the publishable or anon key only.
Longer guide
- Lovable blocked your publish: what each critical finding means and how to fix it
What the November 23 security-check redesign changed, when the workspace setting blocks every publish path, and how to read the finding on a project you own.
- Supabase email rate limit exceeded: what the Auth error means
What the message email rate limit exceeded means, which Auth limit returned the 429, and how to raise the cap on a project you own without turning off email confirmation.
- OpenAI API key exposed in the frontend: check your own app
Which keys are meant to be public, why a NEXT_PUBLIC_ or VITE_ prefix ships the others, and what to do on your own app if a secret key is in the bundle or the git history.
- Lovable Supabase data exposed: check RLS on your own app
What Crissy Field counted in 159,041 Lovable projects, why a public Supabase key is not the lock, and a 10-minute RLS check for an app you own.