Skip to content

WAF Reference

WAF rules are global public proxy rules evaluated before rate limits, traffic shapers, route resolution, and target forwarding.

Exact Fields And Defaults

Reserved WAF endpoints:

PathUse
/.p2pstream/waf/captcha/verifyCaptcha form verification.
/.p2pstream/waf/waiting-roomWaiting-room page endpoint.
/.p2pstream/waf/waiting-room/statusWaiting-room status and admission check.

ACME HTTP challenges bypass the WAF before these reserved endpoints are handled.

WAF rule defaults:

SettingDefault or limit
Namewaf-rule when empty
Priority100 in database defaults
ActionBlock
Activation modeAlways
Captcha pass TTL1800000 ms, 30 minutes
Captcha pass TTL range1 minute to 24 hours
Default keyremote IP
Block status403
Block body sourceInline
Block content typetext/plain; charset=utf-8
Block bodyRequest blocked\n
Block body limit64 KiB
Captcha page templateNone
Waiting-room page templateNone

Waiting-room defaults:

SettingDefaultRange
Max admitted sessions501 to 1,000,000
Admission rate10/sec1 to 100,000/sec
Admission session TTL600000 ms1 minute to 24 hours
Queue poll interval5000 ms1 to 60 seconds
Queue timeout1800000 ms1 minute to 24 hours
Page titleWaiting roomnon-empty custom text
Page bodyTraffic is high. You will be admitted automatically.non-empty custom text

Automatic activation defaults:

SignalDefault
Request window10000 ms
Minimum request rate50 rps
Traffic spike multiplier4
Proxy active requests100
Target active requests100
Agent active requests50
Server CPU85%
Agent CPU85%
Minimum active duration30000 ms
Quiet period60000 ms

Validation Rules

Captcha providers are created under Traffic Policy -> WAF and support Cloudflare Turnstile, hCaptcha, and Google reCAPTCHA v2 checkbox. Provider secret keys are required, stored server-side, and not sent back to the UI after creation. Captcha rules require an enabled provider.

p2pstream captcha provider editor showing provider type, site key, secret key saved state, and enabled state
The captcha provider editor stores the provider credentials used by captcha WAF rules. Saved secret keys are represented by state, not echoed back in full.
p2pstream Traffic Policy WAF section showing WAF rules, actions, activation modes, captcha providers, and rate limits
The Traffic Policy page keeps WAF rules near rate limits so admins can see which early policy layer will act before route resolution.

Block response template mode requires a selected generic_body response template.

Captcha page templates can only be selected for captcha WAF rules. The selected template must have kind waf_captcha_page and include {{ .captcha_element_html }}.

Waiting-room page templates can only be selected for waiting-room WAF rules. The selected template must have kind waf_waiting_room_page and include both {{ .queue_position }} and {{ .retry_after_seconds }}.

WAF rules use request-only CEL match_rule rules. Empty match rules match every request. See CEL Policy Matching for variables, helper functions, builder behavior, limits, and examples.

Route data, target data, target health, and load-balancer state are not available inside WAF match CEL. WAF rules still run before route resolution.

WAF key parts reuse rate-limit key sources: remote IP, host, method, path, protocol, header, cookie, and query parameter.

Automatic trigger thresholds accept 0 to disable individual signals. CPU percentages are 0 to 100.

p2pstream WAF rule editor showing match builder, action, activation mode, response template, captcha, and waiting-room settings
The WAF editor combines match rules, key parts, action settings, custom responses, captcha provider selection, and waiting-room automation thresholds.

Runtime Effects

Rules are ordered by priority, then ID. The first enabled matching rule wins.

p2pstream verifies captcha tokens against the provider siteverify endpoint with a 3 second timeout. After success, it sets a signed p2pstream_waf_<rule_id> pass cookie and redirects with 303 See Other.

Waiting-room state is in memory. Admission and queue identity are stored in signed cookies. Valid admission cookies continue to pass after restart until expiry; queue cookies are accepted after restart, but visitors are re-enqueued because FIFO state is not persisted.

Custom WAF page templates are rendered with html/template. Normal placeholder values are escaped. The captcha element placeholder is trusted server-generated HTML so the provider widget and form can render.

Captcha and waiting-room passes only satisfy the matching WAF rule. The request still continues through rate limits, traffic shaping, route resolution, and target forwarding.

The original request body is never replayed after a captcha challenge or waiting-room admission.

Examples

Login captcha rule:

text
Action: Captcha
Host pattern: app.example.com
Path prefix: /login
Methods: POST
Key: remote IP
Captcha pass TTL: 1800000 ms

Automatic waiting room:

text
Action: Waiting room
Activation mode: Automatic
Host pattern: app.example.com
Minimum request rate: 50 rps
Target active requests: 100

Operations documentation for self-hosted p2pstream deployments.