Set up GitLab merge request comments
- You have gained the necessary resource access and permissions required for deployment.
- You have created a Semgrep account and organization.
- You have connected your source code manager.
- Optionally, you have set up SSO.
- You have successfully added a Semgrep job to your CI workflow with diff-aware scanning.
Semgrep can create merge request (MR) comments in your GitLab repository. These comments provide a description of the issue detected by Semgrep and may offer possible solutions. These comments are a means for security teams, or any team responsible for creating standards, to help their fellow developers write safe and standards-compliant code.
Automated comments on GitLab merge requests are displayed as follows:
Figure An inline GitLab merge request comment.
Conditions for MR comment creation
MR comments appear for the following types of scans under these conditions:
| Type of scan | Product name | Trigger condition | How to set up |
|---|---|---|---|
| Static application security testing (SAST) | Semgrep Code | A comment appears when a finding is generated by a rule in Comment or Block mode. This means you can fully customize what comments your developers receive. | Complete the steps in the following sections: |
| Software composition analysis (SCA) | Semgrep Supply Chain (SSC) | A comment appears based on the conditions you explicitly set in a Supply Chain policy or when Semgrep detects a license violation. | To receive Supply Chain comments, complete the steps in Confirm account connection and access and set up a policy. To receive license violation comments, enable dependency search. |
| Secrets | Semgrep Secrets | A comment appears when a finding is generated by a rule in Comment or Block mode. A comment also appears for invalid findings and validation errors if these conditions are set to Comment or Block mode. | Complete the steps in the following sections: |
Comments from Supply Chain scans include the following information:
- Risk
- A description of the vulnerability, including the types of attack it is vulnerable to.
- Fix
- Indicates what versions to upgrade to, if any, that resolves or eliminates the vulnerability.
- Reference
- A link to additional information about the vulnerability from its source, such as the GitHub Advisory Database and the National Vulnerability Database (NVD), if available.
Steps to set up MR comments
Prerequisites
In addition to finishing the previous steps in your deployment journey, it is recommended to have completed a full scan on your default branch for the repository in which you want to receive comments.
Confirm your Semgrep account's connection
PR comments are enabled by default for users who have connected their GitLab group to Semgrep AppSec Platform. Confirm that you have the correct connection and access:
- In your Semgrep AppSec Platform account, click Settings > Source code managers.
- Check that an entry for your GitLab group exists and is correct.
Triage through MR comments
Developers can triage Semgrep findings without leaving GitLab by responding to the MR comments authored by Semgrep. To use this feature, you must have a paid GitLab plan, and must update your source code manager (SCM) connection to use an access token with an elevated role. This allows you to enable webhooks, which Semgrep requires for the triage through MR comments feature.
Ensure that you're using one of the following GitLab plans:
- GitLab Premium
- GitLab Ultimate
- GitLab Self Managed
- Log in to GitLab, and create an access token with access to the desired GitLab groups. Assign the
apiscope and one of the following roles:MaintainerOwnerAdmin
- Return to Semgrep and sign in.
- Go to Settings > Source code managers, and find your GitLab connection.
- Click Update access token.
- In the Update access token dialog that appears, provide the new token you created. Click Update to save and proceed.
- Toggle the Incoming webhooks setting on.
Once you've successfully enabled webhooks and the Triage via code review comments toggle is on, you can change the role for the token you provide to Semgrep to one that's more restrictive, such as Developer.
Configure comments for Semgrep Code
In addition to setting up the connection between Semgrep and GitLab, you must assign rules to Comment or Block mode. This customization enables you to:
- Manage the amount of MR comments your developers receive.
- Ensure that only rules that meet your criteria, such as high severity or high confidence rules, produce comments visible to developers, reducing noise.