CloFix JavaScript (clofix) Engine
Server-side JavaScript WAF scripting with full HTTP pipeline control and shared in-memory state. Runs custom WAF logic with isolated engines for precise request control.
Overview
💡 How it works: JavaScript scripts execute in isolated V8 isolates with a 2-second timeout. Files execute in alphabetical order - use numeric prefixes like `01_rate_limit.js`, `02_bot_detect.js` to control priority. The first script returning a non-allow action stops pipeline execution. Shared dictionaries (`sharedDict("name")`) provide persistent cross-request storage with TTL support. Pattern extraction automatically scans all JavaScript files for strings and regex patterns, creating fast-matching signatures checked against every request. The system is configured via `js_blocker` block in domain config with `js_dir`, `execution_timeout`, `block_threshold`, and `scan_interval` settings.
Feature details
Entry Point
Every script must export `function clofix(request)` that returns an action object - first non-allow action wins pipeline execution
Request Object
Full access to `request.ip`, `request.method`, `request.path`, `request.url`, `request.query`, `request.headers`, `request.body`, `request.cookies`, `request.user_agent`, `request.is_tor`, `request.timestamp`
Shared Dictionaries
Persistent cross-request state via `sharedDict("name")` with `get()`, `set()`, `incr()`, `delete()` methods - perfect for rate limiting and bot tracking
Pattern Extraction
System auto-extracts patterns from ALL JavaScript files for fast matching - strings and regex patterns become detection signatures
Action Types
Return `{ action: "allow" }`, `{ action: "block", reason: "..." }`, `{ action: "rate_limit" }`, or `{ action: "redirect", redirect_to: "..." }`
Structured Logging
`log.info()`, `log.warn()`, `log.error()` for general logs; `log.attack({ rule_name, category, confidence, payload })` for attack detection
Execution Limits
2 second wall-clock timeout per script, 32MB memory limit, 10MB max file size - prevents runaway scripts from impacting WAF throughput
SQL Injection Detection
Pattern-based detection for UNION SELECT, INSERT INTO, DROP TABLE, time-based attacks, and boolean blind injection
XSS Protection
Script tag injection, event handlers (onerror, onload), JavaScript protocol, and DOM-based XSS pattern detection
Command Injection
Unix/Linux command chaining (`;`, `|`, `&&`, `` ` ``), Windows cmd.exe patterns, and dangerous command execution detection
Path Traversal/LFI
`../`, `..\`, URL-encoded traversal, sensitive file access (`/etc/passwd`, `/windows/win.ini`) blocking
SSRF Protection
Block internal IP ranges (127.0.0.1, 169.254.x.x, 10.x.x.x, 192.168.x.x) and cloud metadata endpoints (169.254.169.254)
Rate Limiting
Per-IP sliding window with timestamp array storage, burst detection, and graduated blocking (60s, 600s, 86400s escalation)
GeoIP Blocking
Country-level blocking using `request.country` (requires GeoIP implementation)
Bot Detection
User-Agent patterns (sqlmap, nikto, wpscan), headless browser detection, and missing UA challenge
Brute Force Protection
Login path monitoring with 5-attempt windows, 30-minute bans after threshold exceeded
DDoS Shield
Two-tier protection - burst detection (30 req/2s) and sustained rate (200 req/min) with escalating bans (60s → 600s → 86400s)
CSRF Protection
Origin header validation for POST/PUT/DELETE/PATCH methods with configurable allowed origins and exempt paths
API Key Authentication
Validate `X-API-Key` header or `api_key` query parameter against pre-configured key store
File Type Filtering
Block dangerous extensions (.php, .asp, .jsp, .exe, .sh, .py) before they reach backend
Maintenance Mode
Temporary blocking with IP allowlisting and health check exemptions
Smart Redirects
URL rewriting with exact and prefix-based 301/302 redirects
Honeypot Traps
Special URLs that ban any visiting IP (except whitelisted search engine bots) for 24 hours
Password Protect URLs
Simple token-based authentication for staging/preview environments
Tor/VPN Blocking
Native `request.is_tor` detection for blocking Tor exit nodes
How CloFix WAF uses it
💡 How it works: JavaScript scripts execute in isolated V8 isolates with a 2-second timeout. Files execute in alphabetical order - use numeric prefixes like `01_rate_limit.js`, `02_bot_detect.js` to control priority. The first script returning a non-allow action stops pipeline execution. Shared dictionaries (`sharedDict("name")`) provide persistent cross-request storage with TTL support. Pattern extraction automatically scans all JavaScript files for strings and regex patterns, creating fast-matching signatures checked against every request. The system is configured via `js_blocker` block in domain config with `js_dir`, `execution_timeout`, `block_threshold`, and `scan_interval` settings.
Canonical URL: https://clofix.com/features/clofix-waf/javascript-engine/