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 finds bugs and enforces code standards at editor, commit, and CI time. Precise rules look like the code you’re searching; no more traversing abstract syntax trees, wrestling with regexes, or using a painful DSL. Code analysis is performed locally (code is not uploaded) and Semgrep runs on uncompiled code.

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 is used in production everywhere from one-person startups to multi-billion dollar companies; it’s the engine inside tools like NodeJsScan. See tools powered by Semgrep.

Semgrep is developed and commercially supported by r2c, a software security company. r2c’s hosted service, Semgrep App, lets organizations easily deploy in CI, manage rules across many projects, monitor the efficacy of code policy, and integrate with 3rd-party services. r2c offers free and paid hosted tiers (see pricing).

Language support

General availability

Go · Java · JavaScript · JSX · JSON · Python · Ruby · TypeScript · TSX

Beta & experimental

See 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.44.0.tar.gz (78.1 kB view details)

Uploaded Source

Built Distributions

semgrep-0.44.0-cp36.cp37.cp38.cp39.py36.py37.py38.py39-none-macosx_10_14_x86_64.whl (51.0 MB view details)

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

semgrep-0.44.0-cp36.cp37.cp38.cp39.py36.py37.py38.py39-none-any.whl (52.8 MB view details)

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

File details

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

File metadata

  • Download URL: semgrep-0.44.0.tar.gz
  • Upload date:
  • Size: 78.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for semgrep-0.44.0.tar.gz
Algorithm Hash digest
SHA256 8f99381f92c84832cab9c1552dbb2afce61833f21dbd829ec1d17e7ce937ecce
MD5 a73648b7d84666efaa3e92ba76e08e85
BLAKE2b-256 33346a04d5e45b48fd4d7084f24cdec77cf79a82799e67c770431296a242bce6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: semgrep-0.44.0-cp36.cp37.cp38.cp39.py36.py37.py38.py39-none-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 51.0 MB
  • Tags: CPython 3.6, CPython 3.7, CPython 3.8, CPython 3.9, Python 3.6, Python 3.7, Python 3.8, Python 3.9, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for semgrep-0.44.0-cp36.cp37.cp38.cp39.py36.py37.py38.py39-none-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 3d9b5f567654d7b0b2b40996622d7d9bc76fa5d5558370a19366d424c304f422
MD5 469313444f7088fcb2c47b3112f0866c
BLAKE2b-256 7ca1babcb6a7db927eab627f7fae91249d5c9785f74b048e1e6db51f7f24bd78

See more details on using hashes here.

File details

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

File metadata

  • Download URL: semgrep-0.44.0-cp36.cp37.cp38.cp39.py36.py37.py38.py39-none-any.whl
  • Upload date:
  • Size: 52.8 MB
  • Tags: CPython 3.6, CPython 3.7, CPython 3.8, CPython 3.9, Python 3.6, Python 3.7, Python 3.8, Python 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for semgrep-0.44.0-cp36.cp37.cp38.cp39.py36.py37.py38.py39-none-any.whl
Algorithm Hash digest
SHA256 fa944bd081e4d66580b987139e2d43716846004f9deaff10032c65a66d0eb803
MD5 f657fc7aea88395789340148a3304ddc
BLAKE2b-256 ece1c6ab6a5700f74d741768480ab0767b1bce8d1de566811d2280b4c190b60c

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