Tutorial: SAST code scans using Semgrep
Scan a codebase using Semgrep
This tutorial shows you how to scan your codebases using Semgrep, a popular tool for detecting vulnerabilities in application code. Semgrep can scan a wide variety of languages and includes a free version for individuals who want to scan files locally.
In this tutorial, you'll set up a simple pipeline with a Semgrep step running in orchestration mode.

Set up your pipeline
Do the following:
Select Security Testing Orchestration (left menu, top) > Pipelines > Create a Pipeline. Enter a name and click Start.
In the new pipeline, select Add stage > Security.
Under Configure Codebase, select the connector to your Git account.
In Repository Name, open the value-type pulldown (right) and select Runtime Input.

Configure codebase to specify repository at runtime Go to Infrastructure and select Cloud, Linux, and AMD64 for the infrastructure, OS, and architecture.
Add the Semgrep step
In Execution, click Add step and select Semgrep.
In the Semgrep step, verify that the Scan mode is Orchestration.
Set Fail on Severity to Medium.
Apply your changes and save the pipeline.
Run the pipeline and check your results
Run the pipeline: click Run (top right). The Run Pipeline dialog box appears.
Enter the repository and branch to scan.
When you scan a codebase for the first time, the standard practice is to scan the root branch. This is usually the
mainormasterbranch.Run the pipeline and then wait for the execution to finish.
If the scan detected any critical vulnerabilities, the pipeline fails with the message
Exited with message: fail_on_severity is set to critical and that threshold was reached.
pipeline failed, critical issues found Select Vulnerabilities and examine any issues detected by your scan.

view scan results
Specify the baseline
Select Test Targets (left menu).
Select the baseline you want for your target.

YAML pipeline example
Here's an example of the pipeline you created in this tutorial. If you copy this example, update YOUR_GIT_CONNECTOR_ID with your codebase connector.
Last updated
Was this helpful?