Supabase security · 8 minute read
What an exposed Supabase key actually grants — and how to tell whether it was used
A GitHub search surfaced a key from your public repository and someone told you about it — or you found it yourself. The instinct is to rotate immediately, and that instinct is right. But the hour before rotation is worth spending on the threat assessment, because the answer to "what could they actually do with it" is different for every key type, and the answer to "can I tell whether they did" is mostly no. This article lays out both, with the checks that show what the key granted and the reasons rotation stays the correct move even when every check comes back clean.
How exposed keys are actually found
Nothing exotic is required. GitHub code search is a public search engine over every repository, and the queries that surface credentials are simple text patterns: filename:.env, extension:env, filenames like .envrc or appsettings.json, and — for browser projects — the framework prefixes that ship keys into client bundles by design: NEXT_PUBLIC_, VITE_, EXPO_PUBLIC_. Anything that matches a JWT shape (eyJ...) or a known key prefix gets opened, checked whether it still answers, and only then is anyone contacted.
Two observations from running that search-and-verify process over a week of public repositories, stated as plainly as I can put them. First, keys stay live for a long time: every key verified as readable on day one was still answering identical read requests days later at follow-up, because nobody had rotated in between. Second, the verification itself is invisible to the owner: the probe is one ordinary-looking REST request, indistinguishable from app traffic in most logs.
That is the honest shape of the threat: the finding step is free, repeatable, and silent. Assume the window between commit and rotation is the exposure window, and that whatever you can find, someone less careful was also able to.
What each key type actually grants
The anon key: not a secret, and that is not the point
The anonkey ships in every browser bundle by design — it is public, and treating its presence as "the leak" is a category error. The question is what the role behind it can do. A REST request with the anon key is an unauthenticated request: it reads every table where the anon role holds SELECT and a policy allows it, writes wherever an INSERT/UPDATE policy with a missing or trivially-true WITH CHECK lets it, and reaches SECURITY DEFINER functions exposed as RPC endpoints. So an exposed anon key is only as dangerous as your policy set — which is exactly why the finding that matters is not "a key is in the repo" but "this policy combination is open".
The four access paths a single anon read cannot see — authenticated cross-user reads, writes, definer functions, storage — are catalogued in what a free anon-key check can and cannot prove.
The service_role key: RLS does not apply, at all
The service_role JWT is the one to take seriously. It is a server-side key that authenticates as a privileged role, and row-level security does not filter it — policies do not run for it. Anyone holding it can read, write and delete every row in every table the role can reach, through the same public REST endpoint your app uses, with a request that looks like this:
curl -s "$URL/rest/v1/<table>?select=*" \
-H "apikey: <service_role key>" \
-H "Authorization: Bearer <service_role key>"A 200with a JSON array is the proof that the key was live when it was tried. There is no "maybe" — that response is a full-table read without a login. The same key also signs admin API calls (creating users, reading auth data) depending on where it is used. If the exposed key is a service_role JWT, treat the entire database as read: every table, every column, every historical row.
The newer secret key format (the sb_secret_ family introduced for server-side use) sits in the same tier: it authenticates privileged access and bypasses policies the same way. Same response shape, same verdict.
The paired secret: what the exposure says about the rest of the repo
A privileged key in a public file is rarely the only thing in that file. The commit that shipped it usually also shipped other configuration — database passwords, payment test keys, cloud tokens. The scan that found the key should be widened over the same file history, because the exposure surface is the file, not the line. The seven leak surfaces list is the census I run for that.
How to tell whether the key was already used
Nothing about "the key is public" tells you whether anyone picked it up. The signals live in the logs and in the data itself, and they are weaker than people expect — which is exactly why the answer to a clean-looking audit is still "rotate".
API logs: who called, from where, with what
In the dashboard logs (API → PostgREST, and Auth), filter the window between the commit date and now for requests that do not match your application: source IPs outside your users' regions, user-agents that are scripts rather than browsers (curl, python-requests, HTTP libraries), and table access your app never reads from the client. A service_role key shows up in this log the same way it shows up anywhere — no Authorization user context, just the key on both headers, and requests to /auth/v1/admin routes (listing users, creating users) that a browser client can never legitimately make.
Data and auth state: what a reader leaves behind
A full read usually leaves no trace at all — a SELECT is not an event. What is observable: rows that appeared without your app writing them, auth users you did not create, storage objects in buckets you do not own uploads in, and entries in auth.audit_log_entries with actions or IPs you do not recognise. If pg_stat_statements is enabled, queries that ran through the REST endpoint appear there too — that is where an unexpected select=* on an admin-shaped table surfaces.
Why "nothing in the logs" is not an answer
Three reasons, in order of how often they bite: hosted log retention is bounded (the window between push and discovery is usually longer than the window logs cover for a busy project); a single quiet read — one 200with a JSON array — leaves no pattern to notice; and forks, archives and caches keep copies of the blob alive long after the repo is cleaned, so "I deleted the commit" closes nothing. The key was live for the whole exposure window whether or not anyone used it, and you cannot prove absence.
Why rotation is the answer even when everything looks clean
Rotation is the only step that makes the public value worthless regardless of what happened. The sequence, end to end: rotate the JWT secret in Project Settings → API (this invalidates the anon key too, so the redeploy ships in the same change) → confirm the old key now fails — a read with the old key must return 401, never 200 → purge the file from history (git filter-repo or BFG, then force-push and delete forks that were already cloned) → enable pre-commit secret scanning so the next paste fails before push → run the paired-secret scan from the leak-surfaces census.
Two failure modes are common at the rotation step itself: rotating and verifying with the new key (which proves nothing about the old one — the expected result is the OLD key failing), and rotating the secret without redeploying the app, which takes your own frontend down while the attacker loses nothing. The $29 self-run audit kit contains the full rotate→verify→purge runbook with the exact commands and the evidence file to keep. If you would rather have the verification run with evidence per step — old-key probe, policy census, effective-holder grant check — the fixed-price review runs in 48 hours.
The one-line version
A public key is a live key until you rotate it: the anon key exposes exactly what its table grants allow — often everything — and the service_role key exposes the whole database with policies bypassed. Whether it was used is unprovable, because a read leaves no trace; rotate, verify the old key fails, purge history, and scan for its pair.