LV.1
EXP 0/1000
โ—€ Playbook index
NO.19.6

๐Ÿ”‘ Secret Scanning

In one sentence

Secret Scanning is GitHub's detection feature that automatically finds API keys, tokens, and connection strings lurking in your repository.

Secrets already committed get an alert; secrets about to be committed are blocked at `git push` time by Push protection. Stopping leaks before they happen is the core strategy.

Detection vs Push protection โ€” whatโ€™s the difference?

Secret Scanning operates in two modes. You should enable both.

FeatureWhen does it run?What does it do?Scope
๐Ÿ” Secret scanning alertsAfter commit (including history, continuously)Notifies you of detected secrets in the Security tabCommit history, Issues, PRs, descriptions, Wikis
๐Ÿ›ก๏ธ Push protectionRight before git pushRejects pushes containing secrets (bypass is possible)Incoming changes only
โœ… Validity checksWhen an alert firesAsks the provider API whether the secret is still activeSelect supported providers (AWS, GitHub, Slack, and others)

๐Ÿ”‘ Alerts = find secrets already in the repo; Push protection = prevent them from getting in at all. Push protection is the most effective measure (no history rewriting needed).

๐Ÿ“˜ Details: About secret scanning โ†— ยท About push protection โ†—

What gets detected

  • ๐Ÿท๏ธ Provider patterns โ€” Regex patterns registered by 200+ partners including AWS, Azure, GCP, Stripe, Slack, OpenAI, and GitHub PATs. Extremely low false-positive rate
  • ๐Ÿงช Generic / non-provider patterns โ€” password = "...", HTTP basic auth, generic API key-like strings. AI-based detection (Copilot Secret Scanning) can also be enabled
  • ๐Ÿ› ๏ธ Custom patterns โ€” Define your own regex for proprietary token formats (requires GHAS)
  • ๐Ÿ“š Scope โ€” Not just code: Issues, PRs, commit messages, descriptions, Wikis, and Gists are all scanned

๐Ÿค– Generic secrets and AI detection tend to produce more false positives. Pairing them with Push protection means things get stopped at the moment someone tries to commit them โ€” much easier to operate.

๐Ÿ“˜ Details: Supported secrets (provider patterns) โ†— ยท Defining custom patterns โ†—

Response flow when a secret is exposed

When a secret is found, remediation matters more than detection.

  1. ๐Ÿšจ Rotate / revoke immediately โ€” removing it from the repository is not enough (it remains in history and in other peopleโ€™s clones)
  2. ๐Ÿ“ฃ GitHub notifies you โ€” providers enrolled in the partner program may automatically invalidate the secret (AWS, GitHub PATs, and others)
  3. ๐Ÿงน Close the alert โ€” mark it as Revoked, False positive, or Used in tests
  4. ๐Ÿ›ก๏ธ Enable Push protection to prevent recurrence

Getting started (fastest path)

Step 1 โ€” Enable Push protection (highest priority first)

Repo โ†’ Settings โ†’ Code security
  โœ… Secret scanning
  โœ… Push protection

Public repos have this on by default and completely free. Repo-level push protection for private repos requires Secret Protection / GHAS โ€” but individual user opt-in is free on all plans (User โ†’ Settings โ†’ Code security and analysis).

Step 2 โ€” Scan for existing leaks

Once enabled, past commit history is automatically scanned. Alerts will appear in the Security tab โ€” work through them from the top, rotating each secret.

Step 3 โ€” Add custom patterns

Repo or Org โ†’ Settings โ†’ Code security โ†’ Secret scanning โ†’ Custom patterns

Register your own token format with a regex. Free for public repos; private repos require GHAS / Secret Protection. Use the dry-run feature to check for false positives before going live.

Step 4 โ€” Enable org-wide / enterprise-wide

Use default settings in Org โ†’ Settings โ†’ Code security to apply to new and existing repositories at once.

๐Ÿ“˜ Details: Enabling secret scanning for your repo โ†—

Eligibility and pricing

FeaturePublic repoPrivate repo (No GHAS / Secret Protection)Private repo (With GHAS / Secret Protection)
Push protection (user personal opt-in)โœ… Freeโœ… Free (since 2024)โœ…
Push protection (repo / org level)โœ… FreeโŒโœ…
Secret scanning alertsโœ… FreeโŒโœ…
Partner secret invalidationโœ… AutomaticโŒโœ… Automatic
Validity checksโœ… FreeโŒโœ…
Custom patternsโœ… FreeโŒโœ…
AI detection (generic)โœ… FreeโŒโœ…

๐Ÿ’ฐ In 2025, GHAS was split โ€” if you only need secret scanning, Secret Protection ($19/month/active committer) is enough (no full GHAS contract required). Combine with GitHub Code Security if you also want CodeQL.
๐Ÿ†“ Individuals can enable user push protection via Settings โ†’ Code security โ€” this warns even on private repos without any license. Recommending this to all employees is the fastest way to prevent accidents.
๐Ÿ›ก๏ธ Push protection at the repo/org level is completely free and on by default for public repos. A Secret Protection / GHAS license is only needed when you want to enforce it org-wide on private / internal repos. See About push protection โ†—.

๐Ÿ“˜ Details:

Secret Risk Assessment (free inventory scan)

Secret Risk Assessment performs a one-time scan of every repository in your org (public, private, internal, and archived) to make visible "what secrets are hiding and where."

No GHAS / Secret Protection required โ€” completely free (since 2025), available to all Team and Enterprise orgs. Perfect for a pre-purchase inventory or an executive security report.

  • ๐Ÿ”Ž Scope โ€” all repos in the org (any visibility), including archived repos
  • ๐Ÿ“Š Output โ€” aggregated report showing secret type, count, and how many are in each repo (individual secret values are not exposed)
  • ๐Ÿ•’ Frequency โ€” a single point-in-time scan; not continuous monitoring (buy Secret Protection for ongoing coverage)
  • ๐Ÿ” Privacy โ€” detected secret values are not stored by GitHub. Only statistics are visible to org admins
  • ๐Ÿš€ How to run โ€” Org โ†’ Settings โ†’ Code security โ†’ Secret risk assessment โ†’ Run assessment

๐Ÿ“Š Use this first when you want to โ€œjust know how many secrets are leaking across the orgโ€ or โ€œneed numbers for a budget proposal.โ€ Review the results to decide whether to adopt Secret Protection.

๐Ÿ“˜ Details: Enabling Secret Risk Assessment โ†—