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_costrows are unchanged). - Route order (D1).
route_order: nginxon 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(nginxlocation /sp-ab12/). It is stored as/sp-ab12, sorewrite.prefixand a redirect’sprefixreplace/sp-ab12plus the slash. - Network sets.
server.networks.<NAME>is a CIDR listfileor a list ofcountrieslooked up inserver.geoip.database(a MaxMind DB format file, read into memory, nommap). Routes name sets indeny_networksandallow_networks. A client is refused whendenyordeny_networksholds it, or when an allow list is set and neitherallownorallow_networksholds it. The client is the address the server resolved fromserver.trusted_proxies(headerserver.client_address.header) and theserver.client_address.presetsnetworks (the vendor’s header, such asCF-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 updateinstalls 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 nginxvalid_referers(none blocked server_namesand host names), with a strict parser. A refusal answersstatus(default 403) withCache-Control: no-store; routes withreferernever use the response cache. - Request and proxy changes.
request_headers.remove_cookiesdrops named cookies from everyCookieline. Proxyforwarded_for: clientsends oneX-Forwarded-Forvalue andX-Real-IP.rewrite_locationputs the prefix the route’s rewrite removed in front of a pathLocation;cookie.path_prefixandcookie.domain: request_hostrewriteSet-Cookie.server.security.per_ip.max_upgradedlimits upgraded tunnels per client address (429). - Access log files.
access_log: {file, format}on an application or route, formatcombinedorscalpanel(ScalPanel’s nginxlog_format, byte for byte, with nginx\xHHescaping). One writer thread and one bounded queue for all such files;SIGUSR1,scalwsctl reopen-logsandPOST /v1/logs/reopenreopen every log file. - Server-wide compression.
server.compression.enabled,typesandmin_length: every application without its owncompressioncompressestypesplustext/html(nginxgzip onwithgzip_types).min_lengthreplaces 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_cookiesincluded), runtime (max_upgradedat the upgrade), response headers (rewrite_locationandcookiebefore the route’sresponse_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 --versionprintsedge-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
| Id | Where | ScalWS 1.1 | nginx or the generator | Why |
|---|---|---|---|---|
| D1 | route order | opt-in route_order: nginx; default exact, prefix, regex | exact, regex, prefix | released 1.0 order kept (Q1) |
| D2 | referer with a malformed http(s):// value | refused | refused | parity |
| D3 | per_ip.burst: 0 | accepted: a bucket of one request | limit_req without burst | ScalWS burst is the bucket size; parity is nginx burst plus one (Q3) |
| D4 | redirect keep_path: false with Gateway fields | drops the query (1.0 kept it) | return 302 https://$host:2096/ | parity |
| D5 | Server of proxied responses | scalws (the upstream’s is dropped) | upstream’s hidden | no upstream version leaks; a 101 keeps the upstream’s |
| D6 | request_headers.set with "" | header sent empty | header not sent | 1.0 kept; the client’s value never passes either way (Q2) |
| D7 | preserve_host | the client’s authority as sent | $host (lower case, no port) | 1.0 kept; allow_own normalises |
| D8 | $time_iso8601 | always UTC (+00:00) | local time | no time-zone database in scalwsd |
| D9 | $status of an abandoned request | the status ScalWS produced | 499 | ScalWS has no 499 |
| D10 | rewrite_location | Location only | also Refresh | not used by previewed sites |
| D11 | gzip | gzip and brotli | gzip | the client chooses |
| D12 | limits.max_connections | excess waits in the kernel backlog | refused | 1.0 kept |
Consequences
- ScalPanel’s generator output loads with
scalwsctl checkand 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 withkeep_path: falsedrops the query (D4).burst: 0is 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_upgradedis divided among the instances, as the other per-client limits are: each instance getsceil(n / instances), at least 1. rewrite_locationinfers 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.phpfor/blog/index.phpgives/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-transformis honoured. - Site containers route on
X-ScalPanel-Site, so D6 and D7 change nothing for ScalPanel.
Related
- ADR-0022 (trusted proxies), ADR-0050 (route matching, amended 2026-11-18), ADR-0053 (response compression).
- Guides: ScalPanel edge, network sets, hotlink protection.