Guide

You leaked an API key. Here is what to do in the next hour.

It happens to experienced engineers too. What matters is the order you act in. Deleting the key from your code feels like the fix, but the key is already out. Rotate first, clean up second.

Updated · 5 min read

1. Rotate the key now

Create a new key with the provider and revoke the old one. Once it is revoked, the leaked copy is useless, wherever it ended up. For payment and AI providers, use their dashboard's key management page. For Supabase, create a new secret key in the API keys settings; a leaked legacy service_role key is revoked by deactivating the legacy keys, after the frontend has moved to the publishable key.

2. Move the new key somewhere safe

Store it as a server-side environment variable on your host, never in a file in the repo and never in a variable with a public prefix. Calls that need it go through a server or edge function.

3. Check for damage

  • Payment provider: look for refunds, payouts or customers you do not recognise.
  • AI provider: check usage for spikes since the leak.
  • Supabase: look for changed or deleted rows and new users you did not expect.

4. Clean the history if you want to

Tools like git filter-repo can rewrite history to remove the key, but anyone who already cloned the repo keeps a copy. Rewriting is tidy; rotating is what actually protects you.

5. Find out how it happened

Usually a builder pasted the key to get past an error, or a variable got a public prefix. Tell your builder to read the key from a server-side environment variable, and scan again to make sure nothing else slipped in.

Common questions

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

Yes. Collaborators, connected tools and any future breach of the repo can all expose it. Rotation is quick and removes the doubt.

The checks behind this guide

Check your whole app in one go.

The Full Scan runs seven read-only checks and writes a fix prompt for every finding.

More guides