Code Monkey home page Code Monkey logo

hamid-k / semgrep Goto Github PK

View Code? Open in Web Editor NEW

This project forked from semgrep/semgrep

0.0 0.0 0.0 21.24 MB

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

Home Page: https://semgrep.dev

License: GNU Lesser General Public License v2.1

Makefile 0.16% OCaml 20.51% Emacs Lisp 0.04% Standard ML 1.13% Python 32.79% JavaScript 33.10% C 0.06% C++ 0.01% PHP 0.13% Java 11.51% Hack 0.01% Shell 0.26% Dockerfile 0.05% Go 0.18% Ruby 0.05% C# 0.01% HTML 0.01% TypeScript 0.01%

semgrep's Introduction

Semgrep logo

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

Getting Started · Examples · Resources
Usage · Contributing · Commercial Support

Homebrew PyPI Issues welcome! Issues welcome! 1500+ GitHub stars

Semgrep tl;dr:

  • A simple, customizable, and fast static analysis tool for finding bugs
  • Combines the speed and customization of grep with the precision of traditional static analysis tools
  • No painful domain-specific language; Semgrep rules look like the source code you’re targeting
  • Batteries included with hundreds of existing community rules for OWASP Top 10 issues and common mistakes
  • Runs in CI, at pre-commit, or in the editor
  • Runs offline on uncompiled code

Semgrep supports:

Go Java JavaScript JSON Python Ruby (beta) JSX (beta) C (alpha) OCaml (alpha)

Semgrep is proudly supported by r2c. Learn more about a hosted version of Semgrep with an enterprise feature set at r2c.dev.

Getting Started

The best place to start with Semgrep and rule writing is its Quick Start. For a more in-depth introduction to its syntax and use cases visit the Semgrep Tutorial.

Semgrep can be installed using brew, pip, or docker:

# For macOS
$ brew install semgrep

# On Ubuntu/WSL/linux, we recommend installing via `pip`
$ python3 -m pip install semgrep

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

To confirm installation and get an overview of Semgrep's functionality run with --help:

$ semgrep --help

Once installed, Semgrep can be run with single rule patterns or entire rule packs:

# 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 a ruleset with rules for many languages
$ semgrep --config=https://semgrep.dev/p/r2c-CI path/to/src

Explore the Semgrep Registry of rules and CI integrations at semgrep.dev.

Examples

Use case Semgrep rule
Ban dangerous APIs Prevent use of exec
Search routes and authentiation 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

Try it out

Give some rule packs a spin by running on known vulnerable repositories:

# juice-shop, a vulnerable Node.js + Express app
$ git clone https://github.com/bkimminich/juice-shop
$ semgrep -f https://semgrep.dev/p/r2c-security-audit juice-shop
# railsgoat, a vulnerable Ruby on Rails app
$ git clone https://github.com/OWASP/railsgoat
$ semgrep -f https://semgrep.dev/p/r2c-security-audit railsgoat
# govwa, a vulnerable Go app
$ git clone https://github.com/0c34/govwa
$ semgrep -f https://semgrep.dev/p/r2c-security-audit govwa
# vulnerable Python+Flask app
$ git clone https://github.com/we45/Vulnerable-Flask-App
$ semgrep -f https://semgrep.dev/p/r2c-security-audit Vulnerable-Flask-App
# WebGoat, a vulnerable Java+Sprint app
$ git clone https://github.com/WebGoat/WebGoat
$ semgrep -f https://semgrep.dev/p/r2c-security-audit WebGoat

Resources

Learn more:

Get in touch:

Usage

Command Line Options

See semgrep --help for command line options.

Exit Codes

semgrep may exit with the following exit codes:

  • 0: Semgrep ran successfully and found no errors
  • 1: Semgrep ran successfully and found issues in your code
  • >=2: Semgrep failed to run

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

Contributing

Semgrep is LGPL-licensed, feel free to help out: CONTRIBUTING.

Semgrep is a frontend to a larger program analysis library named pfff. pfff began and was open-sourced at Facebook but is now archived. The primary maintainer now works at r2c. Semgrep was originally named sgrep and was renamed to avoid collisons with existing projects.

Commercial Support

Semgrep is supported by r2c. We're hiring!

Interested in a fully-supported, hosted version of Semgrep? Drop your email and we'll be in touch!

semgrep's People

Contributors

aryx avatar drewdennison avatar brendongo avatar ievans avatar rcoh avatar mschwager avatar underyx avatar nbrahms avatar mjambon avatar emjin avatar sabrinabrogren avatar colleend avatar chmccreery avatar dlukeomalley avatar clintgibler avatar iagoabal avatar pabloest avatar ajinabraham avatar daghan avatar dan5382 avatar disconnect3d avatar sansguidon avatar sharontlin avatar srenatus avatar sylvestre avatar ekse avatar javixeneize avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.