Skip to content
ScrubLogs

Guides

Leaked an API key? What to do in the first hour

Updated

If an API key ended up somewhere it shouldn’t (a public repository, a chat, a ticket, a screenshot, a forum post) treat it as compromised. Automated scanners watch public sites for keys around the clock, and leaked cloud and AI keys are often used within minutes.

The order matters: stop the key working first, investigate second. Investigating while the key still works gives an attacker more time.

1. Revoke or rotate the key now

Go to the provider’s dashboard and disable the key. Most providers let you create a replacement first and then delete the old one, but if the leak was public, delete it straight away and accept a few minutes of downtime.

Our secret type pages list the exact steps for the most common keys.

Deleting the message, commit or post where the key appeared is not enough. Copies may already exist in caches, notifications, search indexes and other people’s screens.

2. Replace it everywhere it was used

Create a new key and update every place that used the old one: servers, CI/CD secrets, serverless functions, local .env files and teammates’ machines. Search your infrastructure for the old key’s prefix or ID to find stragglers.

Give the new key only the permissions it needs. A leak is a good moment to replace a broad admin key with several narrow ones.

3. Check whether it was used

Look for activity between the moment the key leaked and the moment you revoked it:

If you find unauthorised activity, contact the provider’s support. Many will review fraudulent usage charges, and they can help you find what the attacker created.

4. Remove it from where it leaked

Now clean up: delete the message, edit the post, close the ticket, or rewrite the Git history (see secret committed to Git). This limits further exposure but doesn’t undo the leak, which is why it comes after rotation.

5. Tell the people who need to know

If the key belongs to your employer or a client, tell their security team now, even if you have already rotated it. They may need to check other systems, and many companies are required to log security incidents. If customer data may have been accessed, privacy law may require notifying a regulator within a short deadline (72 hours under the GDPR, for example), so involve your privacy or legal team early.

6. Make the next leak less likely

What these keys look like

More guides