Skip to main content
YOUR DEPLOYMENT JOURNEY
Semgrep can create pull request (PR) comments in your Bitbucket 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.

Conditions for PR comment creation

PR comments appear for the following types of scans under these conditions:

Supported Bitbucket plans

  • Any of the following Bitbucket plans are supported:
    • Cloud Free
    • Standard
    • Premium
There are two ways in which you can integrate Semgrep comments into Bitbucket depending on the Bitbucket plan you use:
  • Workspace access token: If you use the Bitbucket Cloud Premium plan, you can create a workspace access token. This option saves time because you can create one access token for all repositories in the workspace. With one workspace access token, you can bulk-onboard more repositories at once from a whole workspace. However, you can also use the option of a repository access token to onboard repositories one by one.
  • Repository access token: If you do not have the Bitbucket Cloud Premium plan, create a separate repository access token for each repository where you want to use Semgrep. This configuration option is also useful if you have the Bitbucket Cloud Premium plan, but prefer to onboard repositories one by one instead of bulk onboarding.

Create and add a workspace access token

PREREQUISITE
  • Bitbucket Cloud Premium plan. If you do not have a Bitbucket Cloud Premium plan, create a repository access token.
Create a workspace access token in Bitbucket (only available if you have a Bitbucket Cloud Premium plan):
1
Create a workspace access token in Bitbucket with Read and Write permissions for the Pull requests scope. Follow the instructions in Create a workspace Access Token in Bitbucket documentation.
2
Add the workspace access token as a workspace variable with the Secured option.
Continue setting up Bitbucket PR comments by finishing the rest of this guide.

Enable PR comments in Bitbucket

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.
  • You must have a Bitbucket Cloud workspace access token or a repository access token.

Confirm your Semgrep account’s connection

Confirm that you have the correct connection and access:
1
In your Semgrep AppSec Platform account, click Settings > Source code managers.
2
Check that an entry for your Bitbucket workspace exists and is correct.

Triage through PR comments

Developers can triage Semgrep findings without leaving Bitbucket by responding to the PR comments authored by Semgrep. To use this feature, you must have Bitbucket Cloud Premium and update your source code manager (SCM) connection to use a workspace access token. Workspace-level webhooks are not available on Bitbucket Cloud Free or Standard; Semgrep requires webhooks for the triage through PR comments feature. To update your connection between Semgrep and Bitbucket:
1
Log in to Bitbucket using an account assigned with the Product Admin role.
2
Create a workspace access token. Ensure that you assign the following scopes to the token:
  • webhook (read and write)
  • repository (read and write)
  • pullrequest (read and write)
  • project (admin)
  • account (read)
3
Return to Semgrep and sign in.
4
Go to Settings > Source code managers, and find your Bitbucket connection.
5
Click Update access token.
6
In the Update access token dialog that appears, provide the new token you created. Click Update to save and proceed.
7
Toggle the Incoming webhooks setting on.
Once you’ve enabled webhooks, turned on the Allow developers to triage findings toggle, and enabled triage through code review comments, developers can triage Semgrep findings from Bitbucket Cloud.

Set up the configuration file

The logic to determine whether Semgrep runs a full scan or a diff-aware scan on a pull request is defined in the bitbucket-pipelines.yml file. For PR comments and accurate diff-aware scan analysis to work, you must set SEMGREP_BASELINE_REF, which defines the repository’s default branch used as the comparison baseline, such as main or master. Specifying the default branch helps Semgrep understand the differences between the current branch and the main line of development and to generate meaningful results and PR comments.

Configure PR comments

Once you have set up the connection between Semgrep and Bitbucket, you can create a remediation policy that lets you define the conditions under which Semgrep leaves a pull request comment. This customization enables you to:
  • Manage the amount of PR 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.

Receive comments in an access-controlled Bitbucket account

Bitbucket Premium provides access control features for content that your individual account owns. If you use this feature, you need to add several IP addresses into your allowlist. If you are behind a firewall, are using a virtual private network (VPN), or have network restrictions regarding access, you may need to add the following IP addresses to the ingress allowlist and egress allowlist:

Additional egress IP addresses

You must also add CloudFront IP addresses to your egress allowlist. Refer to Locations and IP address ranges of CloudFront edge servers for a list of IP addresses.

Test your configuration

Test that you are able to receive findings by manually triggering a scan through your CI provider. Receiving PR or MR comments may require additional steps depending on the custom configuration of your VPN or SCM (for example, if you use a static IP without a hostname). Reach out to Semgrep Support with any concerns.
INFOOnly rules set to the Comment and Block rule modes in the Policies page create PR comments.

Optional features

Customize PR comments

You can customize the comments Semgrep leaves on your PR. Custom comments allow you to direct your teams to the resources they need to handle the vulnerabilities Semgrep identifies in their code. To provide custom PR comments:
2
Navigate to Settings > General > Global.
3
Go to the Custom PR/MR comments footers section.
4
Provide a custom comment for each Semgrep product whose findings you want to generate a PR comment. Semgrep supports Markdown and plaintext links in your message.
5
Click Save changes.

Enable Rule-defined fix in Bitbucket Cloud repositories

Autofix is a Semgrep feature in which rules contain suggested fixes to resolve findings. To enable Rule-defined fix for all projects in your Semgrep AppSec Platform organization, follow these steps:
1
In Semgrep AppSec Platform, go to Settings > General > Code.
2
Use the Rule-defined fix toggle to enable this feature.

Next steps

You’ve finished setting up a core deployment of Semgrep 🎉.

Additional references

Why am I not receiving PR or MR comments?

Why did the comments on a PR or MR not appear inline?