First, treat the key as stolen. Bots scan public repositories within minutes. Revoke or rotate the key at the provider right away. Deleting the file in a new commit is not enough, because the key stays in the Git history. Cleaning history (with git filter-repo or BFG) is optional after rotation.
To avoid it next time:
Do not put secrets in code or committed config files. Keep them in environment variables or a separate file that is in .gitignore.
In .NET development, use User Secrets (dotnet user-secrets).
In production, use a secret store: Azure Key Vault, AWS Secrets Manager, HashiCorp Vault, or your CI system's secret variables.
Turn on secret scanning (GitHub has it) and consider a pre-commit hook such as gitleaks.
Give keys the least permissions and an expiry, so a leak does limited damage.
Commit a template such as .env.example with fake values, so teammates know what to configure.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
First, treat the key as stolen. Bots scan public repositories within minutes. Revoke or rotate the key at the provider right away. Deleting the file in a new commit is not enough, because the key stays in the Git history. Cleaning history (with git filter-repo or BFG) is optional after rotation.
To avoid it next time:
dotnet user-secrets).Commit a template such as
.env.examplewith fake values, so teammates know what to configure.