Credentials đã push = credentials bị compromise. Rotate ngay lập tức — đây là ưu tiên số 1.
Bước 1: Rotate credentials (NGAY LẬP TỨC):
- API keys, DB passwords, JWT secrets → revoke và generate mới
- Không chờ xóa khỏi git — ai đó có thể đã crawl rồi
Bước 2: Xóa khỏi git history:
# Dùng git filter-repo (khuyến nghị, thay thế filter-branch):
pip install git-filter-repo
git filter-repo --path .env --invert-paths
# Hoặc BFG Repo Cleaner (nhanh hơn cho large repos):
java -jar bfg.jar --delete-files .env
git reflog expire --expire=now --all
git gc --prune=now --aggressive
git push --force --allBước 3: Thông báo team re-clone (sau force push, local repos của mọi người bị stale).
Bước 4: Thêm .env vào .gitignore:
echo ".env" >> .gitignore
echo ".env.local" >> .gitignore
git add .gitignore && git commit -m "chore: add .env to gitignore"Phòng tránh: pre-commit hook detect secrets (git-secrets, detect-secrets, Gitleaks).
GitHub secret scanning tự động notify nếu detect credentials trong push.
Credentials that have been pushed are compromised credentials. Rotate them immediately — this is the top priority.
Step 1: Rotate credentials (IMMEDIATELY):
- API keys, DB passwords, JWT secrets → revoke and generate new ones
- Do not wait to clean up git — someone may have already crawled it
Step 2: Remove from git history:
# Use git filter-repo (recommended, replaces filter-branch):
pip install git-filter-repo
git filter-repo --path .env --invert-paths
# Or BFG Repo Cleaner (faster for large repos):
java -jar bfg.jar --delete-files .env
git reflog expire --expire=now --all
git gc --prune=now --aggressive
git push --force --allStep 3: Notify the team to re-clone (after force push, everyone's local repos are stale).
Step 4: Add .env to .gitignore:
echo ".env" >> .gitignore
echo ".env.local" >> .gitignore
git add .gitignore && git commit -m "chore: add .env to gitignore"Prevention: pre-commit hooks to detect secrets (git-secrets, detect-secrets, Gitleaks).
GitHub secret scanning automatically notifies you when credentials are detected in a push.