- built-in high-entropy AWS credentials (detected automatically by GitHub),
- a mock GitHub PAT,
- an example ACME token that initially does NOT match the custom regex.
Never commit real credentials, API keys, or tokens to a repository. All secrets in these examples are dummy values shown for demonstration only.
Overview
- Built-in secret formats (AWS keys, GitHub PATs, etc.) are detected automatically by GitHub Secret Scanning.
- Organization-specific secrets (like
ACME-...) require a custom pattern to be created and published. - Use the test string and dry run features to validate patterns before publishing to avoid false positives.
Why the initial commit did not raise an alert
Theacme_token shown above uses a proprietary format not recognized by GitHub out of the box. Until you create a custom secret pattern that matches the token format and publish it, Secret Scanning will not generate alerts for that token. Pushing the original file to main will therefore not trigger an alert for the ACME token.
Creating a custom secret pattern
Custom patterns can be configured at either the repository or organization level.
To create a pattern:
- Go to the repository or organization Settings.
- Navigate to Security -> Advanced Security -> Secret scanning (or the “Secret scanning” subsection).
- In the Custom patterns section, create a new pattern:
- Name: e.g.,
Acme - Regular expression: e.g.,
ACME-[A-Z0-9]{7} - Optional “before secret” and “after secret” context to reduce false positives
- Test string for validation: e.g.,
ACME-9874561
- Name: e.g.,
ACME- followed by exactly 7 uppercase alphanumeric characters:
ACME-[A-Z0-9]{7}
You can validate the pattern by providing a test string in the UI and then running a dry run against selected repositories.
Helpful reference:
Dry run: initial result (no matches)
If you run a dry run against the repository while the token remainsACME-12345678901234567890123456789012, the pattern ACME-[A-Z0-9]{7} will not match because the token is too long. The dry run will likely return zero matches.
Tip:
- For large organizations, select a subset of repositories to run a targeted dry run and reduce runtime.
Update the token to match the regex and commit
Editapp.js so the ACME token matches the custom pattern. Replace the long token with a correctly sized token:
main. If the custom pattern has not been published yet, this push will still succeed without generating a scanning alert — use the dry run feature to validate matches before publishing.
Dry run after update — match found
Run the dry run again for the target repository. With the token updated toACME-1234567 and the pattern ACME-[A-Z0-9]{7}, the dry run should produce one or more matches.
The dry run report will show:
- Repository and file path with matches
- Number of matches and example matching strings
- Links to the commit/file locations where matches occurred
Publish the pattern
Publishing the custom pattern (at org or repo level) makes it active for future pushes:- In the Custom patterns UI, choose to publish the pattern to the organization or repository.
- Confirm and publish.
- Future pushes that include matching secrets will automatically create Secret scanning alerts.
- The pattern appears in the global custom patterns list where you can edit or delete it.
Viewing secret scanning alerts in the repository
When a matching secret is pushed after publishing the pattern, GitHub creates a Secret scanning alert. To view and act on alerts:- Go to the repository on GitHub.
- Click Security -> Secret scanning alerts.
- The list shows recent matches with:
- Repository and file path
- Commit where the match was introduced
- Time and occurrence count
- Open an alert to see details and take action:
- Close as false positive
- Edit or tighten the pattern
- Follow remediation guidance (rotate or revoke the secret)
ACME-1234567, the repository’s Secret scanning alerts page will list the alert pointing to the file and commit containing the token.
If a custom pattern produces false positives, update the regular expression or add contextual “before” and “after” strings. Tightening the regex reduces noise and prevents unnecessary alerts.
Summary
- GitHub Secret Scanning automatically detects many public secret formats; organization-specific secrets require custom patterns.
- Repository-level patterns: up to 100. Organization-level patterns: up to 500.
- Validate patterns with the integrated test string and dry run features before publishing.
- After publishing, matching pushes generate Secret scanning alerts visible under Security -> Secret scanning alerts.