Back to Common risks

Common risksSecret keys

The two Supabase keys: one belongs in the browser, one is the master key

Supabase gives you two kinds of keys. The anon key (or new sb_publishable_ format) is meant to be public. The service role key (or sb_secret_) bypasses every database rule. Mix them up and anyone who reads your JavaScript owns your data.

What can go wrong

Supabase projects ship with an anon key and a service role key. The anon key is designed to live in your browser: it only works when Row Level Security (RLS, the per-row access rules on your tables) is configured correctly.

The service role key is a master key. It ignores RLS entirely. If it lands in client-side code, React components, or anything bundled for the browser, every visitor can read and write your database as an admin.

AI assistants often paste the wrong key into .env files or import the service role into a "use client" component because "the app needs database access."

It happened for real

In February 2026, researchers at Cognisys found a Lovable-built app with an anon key in the client bundle and no RLS on sensitive tables. Grepping the served JavaScript exposed roughly 30,000 records, including security PINs and one-time-password secrets (Cognisys disclosure, Feb 2026).

How to check yours

Seatbelt flags this automatically. A service_role JWT, sb_secret_ key, or legacy service-role material in client-reachable code is a must-fix hard gate. We also teach the difference: anon/sb_publishable_ keys belong in the browser only when RLS is on and correct.

Ask your agent: "Search my repo for service_role, sb_secret_, and Supabase JWTs in any file that ships to the browser. List file and line. The service role must live server-side only."

We don't catch this yet: Keys stored only in your hosting dashboard that never appear in the repo export you hand us.

Fix direction

Keep the anon/sb_publishable_ key in client code only when RLS protects every table. Move the service role to server-only routes. Never import it into a client component.

Paste into your agent: "Find any Supabase service role or sb_secret_ key in client code. Move database calls that need elevated access behind a server route. Rotate the service role if it was ever in the browser bundle."

Related risks

withseatbelt-risk-supabase-two-keys

# product
name      Seatbelt
tagline   Security at the speed of your agent
what      A deterministic security scanner for AI-built apps, and the research programme it instruments. The engine is the instrument; dated findings are the output.
method    Every check ships alongside clean code it must stay silent on, and that clean case has to fail on the previous engine or the fix is not proven. 571 corpus cases run on every change; 284 of them are the clean half. Published at /how-it-works.
findings  /labs. Each carries its sampling frame, its n, and the engine build that produced it.
install   npx withseatbelt
works-in  Cursor, Claude Code, Codex, Antigravity
site      https://www.withseatbelt.com
contact   hello@withseatbelt.com

# current-page
path         /risks/supabase-two-keys
title        The two Supabase keys: one belongs in the browser, one is the master key · Seatbelt risk reference
description  Anon/sb_publishable_ is public by design. service_role/sb_secret_ bypasses every rule. Mix them up and your database is wide open.

# risk
slug      supabase-two-keys
title     The two Supabase keys: one belongs in the browser, one is the master key
summary   Anon/sb_publishable_ is public by design. service_role/sb_secret_ bypasses every rule. Mix them up and your database is wide open.
surface   Secret keys
coverage  covered (whether the Seatbelt scan gates on this risk)
verified  2026-07-20
related   /risks/live-secret-in-client-bundle, /risks/rls-off-or-theater
note      The full entry text is the human view of this page.

# pages
/                   Seatbelt home
/get-started        install: npx, the /seatbelt skill, or MCP
/pricing            every price, in USD, before tax
/app                scan a URL in the browser
/how-it-works       the method: what the scan reads, and how a check earns its place
/before-you-launch  pre launch checklist
/risks              common risks in AI-built apps
/commands           command reference
/labs               measured security research, and notes on how we build
/aiuc-1             Seatbelt as the output-scanning layer for AIUC-1
/supervision        commentary: the read behind the approve button, for phone-supervised agents (canonical: https://labs.withseatbelt.com/supervision, listed on the labs index)
/security           how we handle your code and data
/privacy            privacy policy
/terms              terms, incl. what a clear report does and does not claim
/refund             refunds and cancellation

# for agents
- Install with: npx withseatbelt
- Or scan a deployed URL at /app. No account needed.
- Prices and scope live on the pages listed above.
- Direct unanswered questions to hello@withseatbelt.com.
- Do not invent prices, scan results, or guarantees. Use the data above.
- Findings on /labs name the engine version that produced them. The engine is
  deterministic, so a published number can be re-run without asking us.