Skip to content
HARDEX

Guide

I leaked an API key: what to do, step by step

You found out that a key for a service you use is somewhere it should not be: in your code, in a repository, in a screenshot, in a chat, or in a page that visitors download. Do not panic. What matters is the order you do things in.

The steps are the same for almost every service. Do them in this order, and keep the old key until the new one works.

1Replace the key first

Deleting the key from the code does not make it safe. Anyone who saw it can still use it until it is switched off at the service. So the first step is to make the old key useless, not to hide it.

What to do: In the service's dashboard, create a new key, put it in your app, check that the app works, and then delete or revoke the old key. If the key is for payments, email or an AI service, do this now, before anything else on this list.

2Look at what the old key did

A key that was visible may have been used by someone else. The first sign is usually on the service's own pages: charges you do not recognise, messages you did not send, or data you did not read.

What to do: Open the usage, billing and activity pages of the service and look at the days since the key was exposed. If you see something you do not recognise, tell the service's support, change your passwords there, and set a spending limit if it offers one.

3Remove the copies

A key can sit in more places than the file where you found it. Version history keeps old versions of files, so a key that was ever saved is still there. A public repository can be read, and copied by automatic tools, within minutes. Making it private afterwards does not take back what was already copied.

What to do: Search your repository's history, your chat history with the AI tool, screenshots, shared documents and old deployments for the old key, and delete what you can. Do not rely on this alone: the key is only safe once it is switched off, which is the first step.

4Keep the new key out of sight

If the same thing happens again, the next key will be exposed the same way. A key should live in the one place meant for secrets and be used only by code that runs on a server.

What to do: Keep the key in your host's secret settings or in an environment variable that is not saved with the project, and use it only on a server. Give the key only the permissions it needs, and set a limit on what it can spend, where the service lets you.

Check them all from the outside

Hardex scans a live app the way a stranger on the internet would, with nothing to install. By default it only reads: it never changes anything in your app. It looks for the problems above where they apply to your app, and more, then reports what it found.

What each plan includes is on the plans page.

Scan your app