caelo

Caelo › Guides › Leaked an API key?

I leaked an API key or the Supabase service_role key. What do I do now?

By Arthi Arumugam, Irth Labs · Published · Updated

Short answerRotate the key at the provider right now: revoke the leaked key and issue a new one. Deleting the file or the commit is not enough, because the key may already have been copied, and it stays in git history and forks. After rotating: put the new key only in server-side environment variables, check the provider's usage and logs for activity you do not recognise, then remove the old key from your repository history.

First 15 minutes

  1. Revoke and replace the key at the provider. Do this before anything else. For Supabase, create a new secret key under Settings, API Keys, move your server to it, then deactivate the legacy keys. Deactivating turns off the legacy anon key as well, so move the frontend to a publishable key first, and for a leaked service_role key also revoke the legacy JWT secret; for Stripe, use Rotate key on the API keys page and choose the expiry Now, so the old key stops working at once; for OpenAI and similar, delete the key and create a new one.
  2. Put the new key in your hosting provider's server-side environment variables. Never in a variable your framework sends to the browser (for example names starting NEXT_PUBLIC_ or VITE_).
  3. Redeploy, and confirm the app works with the new key.
  4. Check usage: billing spikes, unknown API calls, new database rows or users, changed records, and auth logs.

Why is deleting the commit not enough?

Treat any key pushed to a public repository as compromised. Rewriting history removes it from your repo, but not from forks, clones or anyone who already took it. Rotation is the only real fix; history cleanup is tidying up afterwards.

This is common. A security firm's passive scan of over 5,600 public vibe-coded apps found 400+ exposed secrets and 175 cases of exposed personal data.

If it was the Supabase service_role key

This is the most serious case, because the service_role key ignores every row level security rule: anyone holding it can read, change or delete any row. Rotate it, then review your tables for changes you did not make, and check your auth users list for accounts you do not recognise.

Then find out how it got there. It is usually one of three places: a frontend environment variable, a script or migration committed to the repo, or an automation export (for example workflow files) saved into the repository.

Stop it happening again

  • Keep .env files out of git, and commit only an .env.example with placeholder values.
  • Check secret scanning and push protection on GitHub. Both run for free on public repositories. Private repositories need an organization on GitHub Team or Enterprise with Secret Protection.
  • Search your built site's JavaScript for words like secret and sk_live, and for the service_role key, before each launch.
  • Or have it checked: the Irth Labs App Health Check ($490) looks for exposed keys in code and in the browser, and the free Caelo check (npx caelo .) scans the files on your machine for the key formats on its list.

1. Run the free local check

npx caelo .

Caelo is a free, open source (MIT) command line tool and MCP server from Irth Labs that checks the files of an AI-built app for exposed API keys, Supabase and Firebase misconfigurations and .env files with real values. It runs on your machine, uploads nothing and uses no AI model. Each finding comes with a plain-English fix.

2. Act on a finding

Follow the fix in your report and run Caelo again. If Git could commit an untracked file containing secrets, preview a US$19 quick fix for that file.

For findings that need an engineer, Irth Labs offers a US$490 App Health Check. You receive a written report within 48 hours and a fixed repair quote. The fee counts toward the repair if you proceed.

Book the App Health Check See repair services

Questions

My repo is private. Do I still need to rotate?

If the key was only ever in a private repo with trusted collaborators, the risk is lower, but rotate anyway if the repo was ever public, shared, or pushed to a third-party tool.

Is the Supabase anon key a leak?

No, the anon or publishable key is designed to be public. It is only dangerous when your row level security rules are missing or too loose.

Will removing it from git history fix it?

No. It removes the key from your repository, not from copies already made. Rotate first, then clean history.

Sources