/* Route-Critical (index, V6 §3.6.3 — erzeugt von tools/generate_critical_css.mjs) */ .collapse:not(.show){display:none}.navbar{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between}.navbar>.container-fluid{display:flex;flex-wrap:inherit;align-items:center;justify-content:space-between}.mydraft-svg-icon{display:inline-block;vertical-align:middle;color:currentcolor;flex-shrink:0;transition:color var(--duration-fast, 150ms) ease,stroke var(--duration-fast, 150ms) ease,fill var(--duration-fast, 150ms) ease}.mydraft-svg-icon circle,.mydraft-svg-icon line,.mydraft-svg-icon path,.mydraft-svg-icon polygon,.mydraft-svg-icon polyline,.mydraft-svg-icon rect{transition:stroke var(--duration-fast, 150ms) ease,fill var(--duration-fast, 150ms) ease}@layer components{.live-pulse-dot{width:8px;height:8px}}.min-w-0{min-width:0}@layer overrides{.live-radar-header-badge{background:rgba(239,68,68,.12);border:1px solid rgba(239,68,68,.35);color:#fca5a5;font-size:.75rem;font-weight:700;transition:.25s;cursor:pointer}}@layer overrides{.live-pulse-dot{width:8px;height:8px;background-color:var(--threat-critical,#ef4444);border-radius:50%;display:inline-block;box-shadow:rgba(239,68,68,.7) 0 0 0 0}}@layer overrides{body.light .live-radar-header-badge,html[data-bs-theme=light] .live-radar-header-badge{background:#fbd9dd;border-color:#eeb2b8;color:#8a1723!important}}.isharestuff-live-ticker{color:var(--color-text-body,#f8fafc);backdrop-filter:none;flex-wrap:wrap;row-gap:.3rem;background:var(--color-surface,rgba(15,23,42,.85))!important;border:1px solid var(--color-border,rgba(255,255,255,.12))!important;padding:.45rem .5rem!important;margin-bottom:.75rem!important}.ticker-content{mask-image:linear-gradient(to right,transparent 0px,rgb(0,0,0) 14px,rgb(0,0,0) calc(100% - 14px),transparent 100%);touch-action:pan-y;cursor:grab;user-select:none;-webkit-tap-highlight-color:transparent;order:1;width:100%;max-width:100%;flex:0 0 100%!important}.isharestuff-live-ticker .ticker-lead-group{order:2;width:100%;justify-content:space-between;margin-right:0!important}.ticker-track{display:flex;align-items:center;white-space:nowrap;will-change:transform;transform:translate3d(0,0,0);--ticker-speed:1;animation-name:isharestuffTicker;animation-timing-function:linear;animation-iteration-count:infinite;animation-duration:calc(26s / var(--ticker-speed, 1))}.ticker-link{max-width:min(78vw,340px);font-size:.82rem;display:inline-block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;vertical-align:baseline;transition:color .2s;color:var(--color-text-heading,#f8fafc)!important}.isharestuff-live-ticker .ticker-ctrl-btn{min-width:44px;height:44px;font-size:.78rem;-webkit-tap-highlight-color:transparent}.ticker-controls-bar{gap:.4rem}.ticker-counter{font-family:var(--bs-font-monospace, ui-monospace, monospace);font-size:.72rem;line-height:1;color:var(--color-text-secondary,#94a3b8);min-width:3.4em;text-align:center;user-select:none;white-space:nowrap;margin-left:auto}.ticker-item{font-size:.82rem}.ticker-item .ticker-date{font-size:.72rem;vertical-align:baseline}.ticker-text-group{display:inline-flex;align-items:baseline}.ticker-badge-live-btn{border:0;cursor:pointer;text-decoration:none!important}.ticker-badge{font-size:.78rem!important;min-height:44px!important;min-width:44px!important;padding:6px 12px!important;display:inline-flex!important;align-items:center!important;justify-content:center!important}@media (min-width:992px){.navbar-expand-lg{flex-wrap:nowrap;justify-content:flex-start}.navbar-expand-lg .navbar-toggler{display:none}}@media (prefers-reduced-motion:reduce){@layer overrides{#news-popup,#news-toast-banner,.animate-pulse,.live-pulse-dot,.live-pulsing-dot,.news-item-card{animation:none;transition:none}}.ticker-track{animation:none!important}.ticker-content{cursor:default}}@media (min-width:768px){.isharestuff-live-ticker{flex-wrap:nowrap;row-gap:0;backdrop-filter:blur(12px);padding:.5rem!important;margin-bottom:1rem!important}.isharestuff-live-ticker .ticker-content{order:0;width:auto;max-width:none;flex:1 1 auto!important}.isharestuff-live-ticker .ticker-lead-group{order:0;width:auto;justify-content:flex-start;margin-right:1rem!important}.ticker-controls-bar{gap:.3rem}.isharestuff-live-ticker .ticker-ctrl-btn{min-width:30px;height:auto;font-size:inherit}.ticker-counter{font-size:.66rem;margin-left:0}.ticker-track{animation-duration:calc(40s / var(--ticker-speed, 1))}.ticker-link{max-width:340px;font-size:.85rem}.ticker-item{font-size:.85rem}.ticker-badge{font-size:inherit!important;min-height:0!important;min-width:0!important;padding:.5rem 1rem!important}}@media (max-width:359.98px){.ticker-counter{display:none}.ticker-controls-bar{gap:.3rem}.ticker-badge{padding:6px 9px!important}} 🔒 Removing API Keys from Git History: BFG + Force Push (A Security Incident Response) | Sichere Programmierung – TSECURITY.DE Zum Hauptinhalt springen
•
Sichere ProgrammierungDesign a CDN: the content delivery network system design walkthrough(19.10.2026 um 05:42 Uhr)
•••
Sichere ProgrammierungPSEC-99: A 3D Browser Game in C# and WASM, Without WebGL(19.10.2026 um 05:46 Uhr)
••
Sichere ProgrammierungDesign a failure test from what the user must never see(19.10.2026 um 05:47 Uhr)
•
Sichere ProgrammierungFind Departments with an Average Salary Above the Company Average(19.10.2026 um 05:47 Uhr)
•
Sichere ProgrammierungDesign a web search engine: the system design interview walkthrough(19.10.2026 um 05:47 Uhr)
•••
Sichere ProgrammierungDesign a CDN: the content delivery network system design walkthrough(19.10.2026 um 05:42 Uhr)
•••
Sichere ProgrammierungPSEC-99: A 3D Browser Game in C# and WASM, Without WebGL(19.10.2026 um 05:46 Uhr)
••
Sichere ProgrammierungDesign a failure test from what the user must never see(19.10.2026 um 05:47 Uhr)
•
Sichere ProgrammierungFind Departments with an Average Salary Above the Company Average(19.10.2026 um 05:47 Uhr)
•
Sichere ProgrammierungDesign a web search engine: the system design interview walkthrough(19.10.2026 um 05:47 Uhr)
••
Intelligence View
⚡ tsecurity.de Intelligence

Removing API Keys from Git History: BFG + Force Push (A Security Incident Response)

Removing API Keys from Git History: BFG + Force Push (A Security Incident Response) Published on: 2026-06-06 Reading time: 5 min Tags: #security #git #devops…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!




Removing API Keys from Git History: BFG + Force Push (A Security Incident Response)



Published on: 2026-06-06


Reading time: 5 min


Tags: #security #git #devops #secrets





The Situation



API keys were committed to .env file in Git history. Anyone with repo access could do git log and see them.




git log --all --full-history --name-only | grep ".env"
# abc1234 Remove .env from version control
# def5678 Initial commit: Contest Agent






Immediate risk:




  • Clone repo → check git history → steal API keys

  • If pushed to GitHub, keys are potentially searchable/cached






Solution: BFG Repo-Cleaner



Better than git filter-branch (faster, safer):






Step 1: Install BFG






brew install bfg









Step 2: Delete from History






cd your-project
bfg --delete-files ".env" --no-blob-protection .






Output:




Deleted files:
Deleted 4 commits
Deleted 12 blob(s)
...









Step 3: Clean Up






git reflog expire --expire=now --all
git gc --prune=now --aggressive









Step 4: Verify






git log --all --full-history --name-only | grep ".env"
# (no output = success)









Step 5: Force Push






git push origin main --force-with-lease









Before & After



Before BFG:




$ git log --oneline | head -5
abc1234 Remove .env from version control
def5678 Enable SSL certificate verification
ghi9012 Standardize dependencies






After BFG:




$ git log --oneline | head -5
xyz3456 Remove duplicate service definition
uvw7890 Standardize dependencies
rst1234 Enable SSL certificate verification






Unnecessary commits removed, history cleaned.






BFG vs git filter-branch

































Factor git filter-branch BFG
Speed Slow (1000+ commits) Fast
Safety Complex, error-prone Simple, clear feedback
Usability Requires scripting One-liner
Recommendation ❌ ✅





CRITICAL: Rotate API Keys



Cleaning git history is step 1. Step 2 is mandatory:






Timeline: Do This Immediately



Within 1 hour:




# Anthropic
# → https://console.anthropic.com/account/keys
# → Delete old key, generate new one

# Supabase
# → https://app.supabase.com → Settings → API
# → Click "Reset secret key"

# Telegram
# → Open @BotFather
# → /token → select bot → /revoke
# → Generate new token






Within 24 hours:




  • Update all deployed servers with new keys

  • Test that services still work

  • Monitor logs






Best Practices Going Forward






1. Initialize Correctly from Day One






# First thing in new project:
echo ".env" >> .gitignore
git add .gitignore
git commit -m "Add .env to .gitignore"









2. Create .env.example






# .env.example
ANTHROPIC_API_KEY=your-key-here
SUPABASE_URL=your-url-here
TELEGRAM_BOT_TOKEN=your-token-here









3. Use GitHub Actions Secrets






# .github/workflows/deploy.yml
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}









4. Add Pre-Commit Hook (Optional)






#!/bin/bash
# .git/hooks/pre-commit

if git diff --cached --name-only | grep -E '\.env'; then
echo "❌ Error: Attempting to commit .env file"
exit 1
fi









Real Impact (After Remediation)






Before:
- .env in git history
- 79 commits total
- History size: 50MB

After BFG:
- .env removed from all commits
- 75 commits total (4 cleaned)
- History size: 42MB (-16%)









Execution Checklist



Phase 1: Immediate (Next 1 hour)




  • [ ] Run BFG: bfg --delete-files ".env" .

  • [ ] Clean git: git reflog expire ... && git gc ...

  • [ ] Force push: git push origin main --force-with-lease



Phase 2: Rotate (Next 24 hours)




  • [ ] Anthropic API key

  • [ ] Supabase Secret Key

  • [ ] Telegram Bot token



Phase 3: Prevention




  • [ ] Update deployed servers with new keys

  • [ ] Create .env.example

  • [ ] Update .gitignore

  • [ ] Add GitHub Actions secrets

  • [ ] Notify team (force push happened)



Phase 4: Future




  • [ ] Set up pre-commit hooks

  • [ ] Monthly secret audit

  • [ ] Use Secret scanning tools (GitHub, GitLab)






Key Takeaway



API key exposure is a security incident, not a "mistake."




  • Act fast (BFG)

  • Rotate keys (mandatory)

  • Document the response

  • Prevent recurrence



Your security posture will be better for it—and you'll have a good story for the next security audit.

Intelligence Digest — kostenlos Täglich die wichtigsten Security-News · jederzeit abbestellbar
Community Rating & Social Proof
⭐ Leser-Wertung
–
Ø / 5.0
Noch keine Leser-Bewertungen
War diese Seite hilfreich?
0
Jetzt Bewertung abgeben
🟢 Niedrig (1-3.9) 🟡 Mittel (4.0-6.9) 🔴 Hoch (7.0-8.9) Kritisch (9.0-10.0)

Verwandte Story-Cluster & Quellen (Vektor-KI)

2 Quellen
# Invoice AI: Turn Invoice Photos into Business Intelligence with an AI-Powered Business Analyst
1 weitere Quelle
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Removing API Keys from Git History: BFG + Force Push (A Security Incident Response)

Thematisch verwandte Begriffe: Removing, Keys, from, History · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
Nächster Beitrag