Skip to main content
In this lesson you’ll see how to enable GitHub Advanced Security (GHAS) secret scanning at the enterprise level, apply a custom policy to repositories, and observe how a push containing a secret is detected and handled. This walkthrough also demonstrates a CodeQL-detectable issue in the same example repository so you can see both secret scanning and static analysis results. What you’ll learn:
  • How to create and apply an enterprise GHAS configuration for secret protection and push protection
  • How push protection (pre-receive hook) reacts to detected secrets
  • How secret scanning alerts appear in the repository and what actions you can take
  • A demo Node.js repository that triggers secret scanning and a CodeQL-detectable arbitrary file read

Create and apply an enterprise GHAS configuration

From your Enterprise account, go to Enterprise settings → Advanced Security. The default is the GitHub-recommended configuration (which covers secret protection, code security, and Dependabot). For this demo we create a custom configuration named “NextGen Advanced Security” and enable secret protection with the recommended options. Specifically we enable:
  • Secret protection (secret scanning)
  • Validity checks
  • Extended metadata
  • Generic patterns
  • AI-detected secrets
  • Push protection
We also configure bypass privileges so enterprise owners and organization admins can submit bypass requests.
A screenshot of a GitHub Enterprise security settings page (dark theme) showing Secret Protection/secret scanning options and bypass privileges. A "Select actors" dropdown is open listing roles like Enterprise owners and Organization admin.
Grant bypass privileges sparingly. Bypass requests allow a push to proceed despite detected secrets — use them only for known false positives or controlled testing. For production, require a bypass request instead of allowing users to dismiss alerts.
Require a bypass request rather than allowing users to dismiss alerts directly. In this demo we leave code security and dependency scanning disabled for now (you can enable them later). After saving the new configuration, apply it across the targeted repositories. When applying the configuration, GHAS may show a modal summarizing the impact including license usage. For example, enabling secret protection for private repositories can consume secret-protection licenses. Review the modal before confirming the policy application.
A dark-themed screenshot of a GitHub Enterprise "Settings" page open to GitHub Advanced Security, with a modal asking to apply a configuration that will enable "nextgen-advanced-security" for 3 repositories. The dialog notes the org is on an Advanced Security trial until 2026-09-24 and shows license usage (0 Code Security, 1 Secret Protection).

What happens on push (push protection / pre-receive hook)

After the configuration is applied, secret scanning runs on pushes and (if enabled) push protection enforces a pre-receive hook. When a push contains a high-entropy secret, GitHub detects it and displays a blocking popup indicating the secret type and location (for example, “GitHub Personal Access Token detected on line 14”). When a secret is detected at push you generally have three options:
  • Cancel the push and remove the secret (recommended if the secret is real).
  • Submit a bypass request (for controlled testing or known false positives).
  • Allow the secret (explicitly mark it allowed and proceed with the push).
For this demo we allow the secret so the push completes and an alert is raised in the repository.

Demo repository — examples that trigger GHAS and CodeQL

The demo repository contains a minimal Node.js app with two intentional issues:
  • DEMO 1: High-entropy mock credentials (AWS-style keys and a mock GitHub Personal Access Token). Secret scanning will detect these patterns (public leak).
  • DEMO 2: An intentionally vulnerable endpoint that passes unvalidated user input to res.sendFile() to illustrate an arbitrary file read / path traversal that CodeQL will flag as a static analysis issue.
Below is the demo code used for the examples:

After the push — viewing alerts

After committing and pushing the file that included the mock PAT, the repository’s Security and code security → Secret scanning alerts page shows an open alert for the leaked GitHub Personal Access Token (public leak). The alert includes detection location, remediation guidance, secret type, and bypass metadata.
A screenshot of a GitHub repository's "Security and quality" › "Secret scanning alerts" page showing one open alert for a leaked GitHub Personal Access Token labeled as a public leak. The left sidebar lists security features like Dependabot, code scanning, and secret scanning.
Inside the alert you can:
  • View remediation guidance (rotate or revoke the secret, and remove it from the repository history).
  • See who requested or approved a bypass (if a bypass was used).
  • Close the alert once the secret is rotated and removed.

Quick reference

Remediation best practices

  • Never commit real secrets. Use environment variables, secrets managers, or GitHub Actions secrets.
  • If a secret is accidentally committed: rotate/revoke it immediately and remove it from history (for example with git filter-repo or git filter-branch followed by a force push).
  • Use bypass requests only for known false positives or controlled testing. Monitor who has bypass privileges.
Never commit real secrets to repositories. Use environment variables, secrets managers, or GitHub Secrets/Actions secrets. If a secret is accidentally committed, rotate/revoke it immediately and remove it from history.

Watch Video