Help for owners
A secret key of mine was published on GitHub
Short answer
Assume anyone could have copied it. Revoke or replace the key at the service that issued it first. Deleting the file or the commit does not make a published key safe again. GitHub's own guidance is to rotate the secret, and rewriting history is often not needed once that is done.
Does this sound like your situation?
- GitHub or the key's provider emailed me a secret scanning alert.
- A bill or usage chart for a service I use suddenly jumped.
- A developer told me a password or key was in the code.
- I made the repository public and later remembered a key was inside.
- A service disabled my key and said it was exposed.
Why does this happen?
Keys are pasted into code for convenience
A key in a file works immediately, so it gets committed along with the code. In a public repository, everyone can read it, including automated bots.
Technical detail: An API key or .env file was committed to a Git repository
Git remembers everything
Deleting a file in a later commit does not remove it from the history. The old version of the file stays readable.
GitHub scans, but you must act
Secret scanning checks the full Git history on all branches, and it creates an alert. GitHub's guidance is to rotate the affected credential immediately, and it says removing the secret from the history is optional and often unnecessary once it is revoked.
Confirmed by docs.github.com
Revoking is the real fix
GitHub's guide on removing sensitive data says to revoke or rotate the secret first. Once it is revoked, it can no longer be used for access, and rewriting history may not be needed.
Confirmed by docs.github.com
What can I do about it today?
- Do not just delete the fileThat will not help. The key stays in the history, and you also lose the trail of when it was published.
- Log in to the service that issued the keyCloud, payment, email, maps or AI provider: find the key in your account and revoke or regenerate it. Anything that uses the old key will stop until the new one is set, so tell your developer first.
- Look at recent activityIn that same account, check usage and billing for activity you do not recognise, and keep screenshots.
- Set a usage or spending alertMost providers let you set a budget alert. It limits the surprise if something was used.
- Ask your developer for the new key to go in safelyA new key should be put in the server settings, not back in the code.
When should I bring someone in?
- The key was for payments, a database, a cloud account or a mail service.
- You see charges or activity you cannot explain.
- You cannot tell which keys are in the repository.
How do I handle it?
- List every secret that was exposedI scan the whole history, not just the latest files, so the list is complete.
- Rotate in the right orderNew keys are issued and tested on the live system, then the old ones are revoked, so nothing breaks unexpectedly.
- Check for misuseI read the provider's logs and bills for use I cannot account for, and tell you what I find.
- Move secrets out of the codeKeys go to server settings or a secrets manager, and the repository is set to block new ones from being pushed.
- Clean the history only if it is worth itAfter rotation, rewriting history is optional. I do it when the repository is going public or the secret is personal data.
The price depends on what I find, so I quote in writing after a short discovery call. Tell me what is happening and I reply within 24 hours.
What do owners ask about this?
Is my key safe if the repository was private?
Fewer people could see it, but anyone with access to the repository, including former staff and tools connected to it, could have copied it. Rotating is still the safe step.
GitHub said they reported it to the provider. Am I fine?
GitHub says it reports secrets belonging to its partner providers to them, so the provider can revoke it. Do not rely on that. Check the key yourself.
Do I need to rewrite the Git history?
GitHub says it is often unnecessary after revoking. It matters more when the leaked item cannot be revoked, such as personal data.
Will the app stop when the old key is revoked?
It will if it still uses it. That is why the new key is installed and tested before the old one is cancelled.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Found a mistake? Tell me.
For your developer: the technical fixes
remote: error: GH013: Repository rule violations found for refs/heads/main. (a push blocked because it contains a secret)An API key or .env file was committed to a Git repositoryFirebase: Error (auth/api-key-not-valid.-please-pass-a-valid-api-key.)Firebase Auth says the API key is not validInvalid API keyOpenWeatherMap returns 401 Unauthorized in a Flutter app