Open-source Code Property Graph (CPG) compiler and ProjectDiscovery Nuclei exporter with a Docker verification harness.
Source (C/C++, Java, Go, Python, …) → Joern CPG → DataFlowSlice → Nuclei YAML → nuclei (Docker) → TP/TN report
This repository provides a high-integrity execution primitive for security researchers and AI agents. It operates deterministically rather than probabilistically.
What this tool DOES (and excels at):
- Deterministic Translation: Translates Joern Code Property Graphs (AST + CFG + PDG) directly into syntax-error-free Nuclei YAML.
- Template Refactoring: Acts as an engineering backend to convert flaky, destructive, or noisy community PoCs into schema-compliant, production-ready rules.
- Closed-Loop Verification: Provides a local
harness/docker_runner.pyto spin up targets, execute compiled templates, and guarantee True Positives (TP) locally before submitting Pull Requests. - Handling Async Logic: Automatically enforces HTTP header hardening (e.g.,
User-Agent) and asynchronous execution delays (wait_for) based on code graph analysis.
What this tool DOES NOT do:
- Text-to-Template Generation: This tool cannot generate templates from natural language, CVE advisories, or bug bounty write-ups. It requires actual target source code (C/C++, Java, Go, Python) or a pre-compiled Joern CPG to trace data flows.
- Autonomous Target Acquisition: The provided Docker harness requires you to manually define the target container and supply the source code; it does not automatically hunt for vulnerable images.
While generating new templates from scratch requires target source code for Joern CPG analysis, refactoring existing templates requires zero CPG setup.
This repository serves as a deterministic unit-testing harness to take flaky, state-mutating, or destructive community templates and safely convert them into non-destructive, production-ready rules.
Why Use This Tool for Refactoring?
- Zero CPG Overhead: You do not need source code or Joern static analysis to refactor an existing
.yamltemplate. - Deterministic Verification: Use
harness/docker_runner.pyto test rules against local Docker targets, ensuring 0% syntax errors and verifying True Positives (TP) before opening upstream PRs. - Automated Hardening: Enforce strict
User-Agent: Nuclei-Scannerheaders, state snapshotting, andwait_fortiming primitives.
3-Step Refactoring Workflow
- Fetch Target Template: Pick a community template from
projectdiscovery/nuclei-templatesthat lacks proper cleanup or mutates application state. - Execute Local Harness: Spin up the target container and run the verification harness locally:
python -m harness.docker_runner --template templates/CVE-2024-51483.yaml --target http://127.0.0.1:5000
- Submit Upstream: Verify non-destructive execution and submit a verified Pull Request to ProjectDiscovery.
Case Study Reference
- PR #17007 (CVE-2024-51483): Refactored a destructive
changedetection.iorule to capture setting snapshots via GET, perform a non-destructive check, and restore settings automatically post-scan.
- Empirical Analysis (CVE-2025-62593): CPG Compilation vs. LLM AI Generation: Empirical Analysis of CVE-2025-62593 Rule Accuracy — Benchmarking deterministic CPG static compilation against LLM-based template synthesis on asynchronous execution logic.
- Architectural Overview: Why I Built an Open-Source CPG-to-Nuclei Compiler in Rust — Detailed walkthrough of bridging Joern code graphs to ProjectDiscovery Nuclei DSL syntax.
| Component | Path |
|---|---|
| Joern CPG bridge | cpg_nuclei_core/src/joern_cpg_bridge.rs |
| CPG schema / deserializer | cpg_nuclei_core/src/cpg_schema.rs, cpg_deserializer.rs |
| DFG / taint analysis | cpg_nuclei_core/src/cross_tx_dfg.rs, parser.rs, taint.rs |
| Nuclei YAML exporter | cpg_nuclei_core/src/exporters/nuclei_exporter.rs |
| Pipeline CLI | cpg_nuclei_core/examples/run_cpg_pipeline.rs |
| Docker closed-loop runner | harness/docker_runner.py |
| Architecture docs | docs/cpg/, docs/nuclei/ |
cpg-nuclei-compiler serves as a high-integrity execution primitive for AI coding agents and autonomous security frameworks (e.g., OpenCode, Kilo Code, Cursor, Claude Code).
Rather than relying on probabilistic LLM context windows to guess template schemas or manually trace dataflows, agents invoke this CLI to achieve deterministic graph traversals (AST + CFG + PDG) with 0% syntax-error output guarantees.
Install Joern and point JOERN_HOME at your distribution. See docs/cpg/JOERN_CLI_PROVISIONING.md.
Supported ingestion paths: C/C++, Java, Go, Python, and other Joern frontends.
# Rust compiler tests
cargo test -p cpg_nuclei_core
# Python integration (compiler + harness)
pytest tests/test_cpg_nuclei_compiler.py
# Export Nuclei YAML from source via Joern
cargo run --example run_cpg_pipeline -- --target path/to/main.c
# Closed-loop Nuclei scan (Docker required)
python -m harness.docker_runner --template templates/CVE-2024-51483.yaml --target http://127.0.0.1:5000This repository publishes a composite action (action.yml) that runs the Docker verification harness on a template path in the caller repository.
Requirements
- Check out the repository that contains the template YAML first (
actions/checkout). - Use a Linux runner with Docker (
ubuntu-lateston GitHub-hosted runners). - Relative
templatepaths are resolved againstgithub.workspace(the caller checkout).
Consumer workflow
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Tito0015/cpg-nuclei-compiler@v1
with:
template: path/to/template.yaml
target: http://127.0.0.1:5000Same-repo CI (dogfood) uses uses: ./ — see .github/workflows/verify-harness.yml.
Public repositories with a root action.yml can appear on the GitHub Marketplace automatically. Consumers pin a release with @v1 (or another semver tag) after you publish a tag and release on this repository.
For refactoring projectdiscovery/nuclei-templates in a fork, see docs/nuclei/UPSTREAM_REFACTORING_PIPELINE.md.
Some community templates (including CVE-2024-51483) mutate application settings during execution. Against a live Changedetection.io instance:
- Snapshot
/settings(GET) before scanning. - Run Nuclei in an isolated environment.
- Restore settings from the snapshot after the scan.
The local fixture server on :5000 is a non-production stub for harness tests only.
MIT — see LICENSE. The vendored Nuclei template under templates/ is from projectdiscovery/nuclei-templates (MIT).