ConfigsApr 13, 2026·3 min read

Semgrep — Lightweight Static Analysis for Any Language

Semgrep is a fast, open-source static analysis tool that finds bugs and security issues using patterns that look like source code. Write rules in a syntax similar to the code you are searching — no complex AST queries or regex needed.

TL;DR
Semgrep finds bugs and security issues using code-like patterns across 30+ languages, no complex AST knowledge needed.
§01

What it is

Semgrep is a fast, open-source static analysis tool that finds bugs and security vulnerabilities using patterns that look like the source code you are searching. Write rules in a syntax similar to the code itself, without needing compiler expertise or AST manipulation.

Semgrep targets security engineers, developers, and DevSecOps teams who want custom code analysis rules without the complexity of traditional SAST tools. It supports over 30 programming languages with a single rule syntax.

The project is actively maintained and suitable for both individual developers and teams looking to integrate it into their existing toolchain. Documentation and community support are available for onboarding.

§02

How it saves time or tokens

Semgrep rules are readable by any developer, not just security specialists. A rule that catches SQL injection looks like the vulnerable code pattern itself. The Semgrep Registry provides thousands of pre-written rules for OWASP Top 10, framework-specific bugs, and code quality issues. Running Semgrep in CI takes seconds, not minutes like heavier analyzers.

§03

How to use

  1. Install Semgrep via pip (pip install semgrep) or Homebrew.
  2. Run semgrep --config auto to scan with community-recommended rules.
  3. Write custom rules in YAML targeting patterns specific to your codebase.
  4. Add Semgrep to your CI pipeline to block PRs with security findings.
§04

Example

# .semgrep/sql-injection.yaml
rules:
  - id: sql-injection-string-concat
    patterns:
      - pattern: |
          $QUERY = "..." + $INPUT + "..."
          cursor.execute($QUERY)
    message: >-
      SQL injection via string concatenation.
      Use parameterized queries instead.
    severity: ERROR
    languages: [python]
# Run the custom rule
semgrep --config .semgrep/sql-injection.yaml src/

# Run with the full community ruleset
semgrep --config auto --error
§05

Related on TokRepo

§06

Common pitfalls

  • Running with --config auto in CI without reviewing findings first. Some rules may produce false positives for your codebase. Curate your rule set before enforcing.
  • Writing rules that are too broad. A pattern like $X + $Y matches everything. Be specific about the dangerous pattern you want to catch.
  • Not using metavariable-regex to constrain matches. Without constraints, rules match safe code patterns alongside vulnerable ones, creating noise.
  • Not reading the changelog before upgrading. Breaking changes between versions can cause unexpected failures in production. Pin your version and review release notes.

Frequently Asked Questions

How does Semgrep differ from ESLint or Pylint?+

ESLint and Pylint are language-specific linters focused on style and common errors. Semgrep is a multi-language analysis engine focused on security and custom code patterns. Semgrep rules work across 30+ languages with one syntax.

Is Semgrep free?+

Semgrep OSS (the CLI tool) is free and open-source under LGPL-2.1. Semgrep Cloud (SaaS dashboard with team features) has paid tiers. The community rule registry is free to use.

How fast is Semgrep?+

Semgrep scans most codebases in under 30 seconds. It uses parallel execution and only parses files matching the rule's language filter. It is significantly faster than tools that build full program dependency graphs.

Can I write rules without learning a new language?+

Yes. Semgrep patterns use the syntax of the target language. A Python pattern looks like Python. A JavaScript pattern looks like JavaScript. The only additions are metavariables ($X) for matching arbitrary expressions.

Does Semgrep support autofix?+

Yes. Rules can include a fix field that specifies the corrected code. When run with --autofix, Semgrep applies the fix automatically. Always review autofixes before committing.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets