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.
| Feature | When does it run? | What does it do? | Scope |
|---|---|---|---|
| ๐ Secret scanning alerts | After commit (including history, continuously) | Notifies you of detected secrets in the Security tab | Commit history, Issues, PRs, descriptions, Wikis |
| ๐ก๏ธ Push protection | Right before git push | Rejects pushes containing secrets (bypass is possible) | Incoming changes only |
| โ Validity checks | When an alert fires | Asks the provider API whether the secret is still active | Select 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.
- ๐จ Rotate / revoke immediately โ removing it from the repository is not enough (it remains in history and in other peopleโs clones)
- ๐ฃ GitHub notifies you โ providers enrolled in the partner program may automatically invalidate the secret (AWS, GitHub PATs, and others)
- ๐งน Close the alert โ mark it as
Revoked,False positive, orUsed in tests - ๐ก๏ธ 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
| Feature | Public repo | Private 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 viaSettings โ 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:
- Push protection is GA & free for all public repos (GitHub Blog) โ
- Push protection enabled for free users (2024 Feb) โ
- Introducing GitHub Secret Protection & Code Security (2025 Mar) โ
- GitHub plans pricing โ
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 โ