Dev.to Security 🔐 Cybersecurity 👁 0 📖 2 min read

Exposed Supabase key: 20-minute triage before you rotate (and why clean logs do not clear you)

A GitHub search result or a scanner just told you a Supabase key is in a public repo. The instinct is to rotate immediately — correct instinct. But spend 20 minutes on triage first, because “what could they do with it” h

A GitHub search result or a scanner just told you a Supabase key is in a public repo. The instinct is to rotate immediately — correct instinct. But spend 20 minutes on triage first, because “what could they do with it” has a very different answer for an anon key and for a service_role JWT, and “did anyone use it” is mostly unknowable.

First: which key did you actually expose

  • anon / NEXT_PUBLIC_SUPABASE_ANON_KEY — public by design, so its presence is not the leak. The question is what the role behind it can do: SELECT where anon has a grant plus a permissive policy, writes where WITH CHECK is missing or true, and RPC calls into SECURITY DEFINER functions.
  • service_role JWT (eyJ...) or sb_secret_... — privileged. RLS does not run for it. Anyone holding it can read, write and delete every row the role reaches through the same REST endpoint. Treat the whole database as read.
  • Paired config: the file that shipped the key usually shipped other settings too. Widen the scan to the file history, not just the line.

The checks that can show use (weaker than people expect)

API logs — filter the window from commit date to now for traffic that is not your app: script user agents, off-region IPs, tables your client never reads, and /auth/v1/admin calls. A service_role request carries no user context; the key appears on both apikey and Authorization.

Data and auth state — a SELECT leaves no row behind. Look for rows nobody wrote, users nobody created, objects in buckets you never upload to, unfamiliar auth.audit_log_entries, and unexpected select=* in pg_stat_statements if it is enabled.

Why clean logs are not a clearance: hosted retention is finite, the first probe is one ordinary-looking REST request, and a full read is not an event.

Rotation stays the answer

Rotate, confirm the old key returns 401, purge it from history where you can, search the same commit for paired secrets, add a pre-commit check. If the exposed key was privileged, also review what it could have reached during the exposure window — logs alone cannot reconstruct that.

After rotation: stop it drifting back

Rotating a key does not fix the policy that made the anon key dangerous in the first place. I run a small read-only nightly catalog diff — 10 checks over pg_class, pg_policies, pg_proc, pg_roles and information_schema, no application rows, no writes, no service_role required. The first run captures a baseline silently; later runs email only when the finding set changes. Fail-closed: if the query errors or the scanned-object set changes, the baseline is not overwritten. “0 findings” alone is never proof that anything was checked.

Free, no signup: https://kurtoglu1.gumroad.com/l/supabase-rls-drift-monitor-free

Honest limits: this is catalog drift, not an exploit test; 0 findings does not mean safe; hosted internals are not visible.

If you want a human on five specific tables within 24 hours, that is a fixed-scope $95 Spot Check: https://kurtoglu1.gumroad.com/l/supabase-rls-spot-check — work starts only after payment is secured.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.