A high-performance, multi-language static code analysis tool for security vulnerabilities and code quality, implemented in Rust.
- Multi-language Support: Java, JavaScript, Python, SQL, Bash, and XML are fully supported
- Multi-dialect SQL: GaussDB, OpenGauss, PolarDB-MySQL, and Standard SQL — each powered by a specialized parser
- GaussDB / OpenGauss:
ogsql-parser - PolarDB-MySQL:
sqlparser-rs - Standard SQL:
tree-sitter-sequel
- GaussDB / OpenGauss:
- Embedded SQL Preprocessor: Extract and analyze SQL embedded in Java source code (annotations and strings) and MyBatis XML, then match it with SQL semantic rules without writing complex host-language patterns
- Security-focused: Detects injection vulnerabilities, XSS, authentication issues, and more
- High Performance: Built in Rust for speed and memory safety
- Flexible Rules: YAML-based declarative rule definitions with metavariables, conditions, and dataflow tracking
- Multiple Output Formats: JSON, SARIF, Text, HTML, Markdown, and Semgrep-compatible output
- Parallel Processing: Multi-threaded analysis for large codebases
- Web Playground: Browser-based interactive rule testing through
astgrep-web(REST API + Playground UI) - Desktop GUI: Cross-platform desktop application built with egui for interactive analysis
- Extensible: Modular architecture for easy language and rule additions
# Clone the repository
git clone https://github.com/c2j/astgrep.git
cd astgrep
# Build the project
cargo build --release
# Install the binary
cargo install --path .# Analyze current directory
astgrep analyze
# Analyze specific files/directories
astgrep analyze src/ tests/
# Use specific rules
astgrep analyze --rules security-rules.yml
# Specify languages
astgrep analyze --language java --language python
# Output to file in SARIF format
astgrep analyze --format sarif --output results.sarif
# Validate rule files
astgrep validate rules/*.yml
# List supported languages
astgrep languages
# SQL dialect analysis (GaussDB compatibility scan)
astgrep analyze --dialect gaussdb --rules tests/categories/rules/sql_dialects/gaussdb/ *.sql
# OpenGauss analysis
astgrep analyze --dialect opengauss --rules tests/categories/rules/sql_dialects/gaussdb/ *.sql
# PolarDB-MySQL analysis
astgrep analyze --dialect polardb-mysql --rules tests/categories/rules/sql_dialects/polardb_mysql/ *.sql
# List available rules
astgrep list --language java --detailed
# Initialize configuration
astgrep init --template security --output astgrep.toml
# Show supported languages and extensions
astgrep info --extensionsThe project is organized as a Cargo workspace with ten crates:
astgrep-core: Core types,Languageenum, error handling, and configurationastgrep-ast:UniversalNodeAST definitions, visitor, and builderastgrep-parser: Tree-sitter adapters per language plus the SQL dialect dispatcherastgrep-matcher: Pattern matching engine (literal, metavariable, and structural matching)astgrep-dataflow: Taint analysis, data flow, call graph, and constant propagationastgrep-rules: YAML rule parsing, validation, and execution engineastgrep-cli: Command-line interface with 14 commandsastgrep-web: Axum REST API server and Web Playgroundastgrep-gui: egui desktop playgroundtest-utils:MockAstNode,MockParser, and other testing utilities
- CLI (
astgrep): The primary interface. Runs full analysis, validates rules, lists languages, and supports all output formats. - Web Service (
astgrep-web-server): Axum-based REST API (default port8080) plus a browser Playground at/playgroundfor interactive rule testing. - Desktop GUI (
astgrep-gui): Cross-platform egui application with an interactive rule editor and embedded documentation.
| Language | Extensions | AST | Taint |
|---|---|---|---|
| Java | .java |
Full | Full |
| JavaScript | .js, .jsx |
Full | Full |
| Python | .py |
Full | Full |
| SQL | .sql |
Full | Full |
| Bash | .sh, .bash |
Full | Full |
| XML | .xml, .xsd, .xsl |
Full | — |
Parser adapters also exist for PHP, C, C#, Ruby, Kotlin, and Swift, but these languages are not yet fully integrated into the Language enum.
astgrep understands four SQL dialects, selected with the --dialect flag:
gaussdbopengausspolardb-mysqlstandard
See docs/sql-dialects.md for details on dialect-specific parsing and rule writing.
- Rust 1.70+
- Cargo
After cloning, install the pre-commit hooks:
lefthook install# Build all crates
cargo build
# Run tests
cargo test
# Run with logging
RUST_LOG=debug cargo run -- analyze
# Run benchmarks
cargo benchEach crate has comprehensive unit tests. Run tests with:
# Run all tests
cargo test
# Run tests for specific crate
cargo test -p astgrep-core
# Run tests with output
cargo test -- --nocaptureRules are defined in YAML format:
rules:
- id: java-sql-injection
name: "SQL Injection Detection"
description: "Detects potential SQL injection vulnerabilities"
severity: ERROR
confidence: HIGH
languages: [java]
patterns:
- pattern: "$STMT.execute($QUERY)"
- metavariable_pattern:
metavariable: "$QUERY"
patterns:
- pattern: "$STR + $INPUT"
dataflow:
sources:
- pattern: "request.getParameter($PARAM)"
sinks:
- pattern: "Statement.execute($QUERY)"
fix: "Use PreparedStatement with parameterized queries"
metadata:
cwe: "CWE-89"
owasp: "A03:2021 - Injection"- User Guide — End-user manual for the CLI, Web Playground, and Desktop GUI
- Developer Guide — REST API, integration, and architecture details
- Rule Writing Guide — How to write YAML rules
- SQL Dialect Support — Multi-dialect SQL analysis
- Contributing Guide — Development setup and conventions
- Roadmap — Project roadmap and milestones
See docs/CONTRIBUTING.md for detailed guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
See docs/ROADMAP.md for the detailed, prioritized roadmap.
- Codebase Health — Fix compilation errors, reduce warnings, add CI/CD
- Architecture Refactoring — Break up oversized files
- Semgrep Compatibility — Complete remaining compatibility fixes
- Test Infrastructure — Complete test directory reorganization
For questions, issues, or contributions, please visit our GitHub repository.