Semgrep

A static analysis tool that checks source code against rules written in a code-like syntax. You can write your own rule to find risky patterns.

cat semgrep/meta.ymlChecked on 2026-10-28

Safety

Impact Local onlyStays on your machine and sends nothing out
Admin rights
Not required
Test lab
Not required

Usage

Purpose
Defense
Difficulty
Intermediate
Type
Command line
Platforms
Linux / macOS / Windows / Docker

Trust

Repository
semgrep/semgrep
License
CopyleftLGPL-2.1(エンジン)。公式ルールは Semgrep Rules License v1.0
GitHub
stars17,7532026-11-17
Maintenance
Actively updatedLast update 2026-11-17
Contents
  1. Introduction
  2. What Semgrep does
  3. Read the license by component
  4. How Opengrep relates to Semgrep
  5. Network traffic
  6. Try it safely: confirm detection with one rule you write
  7. Main uses
  8. How it differs from Gitleaks, TruffleHog, OSV-Scanner, and ShellCheck
  9. Notes
  10. Read next
  11. Sources

Semgrep reads source code and looks for the patterns you define. Its README calls it “semantic grep for code.” Unlike grep, which searches text, it matches on what the code means. You write a rule in a form that looks like the code you want to find.

This review is for developers who want to check their own or their company’s code. After reading it, you can do the following:

  • Run one rule you wrote yourself against a small file of deliberately risky code, and confirm that it is detected
  • Tell which ways of running Semgrep send data out, and turn off metrics
  • Explain how the licenses of the engine, the official rules, and Opengrep relate to each other

What Semgrep does

  • Searches by pattern: you write a pattern in the shape of the code, such as eval($X). $X matches any expression, and ... matches any number of arguments or statements.
  • Lets you write your own rules: a YAML file with an id, message, severity, languages, and a pattern. You can narrow a pattern with pattern-not or combine several.
  • Reads many languages: the README lists more than 30 for Semgrep Code (it does not say these are CE’s alone), including Python, JavaScript, TypeScript, Go, Java, Ruby, PHP, C, Bash, Dockerfile, Terraform, and YAML.
  • Exports results: besides the terminal output, it can write JSON and SARIF files. With --error, it exits with code 1 when it finds something, so you can fail a CI job.
  • Tests rules: put test code next to a rule and run semgrep --test to check which lines are detected and which are not.
What it doesn’t doSemgrep CE (Community Edition) follows data flow only within one function or one file. The README warns that for security work it will miss many true positives. Analysis across files is a feature of Semgrep AppSec Platform, which you use after logging in. CE suits one-off checks where you can tolerate false positives.

Read the license by component

Semgrep’s license differs by component. On December 13, 2024, the license of the official rules changed.

Component License Source
Engine (Semgrep CE) LGPL 2.1 The repository’s LICENSE file, the official Licensing page
Official rules (the rules in semgrep-rules) Semgrep Rules License v1.0 The official blog, the Licensing page
Rules published by other parties Their original licenses The Licensing page
Semgrep Code, Supply Chain, Secrets, AppSec Platform Proprietary (Terms of Service) The Licensing page

The official blog says the engine remains LGPL 2.1. The same post also says that some internal JSON and SARIF fields are now reserved and that experimental features moved to the engine you get after logging in. The PyPI metadata also says LGPL-2.1-or-later.

The official rules are no longer under an open source license. The official Licensing page describes Semgrep Rules License v1.0 as allowing use for internal business purposes only. The license text does not allow you to distribute the rules or offer them to others as a service. Before that, the rules were under LGPL 2.1 with the Commons Clause. The official blog says the change targets vendors that use the official rules in competing products or SaaS. It says individuals and companies that scan their own code in-house are not affected.

The LICENSE file in semgrep-rules is a single line with the URL of this license. GitHub’s automatic detection reports it as “NOASSERTION.”

Rules from other parties’ repositories keep their original licenses. The official docs give Trail of Bits rules under AGPL-3.0 as an example. Check the license field of each rule before you adopt it.

The “Try it safely” steps in this review use only a rule you write yourself, so the official rules’ license does not limit you.

How Opengrep relates to Semgrep

Opengrep is a separate project forked from Semgrep CE. According to the official docs, it split off at v1.100.0 and uses the same LGPL 2.1 license as the engine. It is run by a different organization from Semgrep, Inc., and several security companies back it.

The two sides give different reasons for the split. Opengrep’s README says Semgrep moved key features behind a commercial license. Semgrep’s blog describes the same change as an update to separate the free CE from its commercial products and to make clear that competing vendors cannot use the official rules. This review does not take either side.

The official docs list these differences. The comparison page is written by Semgrep, so read it together with Opengrep’s README.

Semgrep CE Opengrep
Rules Official rules from the registry are available No ruleset of its own. You bring your own rules
Analysis scope One function or one file --taint-intrafile follows data across functions inside one file
Distribution A Python package A standalone binary (signed with Cosign)
Upgrade path You can move to AppSec Platform None

The docs say both run natively on Windows and share the rule syntax. There is also an opengrep/opengrep-rules repository, split from semgrep-rules on December 13, 2024. Its LICENSE file carries a Commons Clause plus LGPL 2.1 notice. This review does not judge whether that notice can be relied on.

Network traffic

Semgrep reads the code you scan on your own computer. The README says it does not upload code by default. Whether it sends anything depends on how you load rules.

How you run it Traffic
--config rule.yaml (a local file) No metrics are sent if you are not logged in. They are sent while you are logged in (README, CLI reference)
--config auto, --config p/python, and so on Fetches rules from the registry. With the default setting (auto), metrics are sent too
semgrep login, semgrep ci Connects to your account. Results go to AppSec Platform
semgrep install-semgrep-pro Requires login

The official CLI reference lists semgrep scan --config auto as the quick way to start. It uses registry rules, so it sends traffic. According to the reference, --config auto logs in to the registry with your project URL.

The official docs describe the metrics:

  • Sent: the Semgrep version, run time, an anonymous user ID, your IP address, the value of the CI environment variable, how Semgrep was installed, hashes of the project name and rule definitions, the number of findings, and the languages and options used. If you use a registry ruleset, its name is sent in plain text.
  • Not sent: source code and private rules. File names, commit information, and finding messages are sent only when you explicitly ask for it, for example with semgrep ci.
  • Stored locally: the anonymous ID is saved in ~/.semgrep/settings.yml.

To stop metrics, add --metrics=off or set the environment variable SEMGREP_SEND_METRICS=off. --config auto cannot be combined with --metrics=off; the run stops with an error and exit code 2. To keep metrics off, use local rules or a named ruleset such as p/python. Tools that wrap Semgrep may turn metrics on by default. The official docs give GitLab’s Semgrep SAST analyzer as an example.

--enable-version-check is on by default and checks a Semgrep server for the latest version. Add --disable-version-check to stop it. In the 1.182.1 source, the check is a GET to https://semgrep.dev/api/check-version. It carries a User-Agent, plus your credentials while you are logged in.

Try it safely: confirm detection with one rule you write

These steps stay on your own computer. The rule format and the use of --test follow the examples in the official docs. We ran them on October 28, 2026, on Windows 11 with Semgrep 1.182.1 in a Python 3.12 virtual environment. We have not tried macOS or Linux. The exact output can differ between versions.

  1. Check that Python 3.10 or later is installed, then install Semgrep with pipx. The official instructions do not ask for administrator rights.

    pipx install semgrep

    The official docs recommend pipx on macOS, Linux, and Windows. With uv, run uv tool install semgrep. Homebrew’s brew install semgrep is maintained on a best-effort basis and can lag behind the latest release. The README also shows python3 -m pip install semgrep and the Docker image semgrep/semgrep.

  2. Create an empty working folder and put the rule file detect-eval.yaml in it. The rule looks for eval called with a non-constant value. The message is in English to avoid garbled text.

    rules:
      - id: my-eval-with-variable
        languages: [python]
        severity: ERROR
        message: eval() is called with a non-constant value. The input may run as code.
        patterns:
          - pattern: eval($X)
          - pattern-not: eval("...")
  3. In the same folder, put a file of deliberately risky code, detect-eval.py. The comments are the markers the test in step 6 uses.

    user_input = input("expression: ")
    # ruleid: my-eval-with-variable
    print(eval(user_input))
    # ok: my-eval-with-variable
    print(eval("1 + 1"))
  4. Turn off metrics and the version check, and scan with only the local rule.

    semgrep scan --config detect-eval.yaml --metrics=off --disable-version-check .
  5. Read the result. You should see exactly one finding, the eval(user_input) line, with the rule id and message. eval("1 + 1") is excluded by pattern-not, so it does not appear.

  6. Check that the rule behaves as intended with --test. If only the marked line is detected, you see “All tests passed,” the same as in the official example.

    semgrep --test --metrics=off --disable-version-check .
  7. Fix the code. Add import ast at the top of the file, change eval(user_input) to ast.literal_eval(user_input) from Python’s standard library, and run step 4 again. If it reports 0 findings, this rule no longer finds the problem.

When you finish, delete the working folder.

Main uses

What you want How
Scan with a local rule semgrep scan --config rule.yaml <folder>
Search for a pattern once semgrep -e '$X == $X' --lang=py <folder> (the README’s example)
Write results to SARIF or JSON --sarif --sarif-output=out.sarif, --json-output=out.json
Fail CI when there is a finding --error (exit code 1 on findings)
Skip a folder or a rule --exclude <pattern>, --exclude-rule <id>
Suppress a false positive on one line Add a nosem comment at the end of the line (on by default)
Check an automatic fix --autofix with --dryrun (--dryrun prints the changes without writing them)

You can repeat --config. For example, --config p/python --config myrules/myrule.yaml uses a registry ruleset and your own rule together. A run that includes the first one sends traffic, as the table above shows.

How it differs from Gitleaks, TruffleHog, OSV-Scanner, and ShellCheck

All of these protect your code, but they look for different things.

What it looks for How it holds rules
Semgrep Risky patterns in the code you wrote You write pattern rules. Official rulesets exist too
Gitleaks, TruffleHog Secrets that slipped into the code They ship built-in definitions of what secrets look like
OSV-Scanner Known vulnerabilities in the dependencies you use It matches against a vulnerability database
ShellCheck Mistakes in shell scripts It ships a fixed set of shell-specific warnings

In Semgrep, secrets detection and dependency scanning belong to products you use after logging in (Semgrep Secrets and Semgrep Supply Chain). They are outside CE.

You can split the work like this: Gitleaks for secrets, OSV-Scanner for dependencies, ShellCheck for shell scripts, and Semgrep for how the rest of your own code is written.

Notes

  • Scan only your own code or code you have permission to scan.
  • Finding nothing does not prove the code is safe. CE follows data only within one function or file, and it finds only the shapes your rules describe.
  • Do not redistribute the official rules or build them into a service you offer to others. Scanning your own code in-house is within the license. When you need a ruling, read the license text and the official blog.
  • --autofix rewrites files according to the rule’s fix. Commit your changes first and check the result with --dryrun.
  • Read third-party rules before you use them. A rule can define a fix, so check what it would rewrite.
  • semgrep ci scans nothing if you are not logged in. By default it still exits with code 0, so CI looks green (with --no-suppress-errors it exits with 13). If you do not log in, use semgrep scan.
  • Sources disagree on Windows support. The official blog announced Windows support without WSL in November 2025, and PyPI has a win_amd64 file. But the official prerequisites page still says “Windows (beta)” as of October 28, 2026.
  • Semgrep 1.183.0 and later do not support Intel Macs. 1.182.x is the last supported release.
  • Open result files (SARIF or JSON) and check their contents before you share them.

Sources

  1. Official repository README (semgrep/semgrep)github.com/semgrep/semgrep
  2. LICENSE (engine, LGPL 2.1)github.com/semgrep/semgrep/blob/develop/LICENSE
  3. Official rules repository (semgrep/semgrep-rules)github.com/semgrep/semgrep-rules
  4. Semgrep Rules License v. 1.0semgrep.dev/legal/rules-license
  5. Important updates to Semgrep OSS (2024-12-13)semgrep.dev/blog/2024/important-updates-to-semgrep-oss/
  6. Official docs: Licensingsemgrep.dev/docs/licensing
  7. Official docs: Compare Semgrep to Opengrepsemgrep.dev/docs/faq/comparisons/opengrep
  8. Opengrep official repository (opengrep/opengrep)github.com/opengrep/opengrep
  9. Official docs: Semgrep metricssemgrep.dev/docs/metrics
  10. Official docs: CLI referencesemgrep.dev/docs/cli-reference
  11. Official docs: Prerequisitessemgrep.dev/docs/prerequisites
  12. Official docs: Local scans with Semgrepsemgrep.dev/docs/getting-started/cli
  13. Official docs: Rule structure syntaxsemgrep.dev/docs/writing-rules/rule-syntax
  14. Official docs: Test rulessemgrep.dev/docs/writing-rules/testing-rules
  15. Semgrep Community Edition Fall Release 2025 (Windows support)semgrep.dev/blog/2025/semgrep-community-edition-fall-release-2025/
  16. PyPI: semgreppypi.org/project/semgrep/

Checked on 2026-10-28

Similar tools

Gitleaks

Impact Local only
gitleaks/gitleaks

A command-line tool that finds passwords, API keys, and tokens that have slipped into Git repositories and files.

Purpose
Defense
Type
Command line
Difficulty
Beginner
License
PermissiveMIT
Category
Vulnerability scanning
Actively updatedstars31,101Last update 2026-10-28
Read the Gitleaks review

OSV-Scanner

Impact Local only
google/osv-scanner

A command-line tool from Google that reads dependencies from lockfiles and container images and checks them against known vulnerabilities in OSV.dev. Also covers offline scans and CI use.

Purpose
Defense
Type
Command line
Difficulty
Beginner
License
PermissiveApache-2.0
Category
Vulnerability scanning
Actively updatedstars11,544Last update 2026-11-17
Read the OSV-Scanner review

ShellCheck

Impact Local only
koalaman/shellcheck

A static analysis tool that reads sh and bash scripts without running them and points out common mistakes such as missing quotes and dangerous patterns.

Purpose
Defense
Type
Command line
Difficulty
Beginner
License
CopyleftGPL-3.0
Category
AppSec and DevSecOps
Actively updatedstars40,354Last update 2026-11-09
Read the ShellCheck review

TruffleHog

Impact Reaches others
trufflesecurity/trufflehog

A scanner that finds leaked API keys and passwords in Git history, files, cloud storage, and more. It can also check whether a key it finds still works.

Purpose
Defense
Type
Command line
Difficulty
Beginner
License
CopyleftAGPL-3.0
Category
Vulnerability scanning / AppSec and DevSecOps
Actively updatedstars29,439Last update 2026-11-16
Read the TruffleHog review