Stop 23 of 42 · The Vault · Secrets in git history

The vault key in the old filing cabinet

A teller once photocopied the vault key and stapled it into the bank’s binder. Later she noticed and pulled the page out. But the binder keeps every old version in a filing cabinet, and the vault lock was never changed. The key is gone from today’s page, not from the bank’s memory.

Severity Critical–HighCategory Exposed SecretsThe VaultSources checked 25 Oct 2026

Watch it happen

Play it as

A vault key is committed, then deleted from the current code. Mallory finds it in old history and the unchanged lock still opens.

Arrival

Alice walks in with the bank’s vault key (an API key, a database URL, a service-role key) for the teller to use.

1 / 5

In bank terms and app terms

In the bankIn your app
Vault key copyAn API key, database URL, service-role key or private key
BinderThe files in your repo today
Old filing cabinetGit history: every previous commit
Changing the lockRotating or revoking the secret at the provider

Are you exposed?

You might be exposed if…
  • A .env, .pem or credentials file was ever committed, even if you deleted it afterwards.
  • You pasted a key into code “temporarily” (Stripe, OpenAI, AWS, Supabase service role) and later removed it.
  • Your repo is public, or has been shared with contractors or CI tools you do not fully control.
What to do about it
  1. Revoke and rotate any secret that was ever committed. Deleting it from code is not enough.
  2. Keep secrets in environment variables or a secret manager, and add .env* to .gitignore.
  3. Add a pre-commit or CI secret scanner (for example gitleaks), and optionally purge history with git filter-repo after rotating (rewriting history alone is not enough once pushed, since forks and clones keep copies).

Track these in your to-do list →

It has happened to real companies

Real-world breaches

Uber (2016) — Intruders used an access key that an Uber engineer had posted on a code-sharing website to reach Uber's cloud storage; Uber said about 57 million users' data was accessed. Uber paid the intruders $100,000 through its bug bounty program and did not disclose the breach until November 2017.

Samsung (2019) — A security researcher found that Samsung's SmartThings developers had left source code, secret keys and AWS credentials in publicly accessible GitLab projects.

What it looks like in code

// BAD: Hardcoded secret in source code
const STRIPE_SECRET = "sk_live_51abc123def456..."

// BAD: Committed .env file
// .env
SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIs...
DATABASE_URL=postgresql://user:p@ssw0rd@db.example.com/prod

// BAD: "Removed" secret (still in git history)
// git log shows: commit abc123 "add config" → commit def456 "remove secrets"
// The secret is still accessible via: git show abc123:.env

Ask your AI tool to fix it

Paste this into Cursor, Claude, Lovable, Bolt or whatever you build with.

Prompt
Check my repo and its git history for committed secrets (.env files, API keys, tokens, database URLs, private keys). List what you find and which provider each belongs to so I can rotate it. Then move all secrets to environment variables, add .env* to .gitignore, provide an .env.example with placeholder values, and add a gitleaks pre-commit hook.

Where this comes from

The facts, figures and fixes on this page were checked against these sources on 25 Oct 2026. They are linked so you can check for yourself.

Spot a mistake or something out of date? Report a correction · How these guides are made and checked

Go deeper in isitsecure

The free, open-source scanner checks for most of the problems in these guides.