Internals: decision records

ADR-0054: Edge features for ScalPanel

Status: accepted, 2026-11-18

Context

ScalPanel runs an nginx edge on each node: it terminates TLS, blocks addresses and countries, protects images from hotlinking, serves the panel’s website preview under a path prefix and writes one access log per website. ScalPanel’s generator (scalpanel-agent, its ADR-0216) can write the same edge as a ScalWS configuration. The owner’s sample of that output (generation 42) did not load in ScalWS 1.1: it used keys ScalWS lacked (server.networks, deny_networks, referer, remove_cookies, forwarded_for, rewrite_location, cookie, access_log, max_upgraded, server-wide compression), a prefix path with a trailing slash, burst: 0, and it relied on nginx’s route order. ScalWS adopts the generator’s key names as they are; the generator does not change. The design is docs/design/2026-11-15-1.1-edge-features-design.md.

Decision

  • Adoption rules. A key the sample uses that ScalWS lacks is added under the generator’s name, at the generator’s place in the tree. A key that exists keeps its 1.0 meaning unless the difference breaks the edge; each change is listed below (D1 to D12) with a changelog line and a test. Every new key is optional: a configuration without it behaves as before and pays nothing per request (the pipeline_cost rows are unchanged).
  • Route order (D1). route_order: nginx on an application tries exact routes, then regex routes in configuration order, then prefix routes (longest first), as nginx does. The default, route_order: scalws, keeps ADR-0050’s order (owner answer Q1: opt-in, the generator writes the key). See the ADR-0050 amendment.
  • Trailing slash. A prefix path may end with one /: /sp-ab12/ matches /sp-ab12/ and below, not /sp-ab12 (nginx location /sp-ab12/). It is stored as /sp-ab12, so rewrite.prefix and a redirect’s prefix replace /sp-ab12 plus the slash.
  • Network sets. server.networks.<NAME> is a CIDR list file or a list of countries looked up in server.geoip.database (a MaxMind DB format file, read into memory, no mmap). Routes name sets in deny_networks and allow_networks. A client is refused when deny or deny_networks holds it, or when an allow list is set and neither allow nor allow_networks holds it. The client is the address the server resolved from server.trusted_proxies (header server.client_address.header) and the server.client_address.presets networks (the vendor’s header, such as CF-Connecting-IP), else the peer; a header from any other peer is never read. Country lookups are estimates, and clients behind a VPN, proxy, Tor or cloud host carry the country of their exit. Sets are sorted, merged range tables (one binary search per list, no allocation); a route’s list is merged once and shared. Limits: 512 sets, 32 MiB per file, 1 000 000 entries in all; a file is read without following a final symbolic link. scalwsctl geoip update installs DB-IP’s IP to Country Lite database (CC BY 4.0); the package ships a monthly timer, disabled.
  • Referer. Route referer: {allow_empty, allow_own, hosts, status} follows nginx valid_referers (none blocked server_names and host names), with a strict parser. A refusal answers status (default 403) with Cache-Control: no-store; routes with referer never use the response cache.
  • Request and proxy changes. request_headers.remove_cookies drops named cookies from every Cookie line. Proxy forwarded_for: client sends one X-Forwarded-For value and X-Real-IP. rewrite_location puts the prefix the route’s rewrite removed in front of a path Location; cookie.path_prefix and cookie.domain: request_host rewrite Set-Cookie. server.security.per_ip.max_upgraded limits upgraded tunnels per client address (429).
  • Access log files. access_log: {file, format} on an application or route, format combined or scalpanel (ScalPanel’s nginx log_format, byte for byte, with nginx \xHH escaping). One writer thread and one bounded queue for all such files; SIGUSR1, scalwsctl reopen-logs and POST /v1/logs/reopen reopen every log file.
  • Server-wide compression. server.compression.enabled, types and min_length: every application without its own compression compresses types plus text/html (nginx gzip on with gzip_types). min_length replaces the fixed 1024 bytes.
  • Evaluation order. For a matched route: allow/deny/allow_networks/ deny_networks (403), referer, CORS preflight, basic authentication, max_body, quotas, rewrite, request headers (remove_cookies included), runtime (max_upgraded at the upgrade), response headers (rewrite_location and cookie before the route’s response_headers), compression, access log. As at nginx’s edge, a plain-HTTP request from a denied address first gets the HTTPS redirect, then 403 over HTTPS.
  • Version line. scalwsd --version prints edge-features: with one token per finished feature, space-separated and in alphabetical order: access_log forwarded_for gzip max_upgraded networks prefix_proxy referer remove_cookies route_order. The generator compares it with the list its sample header needs.

Differences from the generator’s expectation

IdWhereScalWS 1.1nginx or the generatorWhy
D1route orderopt-in route_order: nginx; default exact, prefix, regexexact, regex, prefixreleased 1.0 order kept (Q1)
D2referer with a malformed http(s):// valuerefusedrefusedparity
D3per_ip.burst: 0accepted: a bucket of one requestlimit_req without burstScalWS burst is the bucket size; parity is nginx burst plus one (Q3)
D4redirect keep_path: false with Gateway fieldsdrops the query (1.0 kept it)return 302 https://$host:2096/parity
D5Server of proxied responsesscalws (the upstream’s is dropped)upstream’s hiddenno upstream version leaks; a 101 keeps the upstream’s
D6request_headers.set with ""header sent emptyheader not sent1.0 kept; the client’s value never passes either way (Q2)
D7preserve_hostthe client’s authority as sent$host (lower case, no port)1.0 kept; allow_own normalises
D8$time_iso8601always UTC (+00:00)local timeno time-zone database in scalwsd
D9$status of an abandoned requestthe status ScalWS produced499ScalWS has no 499
D10rewrite_locationLocation onlyalso Refreshnot used by previewed sites
D11gzipgzip and brotligzipthe client chooses
D12limits.max_connectionsexcess waits in the kernel backlogrefused1.0 kept

Consequences

  • ScalPanel’s generator output loads with scalwsctl check and no warning, and the contract test (tests/integration/fixtures/scalpanel-edge) serves every scenario of the sample on both HTTP/1 stacks.
  • Configurations without the new keys keep their behaviour and cost. Two 1.0 behaviours change for everyone: proxied responses carry Server: scalws (D5), and a Gateway-style redirect with keep_path: false drops the query (D4). burst: 0 is no longer an error.
  • Network files and the country database are read when a configuration is built (start, scalwsctl check, reload). A missing or invalid file fails the load; the old configuration stays. Unchanged files (path and identity) are not read again.
  • Under scalws-controller, max_upgraded is divided among the instances, as the other per-client limits are: each instance gets ceil(n / instances), at least 1.
  • rewrite_location infers the removed prefix from the paths: when the rewritten path is a suffix of the client’s path, the part in front counts as removed, even when the rewrite did not remove it (rewrite.path: /index.php for /blog/index.php gives /blog). The result is always a path on the same host.
  • Edge gzip of dynamic pages has the BREACH exposure nginx’s edge has today; it is documented, and Cache-Control: no-transform is honoured.
  • Site containers route on X-ScalPanel-Site, so D6 and D7 change nothing for ScalPanel.