Skip to content

Lesson 7 of 13 · 15m

Source Code and Secret Leaks

GitHub code search, trufflehog, and gitleaks turn commit history into infrastructure disclosure — and found keys get reported, never used.

Developers leak their infrastructure into public code long before any breach makes the news. API keys in commit history, .env files pushed to public repos, CI logs with bearer tokens, Docker image layers containing private certificates, gists pasted to share a config with a coworker. GitHub is the highest-density OSINT source on the internet for exactly one reason: the people leaking things there don't think of it as publishing.

GitHub as a sensor

The current code search takes qualifiers worth memorizing. org:target path:.env finds environment files committed inside an organization's repos. org:target content:"AKIA" hunts AWS access key IDs — the AKIA prefix is structurally enforced by AWS, so it almost never false-positives. path:wp-config.php, path:id_rsa, content:"BEGIN OPENSSH PRIVATE KEY" each surface a different failure mode. Gists search separately and leak at a higher rate, because people treat gists as ephemeral — they are not.

The same search run against a person's repos rather than an org's is how handles pivot into infrastructure: a leaked DATABASE_URL in a side project's commit names the hosting provider, the database name, and sometimes the internal hostname convention.

History never dies

Deleting a file in a new commit removes it from the file listing, not the repository. The blob persists in history, in forks that cloned it before the deletion, in GitHub's public event data archived to GH Archive on BigQuery, and in dangling objects reachable by commit SHA long after the UI forgets them. The 2019-era lesson everyone cites — keys deleted in commit n+1 are readable at commit n — is still true today.

Two scanners do the work for you. gitleaks detect --source . --verbose walks full history for ~140 known secret formats plus entropy outliers. trufflehog git file:///path/to/repo does the same and goes a step further — it can verify whether discovered credentials are still live against their issuers. Run both; their rule sets differ enough to find different things.

This already happened, repeatedly

Uber, 2016. Attackers found AWS credentials in a private GitHub repository, used them against S3, and pulled records on 57 million riders and drivers. Uber paid $100,000 framed as a bug bounty, had the attackers sign NDAs, and disclosed nothing — until it came out. Former security chief Joe Sullivan was convicted of obstruction of justice and covering up a felony in October 2022. The credential was leaked; the cover-up was the crime.

Toyota, September 2022. A source repository on GitHub containing an access key to a customer-data source was left public for nearly five years — December 2017 to September 2022. Roughly 296,000 customers' data sat reachable through a repo anyone could read.

These are not edge cases. Credential-in-repo is the single most common real-world leak class, and it is visible to anyone who searches.

What you do with a found key

Nothing that authenticates. The instinct to "check if it's live" by calling the AWS API is using the credential — unauthorized access regardless of how public the leak was, and your IP in the target's CloudTrail. The correct workflow:

  1. Record the artifact: repo URL, file path, commit SHA, and the exposure window from commit dates.
  2. Fork or archive the evidence via your normal ledger process — Wayback captures the commit page; git clone preserves the history.
  3. Report through the target's published disclosure channel — security.txt (RFC 9116) at /.well-known/security.txt first, then their security contact.

Finding a live credential makes you a witness, not a user. The same pipeline pointed inward — trufflehog and gitleaks in your own CI, pre-commit hooks catching keys before they land — is the control this technique argues for.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.