Lesson 11 of 12 · 15m
When a Secret Leaks
Public commits hit scraper feeds in seconds and AWS quarantine in minutes; the runbook is revoke first, investigate second, and rotate before you write the ticket.
Push an AWS key to a public repo and start the clock. GitHub's public events feed emits the push within seconds; scrapers running AKIA[0-9A-Z]{16} over that feed — and the same regexes over commit contents via the code-search endpoints — flag it in under a minute. The scraped keys go straight to automated reconnaissance: sts get-caller-identity to see what they bought, iam list-users and ec2 describe-instances to map the account, then either crypto mining at the account's limit or quiet data reads depending on who's driving. AWS's own scanner follows on a parallel track: it finds the exposed key, attaches the AWSCompromisedKeyQuarantineV2 managed policy to the IAM principal (denying instance launches, most writes, and the expensive stuff), and emails the account's root contact. Public testing of this pipeline lands it in the low single-digit minutes. Deleting the commit nine minutes later changes nothing — the key was harvested before your push notifications settled.
The private-leak version
Private repos leak differently but no less surely. The contractor's clone on a sold laptop. The CI log where a debug step ran env. The poisoned dependency dumping runner memory — tj-actions/changed-files put secrets into public workflow logs across ~23,000 repos in March 2025 (CVE-2025-30066), and the harvest didn't require anyone to commit a key. Codecov's bash uploader shipped env output to an attacker IP for about two months in early 2021. CircleCI disclosed in January 2023 that malware on an engineer's laptop stole a 2FA-backed session cookie and let attackers exfiltrate customer variables — their advice was to rotate everything, because once a store is read you cannot enumerate which secrets were seen. Uber's 2016 breach started with creds from a private GitHub repo and ended with 57 million records out of S3 and a federal conviction for the CSO who covered it up.
The pattern across all of them: the window between exposure and use is shorter than the window between exposure and a human noticing. Assume use. The other thing every one of these cases shares is that the secret wasn't exotic — it was a normal credential in a normal place, and the failure was organizational: nobody rotated it fast because nobody had decided in advance who could.
The wrong mental model
"We'd notice if a credential leaked" — you wouldn't; valid credentials used correctly look like normal traffic. And "it was only exposed briefly" — scrapers work in seconds, not business hours. The other half: "rotate later, once we assess." Assessment after revocation costs nothing; assessment first is how a 9-minute exposure becomes a 9-month tenant.
The runbook
- Revoke the credential first. Not rotate — kill it. A dead key can't be used while you think.
- Then issue the replacement through the normal path and redeploy dependents, in the order the dependency graph demands: the secret's consumers restart in dependency order, not alphabetic panic.
- Audit what it touched: CloudTrail for the leaked principal (
iam,ec2,s3,secretsmanagercalls), Vault audit log for token paths, CI logs for the workflow window. You are looking for use between exposure and revocation, and for anything the credential created — new IAM users, access keys on existing users, role trust-policy changes, launched instances — because the persistence an attacker bought during the window survives your rotation. - Pre-build the list before you need it: who can revoke each class of secret (cloud root, Vault admin, DB superuser), what each secret's dependents are, and where the paging contact lives. An incident at 3 a.m. is not when you learn that only one person can rotate the Stripe key.
A leaked secret is a burned secret. The only variable under your control is how fast it dies.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
RSA Is Simple. Deploying RSA Correctly Almost Never Is.
The capstone to our RSA series. The math checks out. Shipping it as written gets you breached. This is the nineteen-year-old attack that proves it, and what belongs in production instead.
RSA in JavaScript Part 2: The JWT Is Where You'll Actually Meet It
Most JavaScript developers never call an RSA function directly. They verify an RS256 token, and two classic attacks turn that into an authentication bypass — both demonstrated here, both fixed by one line.
Implementing RSA, AES-GCM, and a TLS 1.3 Handshake from Scratch in Python
What is Encryption? The Math That Keeps Your Data Private
Encryption transforms readable data into unreadable ciphertext that only someone with the right key can reverse. It's what makes HTTPS, messaging apps, banking, and password storage work. Here's how it actually functions.