Shapash — Deterministic Rule Engine
Shapash is a deterministic, auditable forward-chaining rule engine designed for security analysis, compliance workflows, and intelligent automation.
Features
- Deterministic Evaluation: Stable rule ordering and reproducible results
- HEL Integration: Uses HEL (Heuristics Expression Language) for rule conditions
- Pluggable Scoring: Trait-based scoring models for custom risk calculations
- TOML Rule Format: Clean
.rulefiles with inline or external HEL conditions - ONNX Model Support: Optional ML model integration for advanced scoring
- Audit Trails: Per-rule evaluation traces for compliance
Quick Start
Define Rules (TOML)
Create a .rule file:
[[]]
= "high-risk-taint"
= "Dangerous taint flow detected"
= 'TaintFlow.sink == "strcpy"' # Inline HEL
= 75
= "strcpy is unsafe with untrusted input"
[[]]
= "security-check"
= "Complex security validation"
= "conditions/nx-check.hel" # External HEL script
= 85
= "NX protection should be enabled"
Evaluate Rules
use ;
use HashSet;
// Load rules from .rule files
let engine = from_paths?;
// Provide facts for evaluation
let mut facts = new;
facts.insert;
// Execute rule engine
let report = engine.execute;
println!;
for rule in &report.triggered_rules
Custom Scoring Models
Implement your own scoring logic:
use ;
;
let report = engine.execute_with_scorer?;
Rule File Format
Rules support both inline and external HEL conditions:
Inline Condition
[[]]
= "example"
= 'binary.arch == "x86_64" AND security.nx == false'
= 50
= "..."
= "..."
External Condition File
[[]]
= "example"
= "conditions/android-malware.hel"
= 90
= "..."
= "..."
File: conditions/android-malware.hel
let has_sms = manifest.permissions CONTAINS "READ_SMS"
let obfuscated = binary.entropy > 7.5
has_sms AND obfuscated
Architecture
┌─────────────────────────────────────────────┐
│ Shapash │
│ • Rule orchestration │
│ • Fact management │
│ • Scoring coordination │
└─────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────┐
│ HEL (external crate) │
│ • Expression evaluation │
└─────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────┐
│ Products │
│ • Inject domain-specific facts │
│ • Custom scoring models │
└─────────────────────────────────────────────┘
Example
See examples/c01-simple-pipeline.rs for a complete working example.
License
Apache-2.0. See LICENSE for details.