Leaked Secrets in Code
From a pushed key to a cloud bill in minutes
Passwords, API keys and cloud credentials committed to a repository are among the most common causes of cloud breaches. Bots watch public code platforms continuously, and a leaked cloud key can be abused within minutes. Deleting the commit isn't enough: the key must be revoked.
Beginner · 5 steps
| Technique | T1552.001 (Credentials In Files) |
|---|---|
| Also | CWE-798 (Hard-coded Credentials) |
| Detection | Secret scanning, push protection |
| First response | Revoke and rotate, then clean history |
| Better design | Secrets manager or short-lived OIDC credentials |
| Common abuse | Crypto-mining, data theft |
Step by step
A key in a commit "Just for testing"
While debugging, a developer hard-codes a cloud access key in a script and pushes the branch to a public repository. They remove it in the next commit an hour later, but the key is still in the Git history.
Found in minutes Automated scanning
Bots monitor public commit feeds for anything that looks like a credential. Within minutes, one extracts the key and tests it with a harmless "who am I" call. It works.
Abuse Mining and data access
The attacker launches large compute instances in several regions to mine cryptocurrency and lists storage buckets to look for data. The first sign for the company is a usage alert and a surprising bill.
Respond: revoke first History cleanup comes second
The right order matters. First, deactivate and delete the key, so nothing else can use it. Then terminate the attacker's resources, check the audit log for everything the key did, and only then rewrite Git history. Removing the commit alone does nothing, because copies already exist.
Prevent it next time No long-lived keys in reach
Push protection now blocks commits that contain credentials. The script reads secrets from a secrets manager at runtime, and the CI system uses short-lived OIDC credentials instead of a stored key, so there is no long-lived key to leak.
How to defend
- Turn on secret scanning and push protection for every repository
- Keep secrets in a secrets manager or vault, never in code or images
- Prefer short-lived credentials (OIDC, instance roles) over long-lived keys
- If a secret leaks, revoke it first; cleaning Git history comes second
- Set billing and usage alerts so abuse is noticed quickly
More in DevSecOps.
Packets
| No. | Time | Source | Destination | Protocol | Info | Size |
|---|