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.
Prerequisites
Before proceeding, see Prerequisites to ensure that your machine meets Semgrep’s requirements.Set up Semgrep
Install the Semgrep CLI tool and confirm the installation:Log in to your Semgrep account
Log in to your Semgrep account. Running this command launches a browser window, but you can also use the link that’s returned in the CLI to proceed:
Turn on cross-file analysis
To turn on cross-file analysis, which allows you to detect vulnerabilities across files and folders:In Semgrep AppSec Platform, go to Settings > General > Code.
Scan your project
Semgrep provides two commands that you can use to start a scan from the CLI:semgrep scan- This is the recommended command for scanning local codebases or scanning a project when you don’t have a Semgrep account. It is also recommended for writing and testing custom rules.semgrep ci- This is the recommended command if you are scanning Git repositories with Semgrep as part of an organization with custom rules and policies.semgrep cifetches your organization’s scan configurations from Semgrep AppSec Platform.
The JSON schema for Semgrep’s CLI output is in semgrep/semgrep-interfaces.In addition to the
--text, --json, and --sarif flags, which set the primary output formats, and the --output=<value> flag that saves the results to a file or posts to a URL, you can append --<format>-output=<file> to obtain additional output streams:
<format>: text, json, sarif, gitlab-sast, gitlab-secrets, junit-xml, emacs, vim
Test custom rules
Semgrep includes features to test the custom rules that you write:Publish custom rules
To share your rules by adding them to the Semgrep Registry:Scan without sending results to Semgrep
To scan your project using the configuration you’ve set up in Semgrep AppSec Platform without sending scan results to Semgrep, use:Scan using Semgrep CE analysis (single-function)
To scan your project using exclusively open source Semgrep, even though you have proprietary cross-file analysis enabled in Semgrep AppSec Platform:INFOSee Semgrep AppSec Platform versus Semgrep Community Edition for information on the differences between Semgrep’s proprietary and open source analyses.
Scan using specific Semgrep products
When you runsemgrep ci, you scan your project with any product that is enabled in Semgrep AppSec Platform. To scan your project with just one product, run:
Extend timeout thresholds
Depending on the file sizes in your project, you may need to increase the timeout threshold so that Semgrep doesn’t time out before the scan completes. You can control this value with the--timeout flag, which specifies the maximum time Semgrep spends scanning a single file. The default value is 5 seconds. Semgrep attempts to scan each file with this timeout value three times, but you can change this using the --timeout-threshold flag:
Improve performance for large codebases
You can set the number of subprocesses Semgrep uses to run checks in parallel:-j = 1 if you’re passing in --pro. For additional information, see Parallelization.
Set log levels
Semgrep provides three levels of logging:| Log level | Flag | Description |
|---|---|---|
| Default | None | Prints scan progress, findings information, warnings, and errors. |
| Verbose | -v or --verbose | Includes everything printed when using the default logging level, adding a list of rules and details such as skipped files. |
| Debug | --debug | Logs the entire scan process at a high level of detail. |
Example usage
To set the logging level for a scan, include the flag when scanning your project:Exit codes
The CLI commandssemgrep ci and semgrep scan finish with exit code 0 as long as the scan completes, regardless of whether there were findings. To finish with exit code 1 when there are findings:
- Configure blocking rules
- Pass in the
--errorflag when runningsemgrep scan.
semgrep ci, you can pass in the --no-suppress-errors if you don’t want internal errors suppressed.