- 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

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.

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).
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.
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.
- 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-repoorgit filter-branchfollowed 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.
Links and references
- GitHub: Secret scanning overview
- GitHub: CodeQL / code scanning
- GitHub: Encrypted secrets for Actions
- Removing sensitive data from a repository