Skip to content
All rules

SB-SERVICE-ROLE-KEY

service_role or secret key exposed to the client

Severity
Critical
Confidence
High
Stack
Supabase
Runs
On by default

What the CLI looks for

A service_role JWT or an sb_secret_ key in client code, in a NEXT_PUBLIC_ or VITE_ variable, or in a committed .env file.

Why it matters

Anything in a NEXT_PUBLIC_ or VITE_ variable ends up in the browser bundle. A service_role key there gives every visitor full read and write access to your database, ignoring RLS.

How to fix it

Rotate the key in the Supabase dashboard first. Then keep it only in server-side environment variables (edge functions, API routes) and use the anon or publishable key in the browser.

# Server only: never prefixed with NEXT_PUBLIC_ or VITE_
SUPABASE_SERVICE_ROLE_KEY=...

# Safe in the browser
NEXT_PUBLIC_SUPABASE_ANON_KEY=...