Secrets Don't Leak in One Moment: The 6 Ways They Slip Into Your Repo (and How to Catch Each One)
Описание и применение
Секреты могут непреднамеренно попадать в публичные репозитории через .env, .env.example, исходный код, логи, историю git и скриншоты. Используя dotguard, корректируя .gitignore, добавляя хуки pre‑push и CI‑проверки, а также очищая историю, можно обнаружить и предотвратить утечки.
Задача
Secrets can be unintentionally committed to public repositories through various subtle practices, leading to prolonged exposure of credentials.
Результат
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.
Рабочий процесс
- 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.
Доказательства
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.
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.
git log --all -p -S "password"
- Дата записи: 2026-11-01T02:59:11.171Z