Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 1 min read

Secrets in a GitHub Repo: How to Find Leaked Keys Before the Merge

TL;DR: scan every pull request for keys, not just the default branch, and fail the check before merge. Below is how to do it in about a minute, what is worth catching, and what to do if a key already got in. Wh

Secrets in a GitHub Repo: How to Find Leaked Keys Before the Merge

TL;DR: scan every pull request for keys, not just the default branch, and fail the check before merge. Below is how to do it in about a minute, what is worth catching, and what to do if a key already got in.

Which keys to look for

Five formats cover most real leaks: AWS, GitHub, Anthropic, OpenAI and Stripe live keys, plus Slack tokens and private key blocks. A good scanner skips test files, sample TLS keys and documentation placeholders, otherwise you will mute it by week two.

Scan in CI with one step

GEL includes a secret-scan guard. It is plain Node, no model and no network.

- uses: actions/checkout@v4   # pin it to a SHA; GEL will tell you
  with: { fetch-depth: 0 }
- uses: flisk-sh/gel@v1

Locally, on any folder:

npx github:flisk-sh/gel run --root .

Start in report mode, then block only this guard:

{ "mode": "report", "guards": { "secret-scan": "block" } }

How well does it work

On a bench of 30 public repos, GEL caught 150 of 150 planted keys across 5 formats and reported 0 secrets on the clean repos. Only 1 of those 30 repos scanned for keys at all. These are planted keys in a test, so treat them as a measure of recall, not a guarantee for your code. Method: bench README.

See it across your org

Cilytics reads the GEL results from each repo's latest run and shows which repos run the guards and what is blocked. It reads the GitHub API only.

Cilytics: paste any GitHub repo and get a CI health score

If a key already leaked

  1. Revoke and rotate it first. Deleting the commit does not help, because the key is already copied.
  2. Check the provider's usage log for the window it was exposed.
  3. Only then clean the history, if you need to.

Checklist

  • [ ] Key scan runs on pull requests
  • [ ] The guard blocks, after a report-only trial
  • [ ] Rotation steps written down before you need them

Related: GitHub Actions security best practices (pins, permissions, links).

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.