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

TechniqueT1552.001 (Credentials In Files)
AlsoCWE-798 (Hard-coded Credentials)
DetectionSecret scanning, push protection
First responseRevoke and rotate, then clean history
Better designSecrets manager or short-lived OIDC credentials
Common abuseCrypto-mining, data theft

Step by step

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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

More in DevSecOps.