What Happens When You Type a URL and Press Enter
DNS lookups, TCP and TLS handshakes, HTTP requests, servers, and the browser's rendering pipeline. The whole journey of a web page, explained so it finally clicks.
Read →Bots scan public repositories for secrets constantly. If you pushed a key, deleting it isn't enough. The exact order of steps: revoke, check for damage, clean history, and prevent a repeat.
It happens to experienced developers too. A quick test, a .env that wasn't in .gitignore, a config file you forgot contained a token, and suddenly a secret is sitting in a public repository. Don't panic, but do move quickly. Automated scanners crawl public commits constantly, and leaked cloud keys can be abused within minutes.
Here's what to do, in order.
This is the only step that actually stops an attacker. Everything else is cleanup.
.env.Do this before rewriting Git history. Deleting the commit doesn't help if someone already copied the key, and you have to assume someone did.
If the leak included a database connection string, change the database password. If it was an SSH key, remove it from every server's authorized_keys.
Look for signs the key was used by someone else:
If you find abuse, contact the provider's support. Many will help with unexpected charges, especially when you act fast and have already rotated the key. Turn on billing alerts and spending caps while you're in there.
A new commit that deletes the key leaves it in history, readable by anyone who browses old commits. To really remove it, rewrite history.
The recommended tool is git filter-repo:
# Replace the secret text everywhere in history
echo 'sk_live_LEAKED_VALUE==>REMOVED' > replacements.txt
git filter-repo --replace-text replacements.txt
# Or remove a file from all history
git filter-repo --invert-paths --path .env
BFG Repo-Cleaner is a popular, simpler alternative for the same job.
Then force push the cleaned history:
git push --force-with-lease --all
git push --force-with-lease --tags
Know the limits:
That's exactly why Step 1 comes first. Rewriting history is hygiene, not a fix.
.env missing from .gitignore?Fix that root cause, or it'll happen again.
Ignore secret files from the start:
.env
.env.*
!.env.example
*.pem
*.key
Scan before commits reach the server. Tools like gitleaks or detect-secrets can run as a pre-commit hook and block a commit that contains something that looks like a key.
Turn on platform protection. GitHub offers secret scanning and push protection, which blocks pushes containing known secret formats. Many providers also partner with GitHub to automatically revoke their keys when they appear in public repos. That's helpful, but don't rely on it.
Use least privilege. A key that can only read one bucket does far less damage than an admin key. Create scoped keys per app and per environment.
Keep secrets in environment variables or a secret manager, never in code. (Here's a guide to doing that properly.)
For the bigger picture, run through this web application security checklist.
No. Assume it was copied as soon as it was pushed. Revoke and rotate the key first. Cleaning the history comes second.
Often within minutes for public repositories, because automated tools continuously scan new commits for credential patterns.
Only after the secrets have been rotated and removed from the entire history. A secret scanner like gitleaks can check the whole history before you flip the switch.
DNS lookups, TCP and TLS handshakes, HTTP requests, servers, and the browser's rendering pipeline. The whole journey of a web page, explained so it finally clicks.
Read →There are dozens of HTTP status codes, but about fifteen cover nearly everything. What each one means, when to return it, and the mix-ups (401 vs 403, 301 vs 302) that confuse everyone.
Read →A, AAAA, CNAME, MX, TXT and NS records in plain English, why DNS changes seem slow, and the troubleshooting commands that tell you what is really going on.
Read →