First, the uncomfortable rule
If a secret has been committed, assume it is compromised. Deleting the line, amending the commit or making the repository private does not undo the exposure. Rotate the credential first, then clean up the code. The order matters.
Where they hide
- Client bundles. Anything shipped to a browser is readable. An “internal” API key in a frontend build is a public key.
- Environment files.
.envis ignored in many projects, but.env.local,.env.productionor an example file sometimes is not. - Example and seed files. A realistic-looking demo key is still a key if it is live.
- Git history. Removing a file from the latest commit leaves it in earlier commits.
- CI logs and error reports. A request URL with a token in the query string can end up in logs you did not intend to keep.
- Generated code. An assistant may produce a plausible key, or reproduce one from the surrounding context.
The first ten minutes
- Identify the provider and scope. Is it a live payment key, a read-only token, a database password, a signing key? Scope decides urgency.
- Rotate or revoke it. Use the provider's dashboard. Do this before cleaning the repository.
- Check for use. Look at provider logs for unexpected calls, new users or unusual spend. If the key had write access, check what changed.
- Replace it with a secret reference. Move the value to your secret manager or environment configuration. Do not commit the replacement.
- Clean history if needed. If the repository is shared or public, rewriting history may be appropriate. Coordinate with the team; a force-push during someone's work is its own incident.
Test keys can still expose data, send email, or consume quota. Treat them as credentials, not decoration.
Prevention that actually sticks
- Short-lived credentials. Prefer tokens that expire and can be scoped narrowly over long-lived keys copied between machines.
- One place for secrets. A secret manager or platform environment settings, not a spreadsheet and a Slack thread.
- Scan before commit and in CI. A local hook catches the accident; a CI check catches the person who skipped the hook.
- Least privilege. A key that cannot delete data cannot delete data by accident.
- Log hygiene. Do not put tokens in URLs, and scrub sensitive fields from error reports.
What a review adds
Automated scanners are good at known formats. They are less good at context: a key that looks like a placeholder but is live, a token embedded in a build config, an environment variable that silently falls back to a committed default. A human review reads those paths and asks what the code does when the secret is missing.
Try the committed-secret scanner for a first pass. It redacts matches on screen and runs entirely in your browser.
Want this read for you?
Appmint reviews shipped apps, code and AI-generated features. Tell us what you're building and we'll suggest the smallest useful next step.
Start a review