By design, Semgrep open source software, Semgrep Community Edition (CE) can only analyze interactions within a single function, also known as intraprocedural analysis. This limited scope makes Semgrep CE fast and easy to integrate into developer workflows. Semgrep Code runs cross-function (interprocedural) analysis by default, and gives security teams the option to trade off speed for better results and deeper analysis with cross-file analysis. By analyzing interactions across files and functions, Semgrep Code can reduce noise, uncover new vulnerabilities, and make results easier to understand.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.
LANGUAGE SUPPORTRefer to Supported languages to see languages supported by Semgrep Code.
Run cross-file analysis
This section guides you through installing the proprietary cross-file (interfile) analysis binary and helps you to scan your projects both in CLI and with Semgrep AppSec Platform.Run cross-file analysis with Semgrep AppSec Platform
PREREQUISITEYou have completed a Semgrep core deployment.
Sign in to Semgrep AppSec Platform.
Go to Settings > General > Code.
Ensure that you have the default ruleset added in your Policies page. If this ruleset is not added, go to Semgrep Registry - Default ruleset page, then click Add to . For best results, set this ruleset to the Monitor rule mode.
Run cross-file analysis in the CLI
PREREQUISITE
- Local installation of Semgrep CLI. See Getting started with Semgrep to install Semgrep CLI.
Sign up or sign in to Semgrep AppSec Platform.
For first-time users, click Create an organization. Note that you can further integrate organizations (orgs) with GitLab accounts and GitHub accounts, including personal and org accounts, after you complete this procedure.
Go to Settings > General > Code.
Update cross-file analysis in the CLI
uses a separatesemgrep binary. To update to the latest version, follow these steps:
Update your Semgrep CLI tool with the following command:Alternatively, using pipx (https://pipx.pypa.io/stable/how-to/install-pipx/) or uv (https://docs.astral.sh/uv/):
- macOS
- Linux
- Windows
- Docker
Write rules that analyze across files and functions
To create rules that analyze across files and functions, addinterfile: true under the options key when defining a rule. This key tells Semgrep to use the rule for both cross-function and cross-file analysis.
Cross-function example
The following example shows how to define theinterfile key (see the Rule pane) and the resulting cross-function analysis in the Test code pane.
userInput() source was called in main() while the exec() sink was called in the DockerCompose class.
Interact with the rule widget to compare Semgrep Community Edition (CE) and Semgrep Code. In the Rule pane, you can remove the lines:
Known limitations of cross-file analysis
CommonJS
Currently Semgrep’s cross-file analysis does not handle specific cases of CommmonJS where you define a function and assign it to an export later. does not track the code below:Regressions in cross-file analysis
resolves names differently than Semgrep CE’s analysis. Consequently, rules withinterfile: true may produce different results than Semgrep CE. Some instances could be regarded as regressions; if you encounter them, please file a bug report. When you need to report a bug in Semgrep’s cross-file analysis, go through Semgrep Support. You can also contact us through Semgrep Community Slack group.
Appendix
Types of Semgrep Code analysis
Cross-file (interfile) analysis- Cross-file analysis finds patterns spanning multiple files within a project to help security engineers deeply understand their organization’s security issues. This analysis reduces noise and detects issues that Semgrep CE can’t find.
- Cross-file analysis runs on full scans. These scans may take longer to complete and can use more memory than Semgrep CE scans. See the available languages for cross-file analysis in Supported languages.
- In Semgrep Code, cross-file analysis includes cross-function analysis as well.
- Cross-function analysis finds patterns within a single file spanning code blocks and functions.
- Semgrep Code scans run cross-function analysis by default.
- See an example of cross-function analysis in Semgrep Code cross-function example.
- See the available languages for cross-function analysis in Supported languages.
Semgrep Code cross-file CI scan issues
To provide reliably completed scans, Semgrep Code can fall back from cross-file analysis to single-file analysis. This ensures that in the vast majority of cases, scans run successfully. By default, if a scan uses more than 5 GB of memory during cross-file pre-processing, the scan uses single-file analysis to ensure lower memory consumption. Similarly, if a cross-file scan doesn’t complete after 3 hours, the analysis times out and Semgrep re-scans the repository using single-file analysis. Typically, this happens because the repository is very large. If 1-2 repositories cause CI scan issues and scanning these repositories with interfile analysis is not critical, modify your configuration file to usesemgrep ci --pro-intrafile. This overrides the Semgrep AppSec Platform setting for these repositories, and always runs these scans with single-file, cross-function analysis.
If many repositories cause scan issues, or you have critical repositories you are unable to scan with Semgrep’s interfile analysis:
Disable the toggle in the Settings > General > Code page of your organization.
Review scan troubleshooting guides such as A Semgrep scan is having a problem - what next? or Troubleshooting “You are seeing this because the engine was killed.”
If you need additional guidance, contact Semgrep Support, or reach out to the Semgrep team in the Semgrep Community Slack so we can help you resolve the issue and create a plan for your organization.