Secrets management
Handling API keys, passwords and certificates safely.
Secrets belong in a secrets manager or environment configuration, never in code or logs. Rotation and limited scope reduce the damage when one leaks. Leaked keys in repositories are still one of the most common incidents.
Why it matters for a product engineer
An API key in a repository works for anyone who finds it. Products depend on more keys every year: payments, email, analytics, model providers, agents. Each new integration adds one. A product engineer who handles keys well limits what one leak can do, and can replace a key in minutes, not days.
How to do it
- Keep secrets out of code, prompts and logs. Load them from a secrets manager or the environment,
and keep
.envfiles out of git. - Give each service its own key, with the smallest scope that works: read-only when it only reads.
- Prefer short-lived tokens. Rotate long-lived keys on a schedule, and when someone leaves.
- Store the tokens you issue only as hashes, like passwords.
- Scan commits, CI logs and chat for secrets, and block pushes that contain one.
- When a key leaks, revoke it first, then clean the history. Deleting the commit is not enough.
Common mistakes
- Trusting a private repository. GitGuardian finds internal repositories about six times more likely to contain secrets than public ones.
- Keys in MCP and agent config files, copied from a quick start guide.
- One shared key for every environment and service.
- Secrets pasted into tickets and chat during an incident.
- Secrets in error messages or analytics events.
Example
This site gives tokens to the agents that people connect to their map. Each token is a random 256-bit string, stored only as a SHA-256 hash, so a copy of the database holds no working token. Access tokens last one hour. Refresh tokens last 60 days and change each time they are used. The analytics API key is read-only, and comes from the environment or an ignored file, never from the code.
Hardcoded secrets on public GitHub
- 29M
- New secrets in public commits in 2025
- 28.65 million, 34% more than 2024
- 2,117
- Valid credentials in MCP config files
- Of 24,008 unique secrets found there
- 64%
- Valid in 2022 and still active in Jan 2026
Leaks grow with every new kind of integration, and most leaked keys are never revoked. Rotation matters as much as prevention.
ReportedGitGuardian, The state of secrets sprawl 2026, 17 Mar 2026
Sources: The state of secrets sprawl 2026 (GitGuardian) ↗ · Secrets management cheat sheet (OWASP) ↗
Resources
1- docsGo deeper
Secrets management cheat sheet ↗
OWASP · 35 minKeeping keys and passwords out of code, rotating them, and giving each service only what it needs.
Tools
1- ToolOpen source
Infisical
Open-source secrets manager for syncing keys and credentials to apps and pipelines.