Semgrep
Lightweight, syntax-aware static application security testing (SAST) engine
WHAT IS IT?
Semgrep (Semantic Grep) is an open-source static analysis engine that understands programming language syntax and Abstract Syntax Trees (ASTs) rather than treating source code as raw lines of text.
WHY USE IT? // PRACTICAL USE CASES
Regex searches break when code spans multiple lines, uses aliased imports, or includes comments. Semgrep rules look like the target language itself (using `$X` metavariables and `...` ellipsis operators) and run in seconds without needing a full build environment.
- [1] Writing custom AST rules to enforce secure coding invariants (e.g., banning unparameterized SQL or `dangerouslySetInnerHTML`)
- [2] Auditing newly cloned repositories for command injection, SSRF, and path traversal sinks
- [3] Running fast pre-commit and pull-request security gates without full compilation
HOW DO I GET IT? // SAFE INSTALLATION GUIDANCE
Install via Python (`pipx install semgrep`) or Homebrew (`brew install semgrep`). Run with `--metrics=off` to disable telemetry during offline/private code audits.
HOW DOES IT WORK? // INTERNAL ARCHITECTURE OVERVIEW
Semgrep parses source files into a generic AST via tree-sitter and language parsers, normalizes constant propagation and import aliases, and matches pattern trees against YAML rule definitions locally.