04.6.6 · Skill in Security and privacy engineering

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.

Your status · Secrets management

Saved in this browser. Sign in to keep it on every device.It colours this skill's tile on your map.

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

  1. Keep secrets out of code, prompts and logs. Load them from a secrets manager or the environment, and keep .env files out of git.
  2. Give each service its own key, with the smallest scope that works: read-only when it only reads.
  3. Prefer short-lived tokens. Rotate long-lived keys on a schedule, and when someone leaves.
  4. Store the tokens you issue only as hashes, like passwords.
  5. Scan commits, CI logs and chat for secrets, and block pushes that contain one.
  6. 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.

Numbers

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

Tools

1