CloFix WAF · Scripting Engine

CloFix Custom Rules & Scripting

Unified rule engine combining CloFixRule directives, JavaScript, and Lua with intelligent bypass system. Runs custom WAF logic with isolated engines for precise request control.

Scripting Engine #6 30 details Published

Overview

💡 How it works: CloFix Custom Rules engine processes rules in execution priority order across three scripting languages. CloFixRule directives are compiled into optimized decision trees for O(log n) lookup times. JavaScript and Lua scripts execute in isolated VMs with 2-second (JS) or 50ms (Lua) timeouts. Files execute alphabetically - use numeric prefixes like `01_rate_limit.js`, `02_bot_detection.lua`, `03_clofixrule.conf` to control pipeline order. The intelligent bypass system supports rule ID, tag, phase, path, and IP bypasses - documented bypasses are essential for production. All rule executions are traced in the audit log with detailed match information for forensics and tuning. Shared dictionaries (`sharedDict` in JS, `clofix.shared` in Lua) maintain cross-request state with TTL support. Pattern extraction from JavaScript files automatically creates fast-matching signatures checked against every request.

Feature details

CloFixRule Directive

CRS-style custom rules with variables (ARGS, REQUEST_HEADERS, REQUEST_URI, BODY), operators (@rx regex, @contains, @streq, @pm, @beginsWith, @endsWith), and transformations (t:lowercase, t:urlDecode, t:htmlEntityDecode, t:removeNulls, t:compressWhitespace)

Multi-Language Support

Choose between declarative CloFixRule (YAML-like), JavaScript (clofix), or Lua (clofix_main) - mix and match in the same deployment with alphabetical execution order

Intelligent Bypass System

Bypass rules by rule ID, tag (`attack-sqli`, `paranoia-level/3`), phase (1-4 request/response), path (`/health`, `/api/public/*`), or IP (`127.0.0.1`, `192.168.1.*`, `10.0.0.0/8`)

Anomaly Scoring Engine

Each rule contributes weighted points to anomaly score (CRITICAL=5, ERROR=4, WARNING=3, NOTICE=2, INFO=1). Threshold-based blocking with configurable inbound/outbound limits

Paranoia Levels 1-4

Progressive protection from minimal false positives (Level 1) to maximum security (Level 4) - adjust per domain or globally

Pattern Extraction

JavaScript files automatically scanned for strings and regex patterns - used for fast matching without execution overhead

Shared Dictionaries

Persistent cross-request state with TTL - `sharedDict("name")` in JavaScript, `clofix.shared.*` in Lua, perfect for rate limiting and bot tracking

Action Types

`block` (403), `allow`, `rate_limit` (429), `challenge` (CAPTCHA), `redirect`, `log_only`, `captcha` - with custom status codes and messages

Transformation Chains

Apply multiple transformations sequentially - `t:lowercase,t:urlDecode,t:htmlEntityDecode` defeats encoding evasion techniques

Virtual Patching

Create custom rules to patch vulnerable applications without code changes - deploy within minutes of vulnerability disclosure

Rule Testing Sandbox

Interactive playground to test custom rules against historical traffic or custom payloads before production deployment

Pre-built Rule Templates

200+ community-contributed templates for WordPress, Drupal, Joomla, Magento, Laravel, Django, and custom applications

API Rate Limiting DSL

Specialized syntax for API protection - per-endpoint limits, burst handling, graduated response (slow down → challenge → block)

Bot Detection Rules

Pre-configured bot fingerprints for 500+ known bots (Googlebot, Bingbot, ChatGPT, GPTBot, Anthropic) with custom actions per bot type

Credential Stuffing Protection

Login endpoint velocity checks, password reuse patterns, and known breached credentials via haveibeenpwned API integration

GraphQL Security Rules

Introspection blocking, depth limiting (default max depth 10), complexity scoring, and batch query throttling

gRPC Method Filtering

Whitelist/blacklist specific gRPC methods with regex patterns - block reflection services and internal methods from external callers

JSON Schema Validation

Enforce JSON schemas on API requests - block malformed payloads before they reach your application logic

XML/SOAP Validation

Detect XML bombs, XXE attacks, and schema violations in SOAP and REST XML payloads

Custom Response Rules

Inspect and modify responses - add security headers (CSP, HSTS), remove server signatures, inject monitoring scripts, block responses containing sensitive data

Webhook Actions

Trigger external webhooks on rule matches - send alerts to Slack, PagerDuty, or custom SIEM solutions with full request context

Delayed Response (Tarpitting)

Slow down attackers with configurable delays - waste attacker resources while maintaining legitimate user experience

Log Sampling

Sample and log only matching rules at configurable rates - reduce log volume while maintaining security visibility

Rule Groups

Organize rules into named groups (PCI, HIPAA, WordPress, API) - enable/disable entire groups with a single toggle for multi-tenant environments

Priority Execution

Assign execution priority (1-1000) - ensure critical rules run first while complex analysis runs later. Pre-optimize based on historical match rates

Rule Metrics Dashboard

Real-time metrics per rule - match count, false positive rate, execution time, and impact score. Identify rules causing latency or blocking legitimate traffic

Automated Rule Optimization

ML-powered suggestions to reduce false positives - learn from blocked vs. allowed traffic patterns and suggest threshold adjustments

Rule Export/Import

Export rule sets as YAML/JSON for backup, version control, or sharing across deployments. Import from other CloFix instances or community repositories

Inline Documentation

Document rules with markdown descriptions, examples, and remediation steps - built-in documentation viewer for security teams

Rule Scheduling

Schedule rules for specific maintenance windows or seasonal traffic - automatically enable holiday shopping protection, disable during low-traffic periods

How CloFix WAF uses it

💡 How it works: CloFix Custom Rules engine processes rules in execution priority order across three scripting languages. CloFixRule directives are compiled into optimized decision trees for O(log n) lookup times. JavaScript and Lua scripts execute in isolated VMs with 2-second (JS) or 50ms (Lua) timeouts. Files execute alphabetically - use numeric prefixes like `01_rate_limit.js`, `02_bot_detection.lua`, `03_clofixrule.conf` to control pipeline order. The intelligent bypass system supports rule ID, tag, phase, path, and IP bypasses - documented bypasses are essential for production. All rule executions are traced in the audit log with detailed match information for forensics and tuning. Shared dictionaries (`sharedDict` in JS, `clofix.shared` in Lua) maintain cross-request state with TTL support. Pattern extraction from JavaScript files automatically creates fast-matching signatures checked against every request.

Canonical URL: https://clofix.com/features/clofix-waf/custom-rules/