Semgrep

Semgrep, Inc.

Pattern-based static analysis — writes rules that read like the code they match.

Application & Supply Chain Freemium CLI Practiced in lab Cross-platform

Cyber Kill Chain & Defender Lifecycle

Attacker — Kill Chain
1 Reconnaissance
2 Weaponization
3 Delivery
4 Exploitation
5 Installation
6 Command & Control
7 Actions on Objectives
Defender — IR Lifecycle
8 Preparation
9 Detection & Analysis
10 Containment, Eradication & Recovery
11 Post-Incident Activity

Description

Semgrep matches patterns against the syntax tree rather than the raw text, so a rule looks like the code it is looking for. That is what makes it practical to write a project-specific rule in minutes instead of learning a query language.

This is the tool the series leans on hardest. The recurring finding across posts is that the standard scanners miss framework-specific misuse — mark_safe() on a variable, fields = '__all__' on a ModelForm, .raw() with an f-string — and that a five-line Semgrep rule catches every one of them, in CI, on every commit.

Use cases

  • Custom rules for framework misuse the generic scanners miss
  • CI gate that fails the build on a new dangerous pattern
  • Codifying a security review finding so it cannot regress

Example

semgrep --config p/django --config ./semgrep-rules/ --error .

Related blog posts