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 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
- Frequently asked questions (FAQs)
- Contributing
- Ask questions in the r2c Community Slack
- CLI usage and exit codes
- r2c YouTube channel with Semgrep presentation videos
- License (LGPL-2.1)
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.36.0.tar.gz
.
File metadata
- Download URL: semgrep-0.36.0.tar.gz
- Upload date:
- Size: 73.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ba53cf9453b76787215372b121a6d34c226d771783213e8f3a7d8cd71f2dfab |
|
MD5 | df503958144c307f318b6f6e513c1f29 |
|
BLAKE2b-256 | 2b634ed5b3c8c7f871fbcbabd6c9d2f16dcb45f70104155aba6f59da65afc8ed |
File details
Details for the file semgrep-0.36.0-cp36.cp37.cp38.py36.py37.py38-none-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: semgrep-0.36.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.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc6677601c91a9a4d3cc414f26ce702cb9dc3a3ed3d60d16a7148b995ad48cb3 |
|
MD5 | 69f8fd6889a700dda21e3f8e48df623a |
|
BLAKE2b-256 | 5a70b471a29f311e7e879f1fa74722fca78b0341b33bb9411c7c9165e1890975 |
File details
Details for the file semgrep-0.36.0-cp36.cp37.cp38.py36.py37.py38-none-any.whl
.
File metadata
- Download URL: semgrep-0.36.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.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 180e867b62efb102e1af35529547752661af7d6bc790d7e462be5b2453e74f4f |
|
MD5 | b76a89ac49325a715eea5c2b1274c8cf |
|
BLAKE2b-256 | 5194d6ce8e42588aeb3f4cde5e477a5254fa2a9127f2d67652ce2bf45328c1a1 |