What do I do if an API key is in my code?
Replace the key first. Deleting it from your code isn't enough, because it stays in your Git history and may already have been copied. Create a new key, turn off the old one, then keep secrets out of the code.
Do this now
- Create a new key and turn off the old one at the provider.
- Check the provider's logs and bill for use you don't recognize.
- Move the key to an environment variable or a secrets manager.
- Add
.envto.gitignore, and commit only a.env.examplewith no real values. - Scan your history with a tool such as
gitleaks --redactso values aren't printed. - Add a pre-commit check so it doesn't happen again.
Is a key in frontend code private?
No. Anything sent to the browser can be read by anyone. Keep private keys on your server and call the provider from there.
Check your whole codebase
Cyber mode reads your code, finds the holes and tells you what to fix first. You approve every fix. Use it only on code you own or may test, and review each change, because AI can miss issues.