pattern-based code vulnerability detection across 30+ languages
Semgrep-core (OCaml engine) performs AST-based pattern matching against user-defined or curated rules to identify security vulnerabilities, code anti-patterns, and compliance violations. The engine parses source code into language-specific abstract syntax trees using tree-sitter and custom parsers, then matches patterns expressed in Semgrep's domain-specific language (YAML-based rule syntax) against the AST structure. This approach enables structural matching rather than regex-based detection, reducing false positives and enabling cross-language consistency.
Unique: Uses tree-sitter-based AST parsing with language-specific custom parsers for 30+ languages, enabling structural pattern matching that understands code semantics (function scope, variable binding, control flow) rather than relying on regex or token-based matching. The hybrid Python-OCaml architecture delegates computationally intensive matching to OCaml while maintaining a flexible Python CLI for workflow orchestration.
vs alternatives: Faster and more accurate than regex-based tools (Grype, Trivy) because it matches against AST structure; more flexible than signature-based scanners because rules can express complex syntactic patterns; lighter-weight than full symbolic execution tools (Coverity, Fortify) while still catching many real vulnerabilities.
dataflow and taint analysis for cross-function vulnerability chaining
Semgrep's taint analysis engine (available in Pro Engine) tracks data flow across function boundaries to detect vulnerability chains where untrusted input reaches a dangerous sink. The system constructs a dataflow graph by analyzing variable assignments, function parameters, return values, and object field mutations across the codebase. It identifies sources (user input, external data), sinks (SQL queries, command execution, file writes), and sanitizers (validation functions) to determine if tainted data can reach dangerous operations without proper sanitization.
Unique: Implements interprocedural taint analysis by constructing a dataflow graph from AST analysis, tracking variable bindings and function call chains to determine if untrusted data can reach dangerous sinks. The Pro Engine reduces false positives by ~25% and increases true positives by ~250% compared to single-function pattern matching by confirming actual reachability rather than just pattern presence.
vs alternatives: More precise than pattern-only matching (which flags all SQL queries regardless of input source) and faster than full symbolic execution tools because it uses lightweight dataflow analysis rather than constraint solving.
language-specific parser support with graceful error handling
Semgrep includes language-specific parsers (built on tree-sitter and custom OCaml implementations) for 30+ programming languages. Each parser converts source code into an AST that the pattern matching engine can analyze. The system implements graceful error handling where parse errors in individual files do not stop the scan; instead, errors are logged and scanning continues on other files. This enables Semgrep to scan heterogeneous codebases with mixed languages and syntax variations without failing on unparseable code.
Unique: Implements language-specific parsers using tree-sitter (for most languages) and custom OCaml implementations (for performance-critical languages), with graceful error handling that allows scanning to continue even if individual files fail to parse. This architecture enables Semgrep to support 30+ languages without requiring language-specific scanning tools.
vs alternatives: More comprehensive language support than language-specific tools (like Pylint for Python or ESLint for JavaScript) because it handles multiple languages in a single tool; more robust than regex-based tools because it parses code into AST structure.
mcp (model context protocol) server for ai-assisted code analysis
Semgrep includes an MCP server implementation that exposes scanning capabilities to AI models and LLM-based tools. The MCP server allows AI assistants to invoke Semgrep scans, retrieve findings, and analyze code patterns programmatically. This enables integration with AI-powered code review tools, automated remediation assistants, and LLM-based security analysis workflows. The server implements standard MCP protocols for tool invocation and result streaming.
Unique: Implements an MCP server that exposes Semgrep scanning capabilities to AI models and LLM-based tools, enabling integration with AI-powered code review and remediation workflows. The server implements standard MCP protocols for tool invocation, allowing AI assistants to invoke Semgrep scans and analyze findings programmatically.
vs alternatives: Enables AI-assisted code analysis by exposing Semgrep as an MCP tool; more integrated than separate AI and scanning tools because findings are directly available to AI models for reasoning and remediation.
token and position tracking for precise finding location reporting
Semgrep's OCaml engine tracks token positions and source locations during AST parsing and pattern matching, enabling precise reporting of finding locations (file, line, column, character offset). The system maintains a mapping between AST nodes and their source positions, allowing findings to be reported with exact character ranges. This enables IDE integration, inline code comments, and precise highlighting in web interfaces. The position tracking is implemented at the parser level and maintained through the entire analysis pipeline.
Unique: Maintains token and position tracking throughout the OCaml analysis pipeline, enabling precise character-level location reporting for findings. This architecture enables IDE integration, inline code highlighting, and automated remediation by providing exact token ranges rather than just line numbers.
vs alternatives: More precise than tools reporting only line numbers because it provides character offsets; enables better IDE integration and automated fixes because exact token ranges are available.
multi-language rule definition and custom rule authoring
Semgrep provides a YAML-based domain-specific language (DSL) for expressing code patterns that work across multiple programming languages. Rules are defined in YAML with pattern syntax that abstracts away language-specific details (e.g., a pattern for 'function call' works identically in Python, JavaScript, and Go). The pysemgrep CLI parses rule files, validates syntax, and passes compiled rules to semgrep-core for matching. Users can write custom rules targeting their codebase, organization standards, or specific vulnerability patterns without modifying the core engine.
Unique: Provides a language-agnostic YAML-based DSL that abstracts away language-specific syntax details, allowing a single rule to match equivalent patterns across Python, JavaScript, Go, Java, and 25+ other languages. Rules are compiled to an intermediate representation that semgrep-core interprets, enabling rapid rule iteration without recompiling the core engine.
vs alternatives: More accessible than writing custom checkers in OCaml or C++ (as required by Clang Static Analyzer or Coverity) and more expressive than regex-based tools because rules can reference AST structure and semantic relationships.
ci/cd pipeline integration with policy enforcement and finding triage
The `semgrep ci` command integrates Semgrep into CI/CD workflows by scanning code, uploading findings to semgrep.dev, comparing against baseline scans, and enforcing organization-wide policies. The Python CLI (pysemgrep) orchestrates the workflow: it authenticates to Semgrep App using API tokens, fetches organization-specific rules and policies, runs the OCaml scanning engine, and reports results. The system can block CI builds based on policy rules (e.g., 'fail if critical vulnerabilities detected'), automatically triage findings based on organization rules, and track finding status across commits.
Unique: Implements a hybrid local-remote workflow where the OCaml scanning engine runs locally (fast, no data transmission) but policy enforcement and finding triage happen server-side via semgrep.dev API. This architecture enables organizations to enforce policies without exposing source code to the cloud while maintaining centralized policy management. The system tracks finding status across commits, enabling developers to see remediation progress.
vs alternatives: More flexible than GitHub's native code scanning (which only supports GitHub-native rules) because it supports custom rules and cross-language patterns; more integrated than standalone SAST tools because it provides built-in CI/CD orchestration and finding management.
incremental scanning with baseline comparison and delta reporting
Semgrep supports incremental scanning mode where it compares current scan results against a baseline (previous commit or main branch) to report only new or changed findings. The Python CLI manages baseline storage and comparison logic: it fetches the previous scan's JSON output, compares rule matches by file path and line number, and reports only findings that are new, moved, or changed in severity. This reduces noise in CI/CD by surfacing only actionable changes rather than all findings in the codebase.
Unique: Implements baseline comparison at the Python CLI layer by storing and comparing JSON scan results, enabling incremental reporting without requiring the OCaml engine to maintain state. This design allows flexible baseline sources (local files, semgrep.dev API, git history) while keeping the core scanning engine stateless.
vs alternatives: Simpler than tools requiring full codebase re-analysis (like some SAST tools) because it compares results rather than re-running analysis; more practical than git-diff-based filtering because it handles line number shifts and can detect moved findings.
+5 more capabilities