WAF Orchestration Rule Design
OpenFlare WAF uses a visual directed acyclic graph (DAG) to compose request filtering policies. The control plane validates and compiles rule graphs into runtime topologies, while openflare-edge executes request matching, zentinel-modsec OWASP CRS attack inspection, and PoW challenges in memory—independently refreshing IP groups over config_sync v1.
1. Security Boundaries and Evaluation Order
Before proxying upstream or serving static Pages assets, openflare-edge evaluates security controls in deterministic order:
- Global request whitelist (
waf-request-whitelist-v1): Delivered alongside the site snapshot and precompiled into exact, prefix, suffix, and regex path matchers (keyed by exact Host or single-level*.suffix). Matching requests bypass all WAF flows and request-body inspection. - Global enabled WAF rule groups: Executed first on every site without per-route reordering.
- Route-bound WAF rule groups: Executed in the route's configured binding sequence.
- Reaching a
blocknode terminates the request immediately with its configured HTTP status and HTML body and records aWafAuditentry. - Reaching an
allownode completes the current rule and advances to the next bound rule; traffic proceeds upstream only after every active rule reachesallow. - On any invalid graph state (missing target, unknown port, or step overflow), the executor fails closed and logs an error rather than allowing uninspected traffic through.
- Reaching a
- Standalone PoW policy: Evaluated via PoW Protection Design. Legacy inline PoW nodes inside WAF graphs automatically skip when a standalone route PoW policy is configured.
GeoIP Resilience and Shared IP Matching
- Weak GeoIP dependency:
openflare-edgeloadsGeoLite2-City.mmdbandGeoLite2-Country.mmdbfrom$STATE_DIRwith 24-hour background refresh (15-minute retry on failure,128 MiBfile cap), preferring City for country + ISO 3166-2 subdivisions and falling back to Country. If MMDB files are unavailable or an IP has no geo record,geo_matchevaluates to non-matching without disrupting IP matching or proxying. - Shared IP / CIDR matcher: Both WAF and PoW reuse
components/edge/src/policy/mod.rs::ip_in_cidrsupporting IPv4, IPv6, and normalized CIDR formats.
2. DAG Node Types and Runtime Semantics
Creating a WAF rule requires only a name, initializing a valid start → allow default graph edited in React Flow. Loops, arbitrary script nodes, subgraphs, and cross-rule jumps are prohibited.
| Node Type | Cardinality | Inputs | Outputs | Configuration & Behavior |
|---|---|---|---|---|
start | Exactly 1 | None | next | Graph entry point |
allow | Exactly 1 | >= 1 | None | Pass exit for the current rule graph |
block | Multiple | >= 1 | None | HTTP status code (default 403) and optional HTML response body |
ip_match | Multiple | >= 1 | true, false | Inline IPs, CIDRs, and referenced IP group IDs |
geo_match | Multiple | >= 1 | true, false | Country ISO codes and ISO 3166-2 subdivision codes |
ua_check | Multiple | >= 1 | true, false | Evaluation order: require non-empty UA → block bots/abnormal UA/custom substrings → browser & OS allowlists (and/or) |
attack_protection | Multiple | >= 1 | true, false | Binds an attack protection group (17 OWASP CRS categories, off/observe/essential/balanced/strict levels + per-rule overrides); zentinel-modsec inspects URI, headers, and bodies up to 64 KiB. Observe hits take true with audit logging; blocking hits take false |
Legacy pow | Retained | >= 1 | next | Algorithm, difficulty, session TTL, challenge TTL; bypassed if standalone route PoW exists |
[!NOTE]
attack_protectionloads request-phase CRS rules mapped to OpenFlare's 17 attack categories (excluding response-phase rules and anomaly scoring) alongside supplemental XXE and ASP injection rules. Within a snapshot, nodes sharing identical preset/override combinations share compiledEnginePoolinstances.
3. Control-Plane Validation, Compilation, and IP Group Sync
3.1 Authoring vs. Runtime Models
- Authoritative graph validation: The React Flow editor saves graph JSON with optimistic-lock
revisionchecks (returning HTTP 409 on conflict).CompileRuleGraphstrips canvas coordinates and compiles exits into ID lookup maps while enforcing limits of128nodes,256edges, and256 KiBeditor JSON per rule:- Strictly acyclic (no self-loops or cycles);
- Exactly one
start, oneallow, and every node reachable fromstartwith a valid path toalloworblock; - Conditional nodes must wire both
trueandfalseports cleanly without multi-target fanout per port.
3.2 Independent IP Group Refresh (waf.ip-group.v1/<id>)
- Supports
manuallists,automaticbehavioral blocking (expr-langwindow rules), andsubscriptionfeeds (text or JSON extraction). - While graph topologies deploy inside
sites.v1, IP group memberships update independently viawaf.ip-group.v1/<id>underconfig_sync v1, bounded by a20 MiBruntime snapshot cap (protocol.MaxWAFIPGroupSnapshotBytes). openflare-edgeverifies SHA-256 digests and swaps IP groups atomically in memory; if snapshot validation or rule compilation fails, the node keeps serving the previous healthy configuration.
4. API, Editor, and Audit Integration
- Management APIs under
internal/apps/openflare/waf/isolate rule metadata,revision-guarded graph saves, ordered route bindings, global request whitelists, attack protection groups, and IP group syncs. - Audit details (
action,reason,flow_id,flow_node_id,attack_group_id, matched CRSrules, and truncated request previews) report back with access logs intoof_node_access_logs(waf_actionandwaf_audit).