How to Write Custom Semgrep Rules for Your Own Codebase
Taint mode, metavariable patterns and rule testing that let you encode your team's specific forbidden patterns — the internal API misuse no public ruleset knows…
Static analysis engine that finds bugs and vulnerabilities with pattern-based rules you can read.
Semgrep is an open-source static analysis tool that finds security bugs and logic errors by matching code patterns, not by building a full compiler model. The engine is free and runs locally in under a minute on most repos; the hosted AppSec platform starts around $40 per contributor per month.
Traditional SAST tools are painful: hours-long scans, thousands of false positives, and rules written in a syntax only the vendor’s consultants understand. Semgrep went the other direction. A rule is basically the code pattern you’d grep for, with metavariables.
That means a security engineer can write a rule in five minutes and actually review it. It supports 30+ languages including Python, Java, Go, Ruby, TypeScript and PHP, and understands enough syntax that $X matches any expression in that position.
pattern: exec($CMD) style matching with metavariables and taint tracking.Diff-aware scanning is the feature that makes it adoptable. On a pull request, Semgrep only reports findings introduced by the new lines, so an old codebase with 4,000 existing issues doesn’t drown every review.
http.Get directly, use our wrapper”).The CLI and Community rules are free under an open-source-friendly license and can run entirely on your machines. The hosted AppSec Platform is free up to 10 contributors, then about $40 per contributor per month for Teams, with Supply Chain and AI triage priced separately.
It is not a type checker. Deep dataflow bugs across dozens of files, or anything requiring whole-program reasoning, may be missed — pair it with a compiler and tests. Very dynamic languages like heavily metaprogrammed Ruby produce false positives, and the YAML rule syntax takes an afternoon to learn properly.