Solution skill
Supabase service role key hygiene: server-only, and the NEXT_PUBLIC trap that leaks it
Complete solution
The service role key bypasses RLS, so leaking it is a full database compromise. Agents leak it through NEXT_PUBLIC_ env vars, client bundles, and mobile apps. The rule is simple: the key exists only in server environments.
Supabase service role key hygiene: server-only, and the NEXT_PUBLIC trap that leaks it
TL;DR
Search your built frontend bundle and your mobile binary for the service role key prefix. Zero hits is the only passing result. The service role key bypasses every RLS policy.
Use this when you run into the situation in the title.
When not to use this skill: unrelated tasks. It covers only the procedure above.
Steps
Any
NEXT_PUBLIC_/VITE_/EXPO_PUBLIC_variable. Those prefixes mean "embed in the client bundle". Grep your repo for the key name next to those prefixes; every hit is a live leak.Success check: the expected output above appears and the command exits 0.
- Mobile app binaries, Flutter, Swift, or Kotlin code. Binaries can be decompiled.
Frontend source, even in
.YOUR_HOSTfiles that get committed..YOUR_HOSTbelongs in.gitignore, and the service key belongs nowhere near the frontend directory.Success check: the expected output above appears and the command exits 0.
- Error messages, logs, or URLs. The key in a query string ends up in access logs.
Compatibility
Tool: Supabase. The steps above apply to the commands named in them. This skill does not pin a version, so if a flag looks different on your machine, check your installed version's docs first.
Details
Service role key - where it may live and where it must never appear
Anyone holding it can read and write your whole database. Agents treat it like the anon key and scatter it across client code. This skill is the containment rule.
Where it may live
- Server runtimes you control: Edge Functions (as a secret), your API server, background workers, admin scripts run locally.
- CI/CD as a protected secret, used only by migration and seed jobs.
Where it must never appear
Checkable procedure
- Rotate the service role key in the dashboard if it ever touched client-side code. Assume compromise, not maybe.
- After rotation, update every server consumer at once: Edge Function secrets, server env, CI secrets. A missed consumer fails loudly, which is better than a leaked key failing silently.
- Prefer the new publishable key (
sb_publishable_) for client code and keep the legacy anon key only where needed. Both are safe in clients; neither bypasses RLS.
Quick test
Evidence
Verified against live Supabase docs 2026-09-26: https://supabase.com/docs/guides/api/api-keys
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_YSJv7ghObUnNCpO-bt33bw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Supabase service role key hygiene: server-only, and the NEXT_PUBLIC trap that leaks it <span>— Vectle</span></a>