Users with Semgrep Code’s Team or Enterprise tier can publish rules to the Semgrep Registry as private rules that are not visible to those outside their organization. Maintaining the rules’ privacy allows you the benefits of using the Semgrep Registry while keeping sensitive code or information internal.Documentation Index
Fetch the complete documentation index at: https://docs.semgrep.dev/llms.txt
Use this file to discover all available pages before exploring further.
Creating private rules
You can create private rules the same way you create other custom rules. The subsequent sections can help you create and save your private rules.Create private rules through Semgrep AppSec Platform
To create and publish private rules through the Semgrep AppSec Platform:Go to Semgrep Editor.
Choose one of the following options to create your rule:
- Click the plus icon, select New rule, provide the YAML file for your rule, and then click Save.
- In the Library panel, select a rule from a category in Semgrep Registry. Click Fork, modify the rule or test code, and then click Save.
Create private rules through the Semgrep command-line interface
To create private rules through the Semgrep CLI, :Log in to Semgrep. Running this command launches a browser window, but you can also use the link that’s returned in the CLI to proceed:
Create your rule. For more information, see Contributing rules.
semgrep publish . to refer to the current directory. You must provide the directory specification.
If the directory contains test cases for the rules, Semgrep uploads them as well (see testing Semgrep rules).
You can change the visibility of the rules. For instance, to publish the rules as unlisted (which does not require authentication but results in the rules hidden from users of the public registry):
semgrep publish --help.
View and use private rules
View your rules in Semgrep Editor under the folder corresponding to your organization name. You can also find it in the Semgrep Registry by searching for[organization-id].[rule-id]. For example: r2c.test-rule-id.
To use the rule with subsequent scans, add the rule in the Registry to an existing policy.
Automatically publish rules
This section provides examples of how to automatically publish your private rules so they are accessible within your private organization. Publishing your private rules in this manner does not make them public. In the following examples, the private rules are stored inprivate_rule_dir, which is a subdirectory of the repository root. If your rules are in the root of your repository, you can replace the command with semgrep publish --visibility=org_private . to refer to the repository root. You must provide the directory specification.
The following sample of the GitHub Actions workflow publishes rules from a private Git repository after a merge to the main, master, or develop branches.
Delete private rules
To remove a private rule, follow these steps:In the Semgrep Editor, find the private rule to delete under the Library tab. Private rules are usually stored in the folder with the same name as your Semgrep AppSec Platform organization.