Skip to content

Domain 2: Configure and Use Secret Scanning (15%) โ€‹

โ† Domain 1 ยท Next Domain โ†’

Exam Tip

Know the difference between secret scanning (reactive โ€” detects secrets already committed) and push protection (proactive โ€” blocks secrets before commit). The exam loves asking which feature handles which scenario.


What Secret Scanning Does โ€‹

Secret scanning automatically scans the full repository history (all branches, all commits) for patterns matching known secrets and credentials:

  • AWS Access Keys
  • GitHub Personal Access Tokens
  • Stripe API Keys
  • Azure Storage Account keys
  • Private SSH keys
  • And 200+ other partner patterns

When a match is found, GitHub creates a secret scanning alert and notifies repository administrators and security managers.


Enabling Secret Scanning โ€‹

Repository Level โ€‹

Settings โ†’ Code security โ†’ Secret scanning โ†’ Enable

Organization Level โ€‹

Org Settings โ†’ Code security โ†’ GitHub Advanced Security โ†’ Secret scanning

  • Can enable for all current repositories, all future repositories, or both
  • Requires GHAS license for private/internal repositories

Enterprise Level โ€‹

Enterprise Settings โ†’ Code security โ†’ GitHub Advanced Security โ†’ Secret scanning

  • Applies a default policy across all organizations in the enterprise
  • Org owners can still override at the org level (unless locked by enterprise policy)

Push Protection โ€‹

Push protection blocks a git push if the diff contains a recognized secret pattern.

How Push Protection Works โ€‹

  1. Developer runs git push
  2. GitHub scans the diff for secret patterns
  3. If a secret is detected: the push fails with an error message naming the secret type
  4. Developer must either:
    • Remove the secret and re-push
    • Bypass the block by providing a reason (if allowed by policy)

Bypass Reasons (If Allowed) โ€‹

ReasonWhen to use
Used in testsThe secret is a fake/test credential
False positiveGitHub incorrectly identified this as a secret
Fix laterAcknowledged but not removing now (creates an alert)

Enabling Push Protection โ€‹

  • Repository: Settings โ†’ Code security โ†’ Push protection
  • Organization: Org Settings โ†’ Code security โ†’ Push protection
  • Enterprise: Enterprise policy level

Exam Trap

Push protection does not prevent all secret leaks. It blocks secrets at push time, but:

  • It only applies to patterns GitHub recognizes
  • Secrets in environment variables, CI logs, or manually pasted into chat are not caught
  • Bypass is possible โ€” the exam may ask about this as a limitation

Secret Scanning Patterns โ€‹

Partner Patterns โ€‹

  • GitHub maintains 200+ patterns in partnership with service providers (AWS, Azure, Stripe, GitHub, etc.)
  • Partner patterns are automatically updated when providers submit new patterns
  • When a partner pattern match is found, GitHub can notify the service provider (automatic revocation for some providers)

Custom Patterns โ€‹

Organizations and enterprises can define their own secret patterns using regular expressions.

Repository-level: Settings โ†’ Code security โ†’ Custom patterns Organization-level: Org Settings โ†’ Code security โ†’ Custom patterns

Custom pattern syntax:

Name: Internal API Key
Pattern (regex): CORP-[A-Z0-9]{32}
Secret group: 1
Test string (optional): CORP-ABC123DEF456GHI789JKL012MNO345

TIP

Custom patterns can also be configured at the enterprise level and applied across all organizations.

Validity Checking โ€‹

For some partner patterns, GitHub can query the service provider's API to check if a detected token is still active (valid):

  • Shows alert status as: Active, Inactive, or Unknown
  • Helps prioritize which alerts require immediate action
  • Not available for all providers

Managing Secret Scanning Alerts โ€‹

Alert States โ€‹

StateMeaning
OpenSecret is active; needs remediation
Resolved โ€” RevokedSecret has been revoked/deleted at the provider
Resolved โ€” False positiveNot actually a secret
Resolved โ€” Used in testsKnown test credential
Resolved โ€” Won't fixAcknowledged; accepted risk

Remediation Steps (Correct Order) โ€‹

Always revoke first

  1. Revoke the secret at the service provider (e.g., delete the GitHub PAT, rotate the AWS key)
  2. Remove the secret from the codebase and commit history
  3. Audit access logs at the provider to check for unauthorized use
  4. Resolve the alert in GitHub with the appropriate reason

Removing Secrets from History โ€‹

After revoking a secret, if it's in commit history, you must also clean it up:

  • Use git filter-repo (recommended) or BFG Repo-Cleaner
  • Force-push the cleaned history
  • Contact GitHub Support to remove cached/cached views

Notifications and Webhooks โ€‹

  • Email notifications: Sent to repository admins and security managers by default
  • GitHub Security tab: Alerts visible under Security โ†’ Secret scanning
  • Webhooks: Organizations can receive secret_scanning_alert webhook events for automation

Domain 2 Quick Quiz

1 / 5
โ“

What is the key difference between secret scanning and push protection?

(Click to reveal)
๐Ÿ’ก
Secret scanning is reactive โ€” it scans existing commits and alerts you when a secret is found. Push protection is proactive โ€” it blocks the push before the secret reaches the remote repository.

โ† Domain 1 ยท Next Domain โ†’

Happy Studying! ๐Ÿš€ โ€ข Privacy-friendly analytics โ€” no cookies, no personal data
Privacy Policy โ€ข AI Disclaimer โ€ข Report an issue