About custom patterns for secret scanning
GitHub performs secret scanning on public and private repositories for secret patterns provided by GitHub and GitHub partners. For more information on the secret scanning partner program, see "Secret scanning partner program."
However, there can be situations where you want to scan for other secret patterns in your private repositories. For example, you might have a secret pattern that is internal to your organization. For these situations, you can define custom secret scanning patterns in your enterprise, organization, or private repository on GitHub. You can define up to 500 custom patterns for each organization or enterprise account, and up to 100 custom patterns per private repository.
Regular expression syntax for custom patterns
Custom patterns for secret scanning are specified as regular expressions. Secret scanning uses the Hyperscan library and only supports Hyperscan regex constructs, which are a subset of PCRE syntax. Hyperscan option modifiers are not supported. For more information on Hyperscan pattern constructs, see "Pattern support" in the Hyperscan documentation.
Defining a custom pattern for a repository
Before defining a custom pattern, you must ensure that secret scanning is enabled on your repository. For more information, see "Configuring secret scanning for your repositories."
-
On GitHub.com, navigate to the main page of the repository.
-
Under your repository name, click Settings.
-
In the left sidebar, click Security & analysis.
-
Under "Configure security and analysis features", find "GitHub Advanced Security."
-
Under "Secret scanning", under "Custom patterns", click New pattern.
-
Enter the details for your new custom pattern:
- You must at least provide the name for your pattern, and a regular expression for the format of your secret pattern.
- You can click More options to provide other surrounding content or additional match requirements for the secret format.
- Provide a sample test string to make sure your configuration is matching the patterns you expect.
-
When you are satisfied with your new custom pattern, click Create pattern.
After your pattern is created, secret scanning scans for any secrets in your entire Git history on all branches present in your GitHub repository. For more information on viewing secret scanning alerts, see "Managing alerts from secret scanning."
Defining a custom pattern for an organization
Before defining a custom pattern, you must ensure that you enable secret scanning for the private repositories that you want to scan in your organization. To enable secret scanning on all private repositories in your organization, see "Managing security and analysis settings for your organization."
Note: As there is no dry-run functionality, we recommend that you test your custom patterns in a repository before defining them for your entire organization. That way, you can avoid creating excess false-positive secret scanning alerts.
-
In the top right corner of GitHub.com, click your profile photo, then click Your organizations.
-
Next to the organization, click Settings.
-
In the left sidebar, click Security & analysis.
-
Under "Configure security and analysis features", find "GitHub Advanced Security."
-
Under "Secret scanning", under "Custom patterns", click New pattern.
-
Enter the details for your new custom pattern:
- You must at least provide the name for your pattern, and a regular expression for the format of your secret pattern.
- You can click More options to provide other surrounding content or additional match requirements for the secret format.
- Provide a sample test string to make sure your configuration is matching the patterns you expect.
-
When you are satisfied with your new custom pattern, click Create pattern.
After your pattern is created, secret scanning scans for any secrets in private repositories in your organization, including their entire Git history on all branches. Organization owners and repository administrators will be alerted to any secrets found, and can review the alert in the repository where the secret is found. For more information on viewing secret scanning alerts, see "Managing alerts from secret scanning."
Defining a custom pattern for an enterprise account
Before defining a custom pattern, you must ensure that you enable secret scanning for your enterprise account. For more information, see "Enabling GitHub Advanced Security for your enterprise."
Note: As there is no dry-run functionality, we recommend that you test your custom patterns in a repository before defining them for your entire enterprise. That way, you can avoid creating excess false-positive secret scanning alerts.
-
In the enterprise sidebar, click Policies.
-
Under Policies, click "Advanced Security."
-
Under "GitHub Advanced Security", click the Security features tab.
-
Under "Secret scanning custom patterns", click New pattern.
-
Enter the details for your new custom pattern:
- You must at least provide the name for your pattern, and a regular expression for the format of your secret pattern.
- You can click More options to provide other surrounding content or additional match requirements for the secret format.
- Provide a sample test string to make sure your configuration is matching the patterns you expect.
-
When you are satisfied with your new custom pattern, click Create pattern.
After your pattern is created, secret scanning scans for any secrets in private repositories within your enterprise's organizations with GitHub Advanced Security enabled, including their entire Git history on all branches. Organization owners and repository administrators will be alerted to any secrets found, and can review the alert in the repository where the secret is found. For more information on viewing secret scanning alerts, see "Managing alerts from secret scanning."
Editing a custom pattern
When you save a change to a custom pattern, this closes all the secret scanning alerts that were created using the previous version of the pattern.
- Navigate to where the custom pattern was created. A custom pattern can be created in a repository, organization, or enterprise account.
- For a repository or organization, display the "Security & analysis" settings for the repository or organization where the custom pattern was created. For more information, see "Defining a custom pattern for a repository" or "Defining a custom pattern for an organization" above.
- For an enterprise, under "Policies" display the "Advanced Security" area, and then click Security features. For more information, see "Defining a custom pattern for an enterprise account" above.
- Under "Secret scanning", to the right of the custom pattern you want to edit, click .
- When you have reviewed and tested your changes, click Save changes.
Removing a custom pattern
-
Navigate to where the custom pattern was created. A custom pattern can be created in a repository, organization, or enterprise account.
- For a repository or organization, display the "Security & analysis" settings for the repository or organization where the custom pattern was created. For more information, see "Defining a custom pattern for a repository" or "Defining a custom pattern for an organization" above.
- For an enterprise, under "Policies" display the "Advanced Security" area, and then click Security features. For more information, see "Defining a custom pattern for an enterprise account" above.
-
To the right of the custom pattern you want to remove, click .
-
Review the confirmation, and select a method for dealing with any open alerts relating to the custom pattern.
-
Click Yes, delete this pattern.