Skip to main content

Lightweight static analysis for many languages. Find bug variants with patterns that look like source code.

Project description

Semgrep logo

Lightweight static analysis for many languages.
Find bugs and enforce code standards.

Homebrew PyPI Issues welcome! Issues welcome! 1500+ GitHub stars Follow @r2cdev


Semgrep is a fast, open-source, static analysis tool that excels at expressing code standards — without complicated queries — and surfacing bugs early at editor, commit, and CI time. Precise rules look like the code you’re searching; no more traversing abstract syntax trees or wrestling with regexes.

The Semgrep Registry has 1,000+ rules written by the Semgrep community covering security, correctness, and performance bugs. No need to DIY unless you want to.

Semgrep runs offline, on uncompiled code.

Semgrep is used in production everywhere from one-person startups to multi-billion dollar companies; it is the engine inside tools like NodeJsScan. Semgrep is developed and commercially supported by r2c, a software security company. r2c’s free hosted service, Semgrep Community, lets organizations write and share rules, and manage Semgrep in CI across many projects. r2c also offers a paid hosted tier for enterprises, Semgrep Team.

Language support

General availability

Go · Java · JavaScript · JSON · Python · Ruby

Beta

TypeScript · JSX · TSX

Visit Supported languages for the complete list.

Getting started

To install Semgrep use Homebrew or pip, or run without installation via Docker:

# For macOS
$ brew install semgrep

# For Ubuntu/WSL/Linux/macOS
$ python3 -m pip install semgrep

# To try Semgrep without installation run via Docker
$ docker run --rm -v "${PWD}:/src" returntocorp/semgrep --help

Once installed, Semgrep can run with single rules or entire rulesets. Visit Running rules to learn more or try the following:

# Check for Python == where the left and right hand sides are the same (often a bug)
$ semgrep -e '$X == $X' --lang=py path/to/src

# Run the r2c-ci ruleset (with rules for many languages) on your own code!
$ semgrep --config=p/r2c-ci path/to/src

Visit Getting started to learn more.

Rule examples

Visit Rule examples for use cases and ideas. There is also an excellent interactive tutorial.

Use case Semgrep rule
Ban dangerous APIs Prevent use of exec
Search routes and authentication Extract Spring routes
Enforce the use secure defaults Securely set Flask cookies
Enforce project best-practices Use assertEqual for == checks, Always check subprocess calls
Codify project-specific knowledge Verify transactions before making them
Audit security hotspots Finding XSS in Apache Airflow, Hardcoded credentials
Audit configuration files Find S3 ARN uses
Migrate from deprecated APIs DES is deprecated, Deprecated Flask APIs, Deprecated Bokeh APIs
Apply automatic fixes Use listenAndServeTLS

Integrations

Visit Integrations to learn about Semgrep editor, commit, and CI integrations. When integrated into CI and configured to scan pull requests, Semgrep will only report issues introduced by that pull request; this lets you start using Semgrep without fixing or ignoring pre-existing issues!

More

Upgrading

To upgrade, run the command below associated with how you installed Semgrep:

# Using Homebrew
$ brew upgrade semgrep

# Using pip
$ python3 -m pip install --upgrade semgrep

# Using Docker
$ docker pull returntocorp/semgrep:latest

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

semgrep-0.39.1.tar.gz (75.0 kB view details)

Uploaded Source

Built Distributions

semgrep-0.39.1-cp36.cp37.cp38.py36.py37.py38-none-macosx_10_14_x86_64.whl (49.7 MB view details)

Uploaded CPython 3.6 CPython 3.7 CPython 3.8 Python 3.6 Python 3.7 Python 3.8 macOS 10.14+ x86-64

semgrep-0.39.1-cp36.cp37.cp38.py36.py37.py38-none-any.whl (52.5 MB view details)

Uploaded CPython 3.6 CPython 3.7 CPython 3.8 Python 3.6 Python 3.7 Python 3.8

File details

Details for the file semgrep-0.39.1.tar.gz.

File metadata

  • Download URL: semgrep-0.39.1.tar.gz
  • Upload date:
  • Size: 75.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for semgrep-0.39.1.tar.gz
Algorithm Hash digest
SHA256 891d5a7dd6c6a4cc819be90ca9dad8571de0173c319100a0d85853d8423036c6
MD5 492cf1640283cd5d80c0deeb41068f0e
BLAKE2b-256 55f9df3a2e79e9353ff8023f918f0f749c2fbf75864e7868dc87b6c1c9403d73

See more details on using hashes here.

File details

Details for the file semgrep-0.39.1-cp36.cp37.cp38.py36.py37.py38-none-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: semgrep-0.39.1-cp36.cp37.cp38.py36.py37.py38-none-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 49.7 MB
  • Tags: CPython 3.6, CPython 3.7, CPython 3.8, Python 3.6, Python 3.7, Python 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for semgrep-0.39.1-cp36.cp37.cp38.py36.py37.py38-none-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 5684fe0585db37defd567e8a3caee383042ca5f5543f45570c24fce6cce6bfad
MD5 caa2f4e74fb6bf1703eadc8a29f2ef6a
BLAKE2b-256 33a58a73f06efa0789323aaa40a0f98cbd6dde3f206e42cebcb43fce51e691e8

See more details on using hashes here.

File details

Details for the file semgrep-0.39.1-cp36.cp37.cp38.py36.py37.py38-none-any.whl.

File metadata

  • Download URL: semgrep-0.39.1-cp36.cp37.cp38.py36.py37.py38-none-any.whl
  • Upload date:
  • Size: 52.5 MB
  • Tags: CPython 3.6, CPython 3.7, CPython 3.8, Python 3.6, Python 3.7, Python 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for semgrep-0.39.1-cp36.cp37.cp38.py36.py37.py38-none-any.whl
Algorithm Hash digest
SHA256 104546d3cbc1856fbfaf556dc5887ccba552481e6ba17a5ffb0d8be3135194d7
MD5 35ea3fe078c73ee4370d9074f4fd8fd1
BLAKE2b-256 67564059b16dcb56288bb194173624df1f021b1cedf86417c42647ac83054f35

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page