Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Secrets Don't Leak in One Moment: The 6 Ways They Slip Into Your Repo (and How to Catch Each One)

Description and use

Secrets can unintentionally enter public repositories via .env, .env.example, source code, logs, git history, and screenshots. By employing dotguard, correcting .gitignore, adding pre‑push hooks and CI checks, and cleaning history, leaks can be detected and prevented.

Problem

Secrets can be unintentionally committed to public repositories through various subtle practices, leading to prolonged exposure of credentials.

Outcome

Adopting automated scanning, proper git ignore handling, and process discipline significantly reduces the risk of secret leaks and enables rapid response when a leak is detected.

Workflow

  • Identify common leak vectors (env files, examples, source, logs, history, screenshots).
  • Use git ls-files to check if .env is tracked; if so, run git rm --cached .env and clean history.
  • Install dotguard globally (npm i -g @wuchunjie/dotguard dotguard).
  • Run dotguard in the project root to scan for hardcoded secrets.
  • Add dotguard to CI pipeline (e.g., GitHub Actions) with a step: npx @wuchunjie/dotguard.
  • Set up a pre-push hook that runs dotguard and aborts the push if secrets are found.
  • When a secret is found, rotate it immediately, remove it from the working tree, clean history with BFG or git filter-repo, add patterns to scanner and .gitignore, and document exposure duration.

Evidence

Last year I found a production database password in one of my own public repos. Not a test password. Not a placeholder. The real one, in a config file, visible to anyone who knew how to read git history. It had been there for 8 months.

Source

dotguard scans config files, not just files named .env, so a .env.example with real values gets flagged the same way as the real thing.

Source

git log --all -p -S "password"

Source

  • Record date: 2026-11-01T02:59:11.171Z