You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/contributing/contributing-rules.md
+28-20
Original file line number
Diff line number
Diff line change
@@ -2,29 +2,30 @@
2
2
slug: contributing-to-semgrep-rules-repository
3
3
description: "This article outlines how to contribute to Semgrep Registry."
4
4
hide_title: true
5
+
title: Contribute rules to the Semgrep Registry
5
6
toc_max_heading_level: 4
6
7
---
7
8
8
9
import LinkToRegistryRule from "/src/components/LinkToRegistryRule"
9
-
10
10
import RequiredRuleFields from "/src/components/reference/_required-rule-fields.mdx"
11
11
12
-
# Contributing rules
12
+
# Contribute rules to the Semgrep Registry
13
13
14
-
Publish rules in the open source Semgrep Registry and share them with the Semgrep community to help others benefit from your rule-writing efforts and contribute to the field of software security. There are two ways in which you can contribute rules to the Semgrep Registry:
14
+
Publish rules to the Semgrep Registry to share them with the Semgrep community and contribute to the field of software security. There are two ways in which you can contribute rules to the Semgrep Registry:
15
15
16
16
<dl>
17
17
<dt>For users of Semgrep AppSec Platform</dt>
18
-
<dd>Contribute rules to the Semgrep Registry through Semgrep AppSec Platform. This workflow is recommended. See <a href="#contributing-through-semgrep-appsec-platform-recommended"> Contributing through Semgrep AppSec Platform (recommended)</a>. This workflow creates the necessary pull request for you and streamlines the whole process.</dd>
18
+
<dd>Contribute new rules to the Semgrep Registry through Semgrep AppSec Platform. This workflow is recommended. See <a href="#contribute-through-semgrep-appsec-platform-recommended"> Contribute through Semgrep AppSec Platform (recommended)</a>. This workflow creates the necessary pull request for you and streamlines the whole process.</dd>
19
19
<dt>For contributors to the repository through GitHub</dt>
20
-
<dd>Contribute rules to the Semgrep Registrythrough a pull request. See the <a href="#contributing-through-github"> Contributing through GitHub</a> section for detailed information.</dd>
20
+
<dd>Contribute rules to the Semgrep Registry, or suggest changes to existing rules, through a pull request to `semgrep-rules`. See the <a href="#contribute-through-github"> Contribute through GitHub</a> section for detailed information.</dd>
21
21
</dl>
22
22
23
-
## Contributing through Semgrep AppSec Platform (recommended)
23
+
## Contribute through Semgrep AppSec Platform (recommended)
24
24
25
-
To contribute and publish rules to the Semgrep Registry through Semgrep AppSec Platform, follow these steps:
25
+
This is the recommended path for adding a new rule. To suggest a change to an existing rule, see [Update existing rules in Semgrep Registry](#update-existing-rules-in-semgrep-registry).
26
26
27
-
1. Go to [Playground](https://semgrep.dev/playground/new).
27
+
1. Sign in to [<iclass="fas fa-external-link fa-xs"></i> Semgrep AppSec Platform](https://semgrep.dev/login).
28
+
1. Go to the [<iclass="fas fa-external-link fa-xs"></i> Semgrep Playground](https://semgrep.dev/playground/new).
28
29
1. Click <iclassName="fa-solid fa-file-plus-minus inline_svg"></i> **Create New Rule**.
29
30
1. Choose one of the following:
30
31
- Create a new rule and test code by clicking <iclass="fa-solid fa-circle-plus"></i> **plus** icon, select **New rule** and then click <iclassName="fa-solid fa-floppy-disk inline_svg"></i> **Save**. Note: The test file must contain at least one true positive and one true negative test case to be approved. See the [Tests](#tests) section of this document for more information.
@@ -34,21 +35,30 @@ To contribute and publish rules to the Semgrep Registry through Semgrep AppSec P
34
35
1. Fill in the required and optional fields.
35
36
1. Click <iclassName="fa-solid fa-circle-check inline_svg"></i> **Continue**, and then click <iclassName="fa-solid fa-code-pull-request inline_svg"></i> **Create PR**.
36
37
37
-
This workflow automatically creates a pull request in the GitHub [Semgrep Registry](https://github.com/semgrep/semgrep-rules). Find more about the Semgrep Registry by reading the [Rule writing](#writing-a-rule-for-semgrep-registry) and [Tests](#tests) sections.
38
+
This workflow automatically creates a pull request in the GitHub [Semgrep Registry](https://github.com/semgrep/semgrep-rules). Find more about the Semgrep Registry by reading the [Rule writing](#write-a-rule-for-semgrep-registry) and [Tests](#tests) sections.
38
39
39
40
You can also publish rules as private rules outside of Semgrep Registry. These rules are not included in the Semgrep Registry, but they are accessible to your Semgrep organisation. See the [Private rules](/writing-rules/private-rules) documentation for more information.
40
41
41
-
## Contributing through GitHub
42
+
## Contribute through GitHub
42
43
43
-
Fork our repository and make a pull request. Sign our Contributor License Agreement (CLA) on GitHub before Semgrep, Inc. can accept your contributions. Make a pull request to the [Semgrep Registry](https://github.com/semgrep/semgrep-rules) with two files:
44
-
1. The semgrep pattern (as YAML file).
45
-
2. The test file (with the file extension of the language or framework). The test file must contain at least one true positive and one true negative test case to be approved. See the [Tests](#tests) section of this document for more information.
44
+
1. Create a pull request in the [<iclass="fas fa-external-link fa-xs"></i> semgrep/semgrep-rules](https://github.com/semgrep/semgrep-rules) repository. The pull request requires two files:
45
+
- The Semgrep rule saved as a YAML file.
46
+
- The test file with the file extension of the language or framework. The test file must contain at least one true positive and one true negative test case to be approved. See the [Tests](#tests) section of this document for more information.
47
+
1. Sign the Contributor License Agreement (CLA) on GitHub; this is required before Semgrep can accept your contributions.
46
48
47
49
Pull requests require the approval of at least one maintainer and successfully passed [CI jobs](https://github.com/semgrep/semgrep-rules/actions).
48
50
49
-
Find more about the Semgrep Registry by reading the [Rule writing](#writing-a-rule-for-semgrep-registry) and [Tests](#tests) sections.
51
+
Find more about the Semgrep Registry by reading the [Rule writing](#write-a-rule-for-semgrep-registry) and [Tests](#tests) sections.
52
+
53
+
## Licensing
54
+
55
+
The Semgrep Registry can import rules from different repositories. These repositories can enforce their own licensing for rules. If you'd like to enforce a specific license, such as the MIT license or GNU Lesser GPL:
50
56
51
-
## Writing a rule for Semgrep Registry
57
+
1. Create a GitHub repository and store your rules there.
58
+
1. Reach out to the Semgrep team through the [<iclass="fas fa-external-link fa-xs"></i> Community Slack](https://go.semgrep.dev/slack) or [Support](/support)
59
+
60
+
61
+
## Write a rule for Semgrep Registry
52
62
53
63
The following sections document necessary fields in rule files of Semgrep Registry, provide information about rule messages, inform about test files, mention rule quality checkers, and describe additional fields required by rules in the security category.
54
64
@@ -175,7 +185,7 @@ In addition to the fields mentioned above, rules submitted to Semgrep Registry h
175
185
- Cross-file (interfile) analysis requires `interfile: true` under the `options` key in YAML rules. For more information, see [Creating rules that analyze across files](/semgrep-code/semgrep-pro-engine-intro/#write-rules-that-analyze-across-files-and-functions).
176
186
:::
177
187
178
-
### Understanding rule namespacing
188
+
### Rule namespace
179
189
180
190
The namespacing format for contributing rules in the [Semgrep Registry](https://github.com/semgrep/semgrep-rules) is `<language>/<framework>/<category>/$MORE`. If the rule does not belong to a particular framework, add it to the language directory, which uses the word `lang` in place of the `<framework>` - `<language>/<lang>`.
181
191
@@ -235,7 +245,7 @@ For an example of a good rule message, see: [this rule for Django's `mark_safe`]
235
245
236
246
When you contribute rules to the Semgrep Registry, our quality checkers (linters) evaluate if the rule conforms to Semgrep, Inc. standards. The `semgrep-rule-lints` job runs linters on a new rule to check for mistakes, performance problems, and best practices for submitting to the Semgrep Registry. To improve your rule writing, use Semgrep itself to [scan semgrep-rules](https://semgrep.dev/blog/2021/how-we-made-semgrep-rules-run-on-semgrep-rules/).
237
247
238
-
### Including fields required by security category
248
+
### Fields required by the `security` category
239
249
240
250
Rules in category `security` in the Semgrep Registry require specific metadata fields that ensure consistency across the ecosystem in both Semgrep AppSec Platform and Semgrep CLI. Nest these metadata under the `metadata` field.
241
251
@@ -542,9 +552,7 @@ You can provide custom values. Sample values include:
542
552
- XML Injection
543
553
- XPath Injection
544
554
545
-
## Updating existing open source rules in Semgrep Registry
546
-
547
-
To update an existing open source rule, follow these steps:
555
+
## Update existing rules in Semgrep Registry
548
556
549
557
1. Find a rule you want to update in the [semgrep-rules](https://github.com/semgrep/semgrep-rules/) repository.
550
558
2. Submit a PR to the repository with your new update.
Copy file name to clipboardexpand all lines: docs/deployment/connect-scm.md
+37-19
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,7 @@ tags:
11
11
12
12
import Tabs from '@theme/Tabs';
13
13
import TabItem from '@theme/TabItem';
14
+
import PL from '@site/src/components/Placeholder';
14
15
15
16
# Connect a source code manager
16
17
@@ -52,11 +53,11 @@ If you opted to scan a GitHub or GitLab repository when you initially signed in,
52
53
1. Optional: If you have created more than one Semgrep account, select the account you want to make a connection for by clicking on the **Navigation bar > Your account name > The account you want to connect**.<br />
1. Go to **<iclass="fa-solid fa-gear"></i> Settings > Source code managers > Add > Azure DevOps**.
55
-
1. In the **Connect your Azure DevOps organization** dialog box, provide:
56
-
- The **Name of your Azure DevOps organization**
56
+
1. In the **Connect your Azure DevOps Project** dialog box, provide:
57
+
- The **Name of your Azure DevOps Project**. Ensure that the value you provide follows the format <PL>organization</PL>/<PL>project</PL>. This information can be seen in the project URL, for example `https://dev.azure.com/organization/project`.
57
58
- Your **Access token**. See [User personal access tokens](https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate) for information on generating a token.
58
59
2. Click **Connect** to save and proceed.
59
-
3. The Azure DevOps organization is now listed under **Source Code managers**. Click **Test** to verify that the new integration is installed correctly.
60
+
3. The Azure DevOps project is now listed under **Source code managers**. Click **Test** to verify that the new connection is installed correctly.
60
61
61
62
</TabItem>
62
63
<TabItemvalue='bitbucket-cloud'>
@@ -67,34 +68,46 @@ If you opted to scan a GitHub or GitLab repository when you initially signed in,
67
68
1. Go to **<iclass="fa-solid fa-gear"></i> Settings > Source code managers > Add > Bitbucket Cloud**.
68
69
1. In the **Connect your Bitbucket Workspace** dialog box, provide:
69
70
- The **Name of your Bitbucket Workspace**
70
-
- Your **Access token**. Semgrep expects a [workspace-level access token](https://support.atlassian.com/bitbucket-cloud/docs/create-a-workspace-access-token/).
71
+
- Your **Access token**. Semgrep requires a [workspace-level access token](https://support.atlassian.com/bitbucket-cloud/docs/create-a-workspace-access-token/).
71
72
1. Click **Connect** to save and proceed.
72
-
1. The Bitbucket project is now listed under **Source Code managers**. Click **Test** to verify that the new integration is installed correctly.
73
+
1. The Bitbucket project is now listed under **Source code managers**. Click **Test** to verify that the new connection is installed correctly.
73
74
74
75
</TabItem>
75
76
<TabItemvalue='github-cloud'>
76
77
78
+
### GitHub Cloud with GitHub SSO
79
+
80
+
These steps are for users that sign in to Semgrep through GitHub.
81
+
77
82
1. Sign in to [<iclass="fas fa-external-link fa-xs"></i> Semgrep AppSec Platform](https://semgrep.dev/login).
78
83
1. Optional: If you have created more than one Semgrep account, select the account you want to make a connection for by clicking on the **Navigation bar > Your account name > The account you want to connect**.<br />
1. From the **Navigation bar**, click **<iclass="fa-solid fa-gear"></i> Settings > Source code managers**.
81
-
1. Click **Connect to GitHub**.
86
+
1. Click **Add > GitHub**.
82
87
1. Review the permissions requested by Semgrep, then click **Continue**.
83
88
1. Click the organization you want to install Semgrep on.
84
89
1. Choose to authorize and install Semgrep for **<iclass="fa-regular fa-circle-dot"></i> All repositories** or **<iclass="fa-regular fa-circle-dot"></i> Only select repositories**.
85
90
1. Click **Install and authorize**.
86
91
1. After a successful link, you are signed out of Semgrep AppSec Platform automatically, as your credentials have changed after linking an organization.
87
92
1. Sign back in to Semgrep AppSec Platform.
88
93
89
-
</TabItem>
94
+
### GitHub Cloud with non-GitHub SSO
90
95
91
-
<!-- removed temporarily because we're using the "old flow"
- **Leave PR comments** refers to Semgrep's capability to post findings to developers in PRs.
95
-
:::
96
+
These steps are for users that sign in to Semgrep through a **non-GitHub** SSO provider.
97
+
98
+
1. Navigate to the following link: [<iclass="fas fa-external-link fa-xs"></i> Semgrep GitHub app](https://github.com/marketplace/semgrep-dev) and install the Semgrep GitHub app onto the GitHub org you want to connect to.
99
+
1. Sign in to [<iclass="fas fa-external-link fa-xs"></i> Semgrep AppSec Platform](https://semgrep.dev/login) using SSO.
100
+
1. Optional: If you have created more than one Semgrep account, select the account you want to make a connection for by clicking on the **Navigation bar > Your account name > The account you want to connect**.<br />
1. From the **Navigation bar**, click **<iclass="fa-solid fa-gear"></i> Settings > Source code managers**.
103
+
1. Click **Add > GitHub**.
104
+
1. In the **Name of your GitHub Organization** field, enter the slug of the org that the app was installed on in step 1. For example, if the GitHub URL of your org is `https://github.com/acme-corp`, then the slug is typically `acme-corp`.
105
+
1. Leave the access token field empty.
106
+
1. Click **Connect**.
107
+
1. Your GitHub org is now listed under **Source Code managers**. Click **Test** to verify that the new connection is installed correctly.
108
+
109
+
</TabItem>
96
110
97
-
-->
98
111
99
112
<TabItemvalue='gitlab-cloud'>
100
113
@@ -106,7 +119,7 @@ If you opted to scan a GitHub or GitLab repository when you initially signed in,
106
119
1. Enter the personal access token generated into the **Access token** field.
107
120
1. Enter your GitLab group's name into the **Name of your GitLab Group** field. If your repositories are organized in subgroups, you only need to provide the name of the top-level group.
108
121
1. Optional, but recommended: if you have multiple GitLab groups in your GitLab account, create a source code manager per group. Repeat steps 1, 3-4 for each GitLab group.
109
-
1. The GitLab groups are now listed under **Source code managers**. Click **Test** to verify that the new integration is configured correctly.
122
+
1. The GitLab groups are now listed under **Source code managers**. Click **Test** to verify that the new connection is configured correctly.
110
123
111
124
You have successfully connected an org in Semgrep AppSec Platform with an organization in your source code management tool.
112
125
@@ -126,16 +139,21 @@ You have successfully connected an org in Semgrep AppSec Platform with an organi
126
139
127
140
<TabItemvalue='bitbucket-data-center'>
128
141
142
+
143
+
1. Create an HTTP Access Token for your project following the steps outlined in [<iclass="fas fa-external-link fa-xs"></i> Bitbucket Data Center documentation](https://confluence.atlassian.com/bitbucketserver/http-access-tokens-939515499.html). Ensure that the access token is created with `PROJECT_ADMIN` permissions.
144
+
1. Copy the token for use in the next steps.
129
145
1. Sign in to [<iclass="fas fa-external-link fa-xs"></i> Semgrep AppSec Platform](https://semgrep.dev/login).
130
146
1. Optional: If you have created more than one Semgrep account, select the account you want to make a connection for by clicking on the **Navigation bar > Your account name > The account you want to connect**.<br />
1. Go to **<iclass="fa-solid fa-gear"></i> Settings** > **Source code managers**, and click **Add > Bitbucket Data Center**.
133
149
1. In the **Connect your Bitbucket project (key)** dialog box, provide:
134
150
- The **Name of your Bitbucket project (key)**. This must be the project key, which you can find by navigating to `<YOUR_BITBUCKET_DATA_CENTER_BASE_URL>/projects`.
135
-
- The **URL** to access your installation of Bitbucket Data Center
136
-
- The **Access Token** that [grants Semgrep permission to communicate with your project](https://confluence.atlassian.com/bitbucketserver/http-access-tokens-939515499.html). Semgrep expects a [workspace-level access token](https://support.atlassian.com/bitbucket-cloud/docs/create-a-workspace-access-token/)
137
-
2. Click **Connect** to save and proceed.
138
-
3. The Bitbucket project is now listed under **Source code managers**. Click **Test** to verify that the new integration was installed correctly.
151
+
- The **URL** to access your installation of Bitbucket Data Center; this is your fully-qualified domain name.
152
+
- The **Access Token** that grants Semgrep permission to communicate with your project. Semgrep expects an [HTTP access token](https://confluence.atlassian.com/bitbucketserver/http-access-tokens-939515499.html) with `PROJECT_ADMIN` permissions.
153
+
1. Click **Connect** to save and proceed.
154
+
1. The Bitbucket project is now listed under **Source code managers**. Click **Test** to verify that the new connection was installed correctly.
1. Optional: Click **Auto scan** to onboard all current and future repositories under your project to Semgrep Managed Scanning.
139
157
140
158
</TabItem>
141
159
<TabItemvalue='github-enterprise'>
@@ -214,7 +232,7 @@ Connect Semgrep and GitLab Self-Managed accounts by creating a PAT and providing
214
232
1. Enter your GLSM base URL into the **URL** field.
215
233
1. Enter your GitLab group's name into the **Name of your GitLab Group** field. If your repositories are organized in subgroups, you only need to provide the name of the top-level group.
216
234
1. If you have multiple GitLab groups in your GitLab account, you need to create a source code manager per group. Repeat steps 1, 3-5 for each GitLab group.
217
-
1. The GitLab groups are now listed under **Source Code managers**. Click **Test** to verify that the new integration is installed correctly.
235
+
1. The GitLab groups are now listed under **Source Code managers**. Click **Test** to verify that the new connection is installed correctly.
Copy file name to clipboardexpand all lines: docs/deployment/create-account-and-orgs.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,7 @@ Semgrep organizations can be **connected** to equivalent GitHub, GitLab, and SSO
80
80
81
81
### Next steps for Bitbucket and Azure Repos users
82
82
83
-
- Connect your Semgrep org to your Bitbucket Data Center project or your Azure DevOps organization. Refer to [<iclass="fa-regular fa-file-lines"></i> Connect a source code manager](/deployment/connect-scm) for steps.
83
+
- Connect your Semgrep org to your Bitbucket Data Center project or your Azure DevOps project. Refer to [<iclass="fa-regular fa-file-lines"></i> Connect a source code manager](/deployment/connect-scm) for steps.
84
84
- To add members to your Semgrep organization, set up [<iclass="fa-regular fa-file-lines"></i> SSO authentication](/deployment/sso).
0 commit comments