I shared a secret key by mistake. What do I do now?
Make a new key and turn off the old one in that service’s settings, then put the new key in .env and your host’s settings. Deleting the key from a file doesn’t turn it off.
Find your situation
- If it was a Stripe secret key (sk_) or restricted key (rk_)
- On the API keys page, open the menu (⋯) next to the key and choose Rotate key. Set Expiration to Now, so the old key stops at once. A later time keeps the old key working until then. Copy and save the new key straight away.
- If it was a Supabase secret key (sb_secret_) or the older service_role key
- In Settings, then API Keys, create a new secret key and put it everywhere the old one was. Then delete the leaked key. For a service_role key, switch your app to the publishable key first, because turning off the old keys turns off the anon key too. Then revoke the old JWT secret.
- If it was a Clerk secret key (sk_test_ or sk_live_)
- On the API keys page, choose Add new key under Secret keys. Update CLERK_SECRET_KEY in .env and on your host, put your site online again, and check the new key shows recent use. Then delete the old one. Development and Production have separate keys, so rotate the one that leaked.
- If it was a key for another service, like OpenAI
- Open that service’s API keys page, create a new key, and revoke or delete the old one. Then check its usage page for spending you don’t recognize. OpenAI says to rotate a leaked key immediately and review your usage.
- If it was a publishable key (pk_ or sb_publishable_) or the apiKey in your Firebase config
- Nothing to do. These are made to be seen. Clerk says a leaked publishable key doesn’t need rotating, and Stripe won’t even let you expire one.
- If it went to GitHub in a commit
- Rotate the key first. GitHub says cleaning the history is often unnecessary once the old key is turned off. Then ask your AI tool to move secrets into .env and to stop Git tracking .env, because adding it to .gitignore doesn’t remove a file Git already tracks.
- If GitHub blocked your push because it found a secret
- Remove the secret from the commits it lists, then push again. If you bypassed the block or shared the secret elsewhere, rotate it.
Who does what
You
- Sign in to the service and rotate or delete the leaked key.
- Paste the new key into .env and your host’s settings, then put your site online again.
- Check the service’s usage or request logs for activity you don’t recognize.
- Decide, with your AI tool’s advice, whether your Git history needs cleaning.
Your AI tool
- Tell you what type a key is from the first letters of its name, and treat it as secret if that’s unclear.
- Find every file and saved commit that holds the key, and list them without printing it.
- Change the code to read the key from .env by name.
- Remove the key from your Git history, if you decide to.
- Restart your product and test that the new key works.
Hand this to your AI tool
One of my secret keys was exposed by mistake. I’ll make the new key and turn off the old one myself in the service’s dashboard. 1. Ask me which service the key is for and where it was exposed. Using that service’s current official docs, give me the exact steps to rotate it. 2. Search this product’s files and its saved Git history for keys that start with that service’s prefix, like sk_live_. Report only file names and commits. Never print a key. 3. If a key is written into any code, change the code to read it from .env by name. 4. Remind me to update the key in my host’s settings and put my site online again. 5. Explain whether removing it from my Git history is worth it. Don’t rewrite history or force-push unless I say yes. This comes from https://buildladder.com/answers/leaked-key. If you can open web pages, read https://buildladder.com/answers/leaked-key.md for the current version. BuildLadder guide, tool, concept, answer and setup pages all work this way: add .md to the address. Ask me before you install anything, sign in to anything or spend money. Never ask me to paste a password or secret key into this chat.
Where to go next
Updated Sources: Stripe API keys, Stripe: managing secret keys, Supabase: rotate a leaked key, Clerk: rotate your API keys, OpenAI: API key safety, GitHub secret scanning, GitHub push protection for users, GitHub: removing sensitive data, Git: gitignore.