Chapter 5 — Security

Last Updated: 2026-12-04 09:44 Views: 11

5.1 Process model and privilege separation

On Linux, FreeBSD, macOS, NetBSD and OpenBSD the server runs a root master with ordinary-user workers:

  • master reads config, binds HTTP/TLS/HTTP3/stream/mail ports, runs the console, handles signals and maintains the PID file.
  • worker reads configuration as root at startup, then setgid/setuids to global.user/group, loads modules, opens logs and serves requests.
  • The master never handles requests or loads third-party .so files. Sockets reach workers via ExtraFiles; workers set Pdeathsig and exit with the master.

user = "root" is refused by default; for debugging set WXSERVER_ALLOW_ROOT=1 in the startup environment only (the console cannot). Windows has no fork/exec model; the service runs as an ordinary local account.

Path Permission requirement
Config, acme.toml 0600 root; kept on console save
certs/*.key / *.crt 0600 / 0644 root:root
certs/ directory 0700 root:root
Log directory Writable by the worker user
Site root, error_page Worker-readable; absolute paths under root/error_page_root

5.2 WAF

The WAF has two engines. full loads CRS rules (crs-lite built in; import the full OWASP CRS converted with wxserver-convert -from crs) and integrates libinjection SQLi/XSS detection for complete detection at higher cost; fast inspects only URL parameters, cookies, forms, JSON/XML and upload names, suiting static or low-risk sites. Order: IP allow/deny → CC sliding window → engine; allow-listed clients pass, deny-listed get 403. waf.cc provides sliding-window CC (window_sec/max_requests/block_sec; key supports ip/ip+uri/ip+ua/variable templates) with counters shared across workers via shared_state.

waf = { enabled = true, engine = "full" }

Custom rules configure targets (URI/ARGS/HEADERS/BODY/COOKIE/UA/REFERER/IP), pattern, is_regex and action (block/allow/log). Global rules live in waf.rules and site rules in http.servers[].waf.rules; both run before CRS, and allow short-circuits later rules. Built-in rules can only be viewed or excluded; resolve false positives with rule_exclusions, rule_overrides, or waf = { enabled = false } per location.

5.3 Access control and rate limiting

Capability Configuration key Description
IP allow/deny access.rules allow/deny rules matched in order
Basic authentication auth_basic realm + credentials
Subrequest authorization auth_request Auth subrequest; allow_codes defaults to 200
JWT auth_jwt HS256/RS256/ES256; exp/nbf + claims; optional JWKS
Tamper-proof links secure_link MD5 signature + expiry
Request rate limiting limit_req / limit_conn Token-bucket rate and concurrent connections; 503
Error-rate blocking error_guard Temporary 429 after excess 4xx/5xx

Rate-limit keys default to $binary_remote_addr and can be any variable. A limit hit returns 503; error-rate blocking returns 429 with Retry-After by default.

5.4 Security response headers

security_headers is off by default; enable it at global, http, site or location level, most specific wins. Keys: hsts (only over TLS), csp, x_frame_options (default SAMEORIGIN), referrer_policy, permissions_policy, nosniff. Existing headers are never overwritten; security_headers = false disables the location and { csp = "off" } just one header.

5.5 Console and log security

The console listens on 127.0.0.1:9090 by default, backed by allow_cidr, login failure blocking, a captcha and TOTP. manager.toml holds password hashes and must be 0600; if exposed, front it with a trusted proxy and restrict sources.

Access logs redact query parameters such as password, token and secret to REDACTED; log_redact_keys adds names. With encrypt = true and a key_file, logs are encrypted line by line with AES-256-GCM; the decryption command is in Chapter 7. server_tokens = false hides the version.

5.6 ACME and certificate privilege model

ACME checks, renewal, DNS API calls and acme.toml reading all happen in the master (root):

  • The master reads the 0600 root:root acme.toml and performs HTTP-01 / DNS-01; HTTP-01 tokens go into master-maintained public challenge files (0644, TTL-limited) answered by workers on :80;
  • Issued certificates land in conf/certs/ (cert 0644, key 0600, dir 0700) and update cert.toml;
  • Workers receive certificates/key in memory via inherited FDs at startup and via the control socket after renewal; workers never read conf/certs or acme.toml — a compromised worker cannot reach DNS API keys.

5.7 Multi-worker and reload

  • Shared state lives in the mmap file (shared_state, 0660 root:workergroup): WAF CC, limit_req/limit_conn and error_guard counters are shared; upstream down/fails/active are shared; health checks run on worker 0 only; metrics are aggregated by the master.
  • Workers send formatted log lines; the master owns rotation/encryption and workers hold no log file descriptors. Log IPC verifies peer credentials (SO_PEERCRED/parent PID) plus a random token.
  • On reload the master re-reads config, binds new ports and starts new workers, then gracefully drains the old ones; the console lives in the master and stays available during reload.
  • Windows has no fork/FD inheritance: sockets are duplicated with WSADuplicateSocketW and workers never re-bind; UDP (HTTP/3, stream UDP) is received by worker 0 only.

5.8 Importing OWASP CRS

The runtime loads TOML rules only; convert ModSecurity .conf first:

# 1) copy crs-setup.conf.example to crs-setup.conf; keep .data files alongside
# 2) convert setup + all rules (multiple -in merge into one output)
wxserver-convert -from crs \
  -in crs-setup.conf -in rules/REQUEST-901-INITIALIZATION.conf \
  -in rules/REQUEST-9xx-....conf -in rules/RESPONSE-95x-....conf \
  -out conf/waf/crs.toml
# 3) rules_files = ["conf/waf/crs.toml"]; use skip_unsupported_rules = true
#    temporarily while evaluating

Verified with CRS 4.31.0-dev: SQLi/XSS/traversal samples are blocked by 942100/941100/930100. Caveats: SecRuleScript/Lua and a few ctl actions are unsupported; .data files must sit next to the TOML (@pmFromFile relative paths) and are not part of the DFA cache key — delete the cache or restart after changing them.

← Previous Article Chapter 4 — TLS and Certificates Next Article → Chapter 6 — Performance and Caching

Comments

No comments yet