Lightweight static analysis for many languages. Find bug variants with patterns that look like source code.
Project description
Lightweight static analysis for many languages.
Find bugs and enforce code standards.
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 900+ 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.
Language support
General availability
Go · Java · JavaScript · JSON · Python
Beta
Ruby · 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.
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.
FAQ
Visit FAQ to learn more. Semgrep is supported by r2c.
Contributing
Visit Contributing or join the r2c Community Slack to learn more. Semgrep is LGPL-2.1 licensed.
Usage
Visit CLI Usage for usage and exit code documentation.
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
Built Distributions
File details
Details for the file semgrep-0.32.0.tar.gz
.
File metadata
- Download URL: semgrep-0.32.0.tar.gz
- Upload date:
- Size: 69.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d7198e1a2556b903d33bee29e61fc4369deef09cfb14e58588c825e4dfa2aba |
|
MD5 | a204ff3db5a70714acae75524581bae5 |
|
BLAKE2b-256 | 45c81ea0abf67a89bbaae1d152fe4595249f692c06b38ab2789f9eff3b7cd212 |
File details
Details for the file semgrep-0.32.0-cp36.cp37.cp38.py36.py37.py38-none-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: semgrep-0.32.0-cp36.cp37.cp38.py36.py37.py38-none-macosx_10_14_x86_64.whl
- Upload date:
- Size: 47.9 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.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18bf061dc04cbe0bb1e368c814b6d1803f986f06ecd327c3b1cd4854ec2ea4f0 |
|
MD5 | 76ed20dd7855b4061b25116a107e0ab7 |
|
BLAKE2b-256 | 392b720ca4167121ab8b9b9ed1f8ac8d3d2f49fdcc3def7c00fa88dd6f165c58 |
File details
Details for the file semgrep-0.32.0-cp36.cp37.cp38.py36.py37.py38-none-any.whl
.
File metadata
- Download URL: semgrep-0.32.0-cp36.cp37.cp38.py36.py37.py38-none-any.whl
- Upload date:
- Size: 50.7 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.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea650a42123a8e9fa7b66366eb0add737b73edc9669e0dc8bb710f9ab796d5e3 |
|
MD5 | 5597661846b4eb495f05994a3400b380 |
|
BLAKE2b-256 | a7ac4b78a7da00c13decf8cb2e865270db43577754c7d9d3d180bacd004fb5df |