Semgrep Rules Manager Save

Manager of third-party sources of Semgrep rules ๐Ÿ—‚

Project README

semgrep-rules-manager logo

Manager of third-party sources of Semgrep rules

Snapcraft's Version ย  ย  PyPI's Version ย  ย  Available rules search engine ย  ย  Available GitHub Action

Description

Although that there is an open source repository containing community rules, some Semgrep users prefer to keep their custom rules in repositories that they manage.

The goal of semgrep-rules-manager is to collect high-quality Semgrep rules from third-party sources. It allows you to examine information about a source, download it, and check for and retrieve remote updates. If a downloaded source no longer meets your requirements, semgrep-rules-manager can handle deletion procedures.

How it works

%%{init: {"theme": "neutral", "flowchart": {"htmlLabels": false}}}%%

flowchart LR

source[("Source code
(in a supported language)")] 
-->|submitted locally via| cli[Command-line interface]

source -->|processed on a pipeline with| cicd["CI/CD action
    (eventually the one provided in this repository)"]

cli -->  lang-parsing

cicd -->  lang-parsing

rules[("Rules
    (in the same language)")] --> lang-parsing

subgraph core[Semgrep OSS Core]

 lang-parsing[Language parsing] -. implemented with .-> tree-sitter[Tree-sitter]

 lang-parsing -->|generates| concrete-sts["Generation of
concrete syntax trees
(language dependent)"]

concrete-sts -->|abstracted to| generic-sts["Generation of
generic syntax trees
(language agnostic)"]

generic-sts -->|fed into| rule-matching[Rule matching]

end

rule-matching -->|generates| warnings[(Warnings)]

subgraph semgrep-rules-manager
    yaml[(YAML definition for sources)] --> index-parsing[Definition parsing] --> git-cloning[Git remote cloning]
end

semgrep-rules-manager -->|provides| rules

Included rules

This online search engine allows you to explore the rules included in semgrep-rules-manager.

Included sources

All sources in semgrep-rules-manager are defined in semgrep_rules_manager/data/sources.yaml. They are listed in the table below.

Identifier Rules per Language Author License
community 396 for Python, 364 for Terraform, 341 for JavaScript, 229 for TypeScript, 228 for Regex, 140 for Java, 105 for Generic, 104 for YAML, 100 for Ruby, 90 for Go, 59 for PHP, 49 for Solidity, 48 for C#, 39 for Dockerfile, 34 for OCaml, 25 for Scala, 24 for JSON, 17 for Kotlin, 17 for C, 12 for Apex, 11 for Rust, 9 for Bash, 7 for Elixir, 5 for Clojure, 5 for Swift, 3 for HTML, 1 for Lua Semgrep LGPL 2.1
gitlab 93 for Scala, 75 for Python, 66 for Java, 64 for C, 31 for Go, 20 for C#, 11 for JavaScript, 10 for TypeScript GitLab MIT
trailofbits 19 for Python, 15 for Go, 9 for JavaScript, 9 for TypeScript, 1 for Rust Trail of Bits AGPL-3.0
0xdea 47 for C++, 46 for C, 1 for Generic Marco Ivaldi MIT
elttam 40 for Java, 15 for Generic, 7 for YAML, 3 for JavaScript, 3 for Go, 2 for TypeScript, 1 for C#, 1 for Kotlin, 1 for Python, 1 for C, 1 for PHP elttam MIT
kondukto 5 for Dockerfile, 5 for PHP, 3 for Go, 3 for Java Kondukto
dgryski 65 for Go Damian Gryski MIT
dotta 7 for PHP, 3 for Kotlin, 1 for Java Federico Dotta MIT
hashicorp 4 for Terraform, 1 for Generic Hashicorp MPL-2.0

Installation in CI

GitHub

The tool is available as a GitHub action and can be easily embedded into a repository to run Semgrep with all rules available in semgrep-rules-manager. Just embed the following step into your workflow definition file:

- name: Semgrep x semgrep-rules-manager
  uses: iosifache/semgrep-rules-manager

Local installation

Snap (snap install semgrep-rules-manager) or pip (pip install semgrep-rules-manager) are the simplest ways to install semgrep-rules-manager.

Get it from the Snap Store

If you don't want to use a package management, simply clone this repository and install Poetry as well as the Python dependencies (poetry install).

See also: Poetry | Installation

Usage

  1. Install semgrep: snap install semgrep

  2. Install semgrep-rules-manager: snap install semgrep-rules-manager

  3. Get help:

    $ semgrep-rules-manager --help
    Usage: semgrep-rules-manager [OPTIONS] COMMAND [ARGS]...
    
    Manages third-party sources of Semgrep rules.
    
    Options:
    --dir PATH  Directory in which the Semgrep rules are stored  [required]
    --help      Show this message and exit.
    
    Commands:
    download  Downloads sources.
    list      Lists sources.
    remove    Removes downloaded sources.
    sync      Syncs downloaded sources.
    
  4. Download a source:

    $ semgrep-rules-manager --dir /home/iosifache/semgrep-rules download --source 0xdea
    โœ… The source was successfully downloaded.
    
  5. List all sources:

    $ semgrep-rules-manager --dir /home/iosifache/semgrep-rules list     
                                                    Available sources of Semgrep rules                                                 
    โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
    โ”ƒ Identifier  โ”ƒ Description                                                      โ”ƒ Author        โ”ƒ Downloaded โ”ƒ Synced with remote โ”ƒ
    โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
    โ”‚ community   โ”‚ Official repository of rules                                     โ”‚ Semgrep       โ”‚ โŒ         โ”‚ โŒ                 โ”‚
    โ”‚ gitlab      โ”‚ Rules used in GitLab SAST                                        โ”‚ GitLab        โ”‚ โŒ         โ”‚ โŒ                 โ”‚
    โ”‚ trailofbits โ”‚ Rules used in the audits, research and projects of Trail of Bits โ”‚ Trail of Bits โ”‚ โŒ         โ”‚ โŒ                 โ”‚
    โ”‚ 0xdea       โ”‚ Custom rules written by Marco Ivaldi                             โ”‚ Marco Ivaldi  โ”‚ โœ…         โ”‚ โœ…                 โ”‚
    โ”‚ elttam      โ”‚ Custom rules used in elttam                                      โ”‚ elttam        โ”‚ โŒ         โ”‚ โŒ                 โ”‚
    โ”‚ kondukto    โ”‚ Custom rules used in Kondukto                                    โ”‚ Kondukto      โ”‚ โŒ         โ”‚ โŒ                 โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    
  6. List only the downloaded source:

    $ semgrep-rules-manager --dir /home/iosifache/semgrep-rules list --source 0xdea
    Identifier: 0xdea
    Description: Custom rules written by Marco Ivaldi
    Rules per language: 40 for C++, 39 for C, 1 for Generic
    Repository URL: https://github.com/0xdea/semgrep-rules
    Repository brach: main
    Author: Marco Ivaldi
    License: MIT
    Downloaded: โœ… (in /home/iosifache/semgrep-rules/0xdea)
    Synced: โœ… because fd3bcad54de9dc76d4a8780a4125d42475d560ce (local) == fd3bcad54de9dc76d4a8780a4125d42475d560ce (remote)
    
  7. Use the downloaded source to scan a codebase: semgrep --config /home/iosifache/semgrep-rules .

  8. Sync the source:

    $ semgrep-rules-manager --dir /home/iosifache/semgrep-rules sync --source 0xdea
    โœ… All sources are already synced.
    
  9. Remove the source

    $ semgrep-rules-manager --dir /home/iosifache/semgrep-rules remove --source 0xdea
    โœ… The source was successfully deleted.
    

Acknowledgements

Thanks to the Semgrep team for making their work available to the open source community!

This project's logo was created with Adobe Firefly.

Open Source Agenda is not affiliated with "Semgrep Rules Manager" Project. README Source: iosifache/semgrep-rules-manager
Stars
66
Open Issues
0
Last Commit
5 months ago
License

Open Source Agenda Badge

Open Source Agenda Rating