PoW Protection Design
The Proof-of-Work (PoW) module combines per-site policies, challenge page templates, a browser Web Component solver, and IP/path matchers shared with the WAF engine. Control-plane logic lives in internal/apps/openflare/pow, persisting policies in of_pow_policies keyed by route_id (cleaned up transactionally on route deletion) and compiling pow_enabled / pow_config directly into sites.v1 for lock-free atomic reloads in openflare-edge.
1. Configuration and Asset Pipeline
- Control-plane API:
GET /api/v1/d/pow/policieslists configured site policies;PUT /api/v1/d/pow/policies/{id}validates ranges and route ownership before savingenabledandconfig. Global challenge page styling (template,widget, and customhtml) is managed through thepow_pagesetting. - Policy constraints (
internal/openflare/edgeconfig/pow_policy.go):algorithm:fastorslow;difficulty:1–16;session_ttl:60–604800seconds;challenge_ttl:30–3600seconds;path_rules:modeisallorblacklist(requiring at least one blacklist entry whenblacklistis chosen). Allow/block rule lists accept up to100entries usingexact,prefix,wildcard(all prefixed with/), orregex. Omittingpath_rulesapplies PoW site-wide.
- Single source of HTML assets: Built-in challenge templates and scripts reside in
components/shared/edgeassets/pow_templates/andpow_static/. Frontend preview assets sync vianode frontend/scripts/generate-pow-assets.mjsand are enforced inmake code-check.
2. Request Flow and Security Guarantees
- Takeover semantics: When a route has a standalone PoW configuration (
route.pow.is_some()),openflare-edgeautomatically skips any legacypownodes inside attached WAF rule graphs so visitors are never challenged twice. Routes without standalone policies keep legacy graph-embedded PoW compatibility. - Matcher & cookie evaluation: The runtime evaluates allowlists (IP/CIDR/path/UA), blocklist modes, and signed session cookies using matchers precompiled in memory during snapshot swaps.
path_rulesexact,prefix, andwildcardrules are case-sensitive, whereas legacypathswildcards remain case-insensitive. - Challenge rendering & solving: Unauthenticated requests receive the rendered challenge HTML (escaping
<inside embedded boot JSON and updating status strings withtextContent), driving the Web Component andopenflare:pow/window.OpenFlarePoWUI events while Web Workers compute SHA-256 solutions. - Verification & anti-replay: Submissions to
POW_API_PREFIXbind strictly to request host and route ID, invalidate the single-use challenge, issue a scoped session cookie, and redirect solely to the server-recorded local target path.
If snapshot decoding or template loading fails, openflare-edge rejects the candidate snapshot and retains the last healthy active configuration rather than failing open.