• Stars
    star
    9,758
  • Rank 3,419 (Top 0.07 %)
  • Language
    OCaml
  • License
    GNU Lesser Genera...
  • Created over 4 years ago
  • Updated 4 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Semgrep logo

Code scanning at ludicrous speed.

Homebrew PyPI Documentation Join Semgrep community Slack Issues welcome! Star Semgrep on GitHub Docker Pulls Follow @semgrep on Twitter


Semgrep is a fast, open-source, static analysis engine for finding bugs, detecting vulnerabilities in third-party dependencies, and enforcing code standards. Semgrep analyzes code locally on your computer or in your build environment: code is never uploaded. Get started →.

Semgrep CLI image

Language support

Semgrep supports 30+ languages.

Category Languages
GA C# · Go · Java · JavaScript · JSX · JSON · PHP · Python · Ruby · Scala · Terraform · TypeScript · TSX
Beta Kotlin · Rust
Experimental Bash · C · C++ · Clojure · Dart · Dockerfile · Elixir · HTML · Julia · Jsonnet · Lisp · Lua · OCaml · R · Scheme · Solidity · Swift · YAML · XML · Generic (ERB, Jinja, etc.)

Getting started 🚀

  1. From the CLI
  2. From the Semgrep Cloud Platform

For beginners, we recommend starting with the Semgrep Cloud Platform because it provides a visual interface, a demo project, result triaging and exploration workflows, and makes setup in CI/CD fast. Scans are still local and code isn't uploaded. Alternatively, you can also start with the CLI without logging in and navigate the terminal output to run one-off searches.

Option 1: Getting started from the CLI

  1. Install Semgrep CLI
# 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 semgrep
  1. Go to your app's root directory and run semgrep scan --config auto. This will scan your project with the default settings.

  2. [Optional, but recommended] Run semgrep login to get the login URL for the Semgrep Cloud Platform. Open the login URL in the browser and login.

Option 2: Getting started from the Semgrep Cloud Platform (Recommended)

Semgrep platform image

  1. Register to semgrep.dev

  2. Explore the demo app

  3. Scan your project by navigating to Projects > Scan New Project > Run scan in CI

  4. Select your version control system and follow the wizard to add your project. After this setup, Semgrep will scan your project after every pull request.

  5. [Optional but recommended] If you want to run Semgrep locally, follow the steps in the CLI section.

Notes:

  1. Visit Docs > Running rules to learn more about auto config and other rules.

  2. If there are any issues, please ask in the Smegrep Slack group https://go.semgrep.dev/slack

  3. To run Semgrep Supply Chain, contact the Semgrep team. Visit the full documentation to learn more.

Semgrep Ecosystem

The Semgrep ecosystem includes the following products:

  • Semgrep OSS Engine - The open-source engine at the heart of everything (this project).
  • Semgrep Cloud Platform (SCP) - Deploy, manage, and monitor SAST and SCA at scale using Semgrep, with free and paid tiers. Integrates with continuous integration (CI) providers such as GitHub, GitLab, CircleCI, and more.
  • Semgrep Code - Scan your code with Semgrep's Pro rules and Semgrep Pro Engine to find OWASP Top 10 vulnerabilities and protect against critical security risks specific to your organization. Semgrep Code provides both Community (free) and Team (paid) tiers.
  • Semgrep Supply Chain (SSC) - A high-signal dependency scanner that detects reachable vulnerabilities in open source third-party libraries and functions across the software development life cycle (SDLC). Semgrep Supply Chain is available on Team (paid) tiers.

and:

  • Semgrep Playground - An online interactive tool for writing and sharing rules.
  • Semgrep Registry - 2,000+ community-driven rules covering security, correctness, and dependency vulnerabilities.

Join hundreds of thousands of other developers and security engineers already using Semgrep at companies like GitLab, Dropbox, Slack, Figma, Shopify, HashiCorp, Snowflake, and Trail of Bits.

Semgrep is developed and commercially supported by Semgrep, Inc., a software security company.

Semgrep Rules

Semgrep rules look like the code you already write; no abstract syntax trees, regex wrestling, or painful DSLs. Here's a quick rule for finding Python print() statements.

Run it online in Semgrep’s Playground by clicking here.

Semgrep rule example for finding Python print() statements

Examples

Visit Docs > 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
Tainted data flowing into sinks ExpressJS dataflow into sandbox.run
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

Extensions

Visit Docs > Extensions to learn about using Semgrep in your editor or pre-commit. 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!

Documentation

Browse the full Semgrep documentation on the website. If you’re new to Semgrep, check out Docs > Getting started or the interactive tutorial.

Metrics

Using remote configuration from the Registry (like --config=p/ci) reports pseudonymous rule metrics to semgrep.dev.

Using configs from local files (like --config=xyz.yml) does not enable metrics.

To disable Registry rule metrics, use --metrics=off.

The Semgrep privacy policy describes the principles that guide data-collection decisions and the breakdown of the data that are and are not collected when the metrics are enabled.

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

More Repositories

1

semgrep-rules

Semgrep rules registry
Solidity
707
star
2

pfff

pfff is mainly an OCaml API to write static analysis, dynamic analysis, code visualizations, code navigations, or style-preserving source-to-source transformations such as refactorings on source code.
186
star
3

bento

[DEPRECATED] Find Python web-app bugs delightfully fast, without changing your workflow. 🍱
Python
143
star
4

semgrep-action

This project is deprecated. Use https://github.com/returntocorp/semgrep instead
Python
72
star
5

semgrep-vscode

Semgrep extension for Visual Studio Code
TypeScript
52
star
6

semgrep-docs

Documentation of Semgrep: a fast, open-source, static analysis tool.
MDX
37
star
7

testo

Test framework for OCaml
OCaml
15
star
8

preflight-extension

[deprecated] Your GitHub Copilot
TypeScript
14
star
9

little-learner-ocaml

OCaml
13
star
10

semgrep-interfaces

Store the ATD/openapi/protobuf/... interfaces between semgrep components
OCaml
13
star
11

semgrep.vim

Semgrep external checker for Syntastic
Vim Script
13
star
12

sexp-fmt

Basic S-expression formatter
OCaml
12
star
13

flake8-click

Flake8 plugin for detecting click best practices. See github.com/returntocorp/r2c-checks
Python
10
star
14

java-xxe-research

Java
8
star
15

poetry-codeartifact-plugin

A Poetry plugin for interfacing with CodeArtifact repositories
Python
8
star
16

semgrepl

A REPL for semgrep
Python
7
star
17

ocaml-tree-sitter-languages

Generate OCaml parsers from tree-sitter parsers
Go
5
star
18

semgrep-ocaml

generated ocaml parser for semgrep
C
5
star
19

semgrep-pro-tests

example test cases for DeepSemgrep
Java
4
star
20

bento-report

Security reports using r2c's Bento program-analysis tool
Python
3
star
21

semgrep-intellij

Kotlin
3
star
22

ocaml-tree-sitter-lang

Generated C/OCaml parsers for multiple programming languages
C
3
star
23

semgrep-langs

Describes language data
3
star
24

check_generic

OCaml
3
star
25

semgrep-cpp

generated C++ parser for semgrep
C
3
star
26

bento-action

Shell
3
star
27

TIP-ocaml

Tiny Imperative Language, implemenented in OCaml, see https://cs.au.dk/~amoeller/spa/
OCaml
3
star
28

semgrep-network-broker

Facilitates network access between Semgrep and on-prem resources
Go
3
star
29

pre-commit-ocaml

Pre-commit hooks for OCaml code
OCaml
3
star
30

semgrep-c-sharp

generated C# parser for semgrep
C
3
star
31

intro-to-semgrep-template

TypeScript
2
star
32

inputset-generator

Generate input sets for analysis on the r2c platform
Python
2
star
33

homebrew-semgrep

Homebrew Recipes for Semgrep
Ruby
2
star
34

semgrep-rust

generated rust parser for semgrep
C
2
star
35

semgrep-ruby

generated ruby parser for semgrep
C
2
star
36

semgrep-tsx

generated TSX parser for semgrep
C
2
star
37

semgrep-elixir

generated Elixir parser for semgrep
C
2
star
38

semgrep-kotlin

generated kotlin parser for semgrep
C
2
star
39

semgrep-jsonnet

generated Jsonnet parser for semgrep
C
2
star
40

semgrep-go

generated go (golang) parser for semgrep
C
2
star
41

project-reason-tree-sitter

project for program analysis candidates
Reason
2
star
42

semgrep-hack

generated hack (hacklang) parser for semgrep
C
2
star
43

semgrep-dart

generated Dart parser for semgrep
C
2
star
44

semgrep-rules-test-action

Run tests for semgrep-rules repositories
Shell
2
star
45

ocaml-tree-sitter-javascript

generated JavaScript parser
C
2
star
46

supersemgrep

Python
2
star
47

semgrep-swift

generated Swift parser for semgrep
C
2
star
48

semgrep-javascript

generated javascript parser for semgrep
C
2
star
49

ocaml-tree-sitter-go

generated Go parser
C
1
star
50

semgrep-clojure

generated Clojure parser for semgrep
C
1
star
51

ocaml-tree-sitter-typescript

generated TypeScript parser
C
1
star
52

ocaml-tree-sitter-java

generated Java parser
C
1
star
53

semgrep-hcl

generated HCL parser for semgrep
C
1
star
54

typed-ast-util

Helper library for writing and running typed-ast rules.
TypeScript
1
star
55

external_netflix_titus-control-plane

Java
1
star
56

ocaml-tree-sitter-ocaml

generated OCaml parser
C
1
star
57

semgrep-lua

generated lua parser for semgrep
C
1
star
58

ocaml-tree-sitter-c-sharp

generated C# parser
C
1
star
59

semgrep-c

generated C parser for semgrep
C
1
star
60

ocaml-tree-sitter-ruby

generated Ruby parser
C
1
star
61

ocaml-tree-sitter-semgrep

Generate parsers from tree-sitter grammars extended to support Semgrep patterns
JavaScript
1
star
62

ocaml-tree-sitter-core

OCaml code generator and runtime library for handling typed tree-sitter CSTs
OCaml
1
star
63

ocaml-tree-sitter-tsx

generated TSX parser
C
1
star
64

tree-sitter-scala-r2c

A fork of tree-sitter-scala for r2c
JavaScript
1
star
65

semgrep-r

generated R parser for semgrep
C
1
star
66

semgrep-grammars

Extensions of public tree-sitter grammars used by semgrep
JavaScript
1
star
67

ocaml-tree-sitter-r

generated R parser
C
1
star
68

bento-emacs

emacs integration for bento
Emacs Lisp
1
star
69

sgrep-build-docker

Dockerfile
1
star
70

tree-sitter-guidelines

tree-sitter contribution guidelines
Makefile
1
star
71

ocaml-tree-sitter-c

generated C parser
C
1
star
72

semgrep-typescript

generated TypeScript parser for semgrep
C
1
star
73

ocaml-tree-sitter-lua

generated Lua parser
C
1
star
74

workshops

1
star
75

ocaml-tree-sitter-rust

generated Rust parser
C
1
star
76

ocaml-tree-sitter-kotlin

generated Kotlin parser
C
1
star
77

semgrep-haskell

C
1
star
78

semgrep-java

generated java parser for semgrep
C
1
star