Hardening
Zion applies security defaults that can be overridden via configuration.
Response headers
Every HTTPS response includes these security headers (stored as static HeaderValue constants):
| Header | Value | Purpose |
|---|---|---|
Strict-Transport-Security | max-age=63072000; includeSubDomains; preload | Force HTTPS for 2 years |
X-Content-Type-Options | nosniff | Prevent MIME sniffing |
X-Frame-Options | DENY | Block iframe embedding |
Referrer-Policy | strict-origin-when-cross-origin | Limit referrer leakage |
Permissions-Policy | camera=(), microphone=(), geolocation=(), payment=() | Disable browser APIs |
Server | (removed) | No server identification |
Method whitelist
Only these HTTP methods are accepted. All others return 405 Method Not Allowed:
GET POST PUT PATCH DELETE HEAD OPTIONSThis blocks TRACE (cross-site tracing), CONNECT (proxy tunneling), and non-standard methods before any processing occurs.
URI length limit
Requests with URI paths exceeding 8,192 bytes return 414 URI Too Long.
Header limits
Hyper is configured with reduced header limits compared to defaults:
| Parameter | Zion | Hyper Default |
|---|---|---|
| Max header count | 64 | 100 |
| Max header buffer | 16 KB | 400 KB |
Rate limiting
Per-IP rate limiting using DashMap with atomic counters:
[server]
rate_limit_rps = 100 # Max requests per IP per window
rate_limit_window_secs = 1 # Window durationWhen rate_limit_rps = 0 (default), rate limiting is disabled — the code returns before accessing any map. Over-limit requests return 429 Too Many Requests.
Timeouts
| Timeout | Duration | Purpose |
|---|---|---|
| TLS handshake | 10 seconds | Prevent TLS slowloris |
| HTTP request | 60 seconds | Kill stalled connections |
| Upstream connect | 3 seconds (configurable) | Fail fast on dead upstreams |
| Connection pool idle | 30 seconds | Reclaim unused upstream connections |
| TCP keepalive (clients) | tcp_keepalive_secs, 60 s | Free the slot of a peer that vanished while the connection was idle |
TCP_USER_TIMEOUT (clients) | tcp_user_timeout_secs, off (opt-in, Linux) | Free the slot of a client that vanished while a response was in flight; also drops a client that stops reading for longer than the value |
| Response waiting for a client that takes nothing of it | send_stall_secs, 300 s | Reset that HTTP/2 or HTTP/3 stream, or close that HTTP/1.1 connection, and free the file, share or upstream connection it holds (below) |
| Upstream DNS lookup | dns_timeout_ms, 2000 ms | A resolver outage or hang falls back to the last good answer instead of stalling connections |
Connection limit
The number of client connections held open at once, on both listeners together, is bounded by a semaphore. The connection that would exceed it is closed at accept, before the TLS handshake, and counted in zion_connections_rejected_global.
By default the ceiling is derived from memory:
conn_limit = (memory_MB / 4) * 1024 / 256 # a quarter of the memory, 256 KB per connectionclamped to 1,000–100,000. The memory is the machine's RAM, or the cgroup limit when one is set below it (memory.max or memory.high of the cgroup or any of its ancestors; memory.limit_in_bytes on cgroup v1): a container, a Kubernetes pod, a systemd unit with MemoryMax=. Before v0.10 the limit was ignored, so a pod limited to 512 MiB on a 32 GiB node admitted 31,980 connections and would be killed by the kernel long before it shed one; it now admits 1,000. The boot report shows which figure was used (ram 512 MB (cgroup limit; the host has 32.0 GB)).
[server] max_connections sets the ceiling explicitly, to go above 100,000 on a large machine or below the derived value where memory is tight. It is read at start; a reload that changes it is refused.
What a connection costs, measured on Linux (release build, 2,000 connections in each state):
| State of the connection | Memory |
|---|---|
| TLS handshake done, no request yet | 14 KB |
| HTTP/1.1 keep-alive, idle after a request | 46 KB |
| HTTP/2, idle after a request | 49 KB |
| HTTP/1.1, a large static file being sent to a client that is not reading | 829 KB |
| HTTP/2, the same on one stream (a connection carries up to 128 streams) | 903 KB |
The 256 KB of the formula is a budget between the idle and the busy figures, not a bound: 1,000 connections that are all stuck mid-download hold about 900 MB. Where that matters (a small container that serves large files), set max_connections from the busy figure, and max_connections_per_ip (an eighth of the ceiling by default) so that one address cannot take the whole of it.
The HTTP/2 row is one stream, and a connection carries up to 128 (an HTTP/3 connection, 256). On a static route at most eight of them stream a file at once, and the smaller files read whole share 4.5 MiB, so one connection that does not read holds at most eight files open and about 10.5 MiB of file data (eight streamed responses of up to 768 KiB, and 4.5 MiB), not one file per stream. One address may open an eighth of the ceiling's connections (and over QUIC, any number), so every static response also takes from its address's share of a budget for the whole process: 256 MiB of 2 GiB on a 16 GiB host (see HTTP/2 responses a client does not read). A proxied route has no such cap: each stream a client does not read holds an upstream connection until send_stall_secs resets it.
New-handshake floods
The connection caps above bound how many connections a source holds open at once; they do not bound how fast it opens new ones. The expensive part of a TLS 1.3 handshake is the server signature: a source that connects, handshakes and closes in a loop makes zion pay that signature every time while paying almost nothing itself (one loopback client drove about 4 cores with an RSA-2048 certificate: 7,419 full handshakes/s at 397% of a core; ECDSA P-256 is cheaper, 9,547/s at 136%). max_handshakes_per_ip_per_sec caps that rate per source IP (per /64 for IPv6), enforced at accept before the handshake, so a rejected attempt costs one map probe and an immediate close. It is a token bucket: the setting is the sustained rate, handshake_burst_per_ip the burst. The default (1,000/s, burst 2,000) is a generous threshold between a thundering herd behind one CGNAT IP (low hundreds/s) and a flood, on by default; handshake_rate_allowlist exempts named sources, and 0 disables it. Rejections are counted in zion_connections_rejected_handshake_rate.
TLS client fingerprints (JA4)
Needs --features tls-fingerprint. Zion computes the JA4 fingerprint of each TLS ClientHello before the handshake (it peeks the bytes, the handshake then reads them as usual):
[tls.fingerprint]
mode = "shadow" # off (default) | shadow | allowlist
on_unknown = "log_only" # allowlist: log_only (default) | drop
on_unfingerprintable = "allow" # allowlist: allow (default) | drop
ban_ttl_secs = 600 # allowlist + drop: seconds a rejected JA4 stays banned; 0 = no ban set
[[tls.fingerprint.allowed]]
name = "chrome-131"
ja4 = "t13d1516h2_8daaf6152771_e5627efa2ab1"
rate_limit_cps = 0 # new TLS connections per second for this JA4; 0 = no limit
allowed_routes = [] # route patterns this JA4 may request; empty = no restrictionmode:offdoes nothing and costs nothing.shadowcomputes the JA4 and counts known and unknown (zion_tls_fp_known,zion_tls_fp_unknown) without ever blocking.allowlistalso enforces.on_unknown(allowlist): what happens to a JA4 not inallowed.log_onlycounts it and lets it through;dropcloses the socket before the handshake (zion_tls_fp_rejected).on_unfingerprintable(allowlist): a ClientHello that cannot be fingerprinted (the peek timed out, the record is larger than the buffer, it is not TLS).allowkeeps availability first;dropfails closed.ban_ttl_secs(allowlistwithon_unknown = "drop"): once a JA4 is rejected, repeat connections with it are rejected on a fast path for this many seconds, with one map lookup and a debug-level log instead of a warning each (zion_tls_fp_banned_hits). Bans survive config reloads, not restarts.rate_limit_cps: a cap on new TLS connections per second for this fingerprint. These are connections, not requests: the gate runs before the handshake. Over the cap, a connection is dropped inallowlistand only counted (zion_tls_fp_rate_limited) inshadow.allowed_routes: the routes this fingerprint may request, with the same pattern syntax as[[route]] path. A request outside them gets403inallowlistand is only counted (zion_tls_fp_route_denied) inshadow. The list grants the whole request surface, so a restricted scraper needs/metricson it;/healthzand/readyzare always allowed. An invalid pattern refuses the config.
JA4 and User-Agent consistency
Needs --features tls-fingerprint and [tls.fingerprint] in shadow or allowlist mode. A client that forges only its User-Agent string (curl, a Go or Python HTTP client saying it is Chrome) still shows the TLS fingerprint of the library it really is. [tls.fingerprint.ua_check] compares the two.
Zion ships no fingerprint database. You name, in [[tls.fingerprint.allowed]], the JA4s you have seen and know to be tools, and list those names in tool_names:
[tls.fingerprint]
mode = "shadow"
allowed = [
{ name = "curl", ja4 = "<the JA4 of your curl>" },
{ name = "chrome", ja4 = "<the JA4 of your Chrome>" },
]
[tls.fingerprint.ua_check]
mode = "shadow" # off (default) | shadow | enforce
browser_ua = ["Chrome/", "Firefox/", "Safari/"]
tool_names = ["curl"]To read a client's JA4, connect with it to a zion in shadow mode and look at the X-Client-TLS-JA4 header your upstream receives.
A request is a mismatch when its User-Agent contains one of browser_ua (ASCII case-insensitive) and its connection's JA4 is one named in tool_names. enforce answers it with 403; shadow only counts it. Nothing else is ever refused:
| Request | Verdict |
|---|---|
browser User-Agent, JA4 of a tool_names entry | mismatch |
browser User-Agent, any other JA4 (known or unknown) | consistent |
browser User-Agent (in any of its values), no JA4 | not compared, counted in zion_tls_fp_ua_no_ja4 |
no User-Agent, or one that does not claim a browser | not compared |
What it does not do:
- It is a soft signal. It catches the client that forged the
User-Agentonly; one that also forges its ClientHello is not caught. - HTTP/3 carries no JA4, and neither does a
:443connection whose ClientHello could not be fingerprinted, so those requests are never compared. Watchzion_tls_fp_ua_no_ja4to see how much of your browser traffic that is. The plaintext:80listener serves ACME challenges and redirects only, so there is no application traffic on it to compare. - Every
User-Agentvalue of a request counts: a request carryingcurl/8.5andChrome/131in two headers claims a browser. - An unknown JA4 is never a mismatch. A browser update changes its JA4: keep the
chromeentry current, or it is simply not named as a tool. /healthzand/readyzare never refused.
Start in shadow and read the counters before enforce: zion_tls_fp_ua_checked (compared), zion_tls_fp_ua_mismatch (flagged) and zion_tls_fp_ua_no_ja4 (not comparable). A config that could never fire (the fingerprint mode off, an empty browser_ua or tool_names, a tool_names entry that matches no allowed name) is refused at boot.
HTTP/2 control-frame floods
HTTP/2 has frames that carry no request and that a server must still read, and often answer: PING, SETTINGS, WINDOW_UPDATE, PRIORITY, RST_STREAM. One connection can send them as fast as the network takes them. The HTTP/2 library bounds streams reset as soon as they are opened (Rapid Reset, CVE-2023-44487) and nothing else, so such a connection was served to its last frame and never closed. The cost per frame is small (two million PINGs cost about 0.13 s of one core), which makes this a way to keep a core busy per connection, not an outage; the per-IP connection limit was the only bound.
[server] h2_control_frames_per_sec closes a connection that sends more than that many control frames in one second, with GOAWAY(ENHANCE_YOUR_CALM):
[server]
h2_control_frames_per_sec = 1000It is off by default (0): a limit that is wrong for your clients closes their connections, and Zion has not measured every client. With no limit the frames are still counted, and zion_h2_control_frames_peak reports the most any one connection sent in a second: read it on your traffic, then set the limit well above it.
What counts, and what does not:
| Frame | Counted |
|---|---|
PING, SETTINGS (and their acks), PRIORITY, GOAWAY | yes |
| A frame type the server does not know (it reads and drops it) | yes, or it would be the way around the limit |
DATA with no payload that does not end its stream | yes |
RST_STREAM | only beyond the streams the connection opened: cancelling a request is free |
WINDOW_UPDATE | separately: 1,000 a second, plus one per 256 bytes of response written to the client in that second |
HEADERS, CONTINUATION, DATA with a payload | no: that is a request, bounded by the stream, header-size and rate limits |
Measured on one connection:
| Client | Control frames per second | Response bytes per WINDOW_UPDATE (300 MB download) |
|---|---|---|
curl 8.7 (--http2) | 2 | 5 MB |
| nghttp 1.69, default and 64 KiB windows | 2 | 18 KB |
| h2load 1.69, 100 streams per connection | 2 | over 100 MB |
| Chrome 154 | 2 to 3 | 2.2 MB |
| Chrome 154 cancelling 100 downloads in flight, three times in a second | 2 (and 302 RST_STREAMs, not counted) | 5 MB |
So 1000 is over 300 times what these clients send, and their WINDOW_UPDATEs are 70 times or more under the allowance of one per 256 bytes.
grpc-go is different. It sends a PING with the data it receives, to estimate bandwidth, so its rate follows the round-trip time. Measured through zion (the rig is in benchmarks/h2-control/):
| Client-to-zion RTT | One 500 MiB download | 20,000 unary calls, 8 callers | One bidirectional stream |
|---|---|---|---|
| loopback | 726 | 2,019 | 5,003 |
| 0.2 ms | 712 | 1,411 | 1,700 |
| 1 ms | 412 | 616 | 380 |
| 5 ms | 169 | 166 | 90 |
On macOS loopback a bidirectional stream reached 17,200. A limit of 1000 would close busy grpc-go connections inside a data centre. If gRPC goes through zion, read zion_h2_control_frames_peak on real traffic and set the limit well above it (20000 leaves even loopback grpc-go alone), or leave it at 0. The C-core gRPC clients (Python, Ruby, C#, PHP) measured 6 to 13. Firefox and Safari have not been measured: benchmarks/h2-control/rig.sh browser does it.
The bound applies however the client got to HTTP/2: ALPN h2, a TLS connection that negotiated nothing and opens with the HTTP/2 preface, or the preface on the plaintext listener. A closed connection is counted in zion_h2_control_flood_closed_total{reason} and logged with the client address (one line a second at most). The GOAWAY is sent if the connection takes it at once; a client that is still sending when the socket closes may see a reset instead.
HTTP/2 responses a client does not read
HTTP/2 flow control lets a client stop a response wherever it likes: a stream whose window is zero is sent nothing more, and the server waits with the next chunk of the response in hand. The HTTP/2 library puts no deadline on that wait, and the keep-alive PING (every 30 s) does not help: it asks whether the client is alive, and a client that answers it can keep its windows closed for the hour a connection may last. Whatever the response holds stays held: on a static route the open file and up to 768 KiB of it, on a proxied route an upstream connection. One connection opens up to 128 streams, and v0.18.0 held a file for each: 128 descriptors to a 2 MiB file for 128 requests on one connection with its windows closed. One address may hold an eighth of the connection ceiling (2048 connections on a 16 GiB host): 262,144 files, sixteen for every connection of the ceiling, where the descriptor budget is about two. Eight files and 4.5 MiB read whole per connection, the first bound below, still let that address hold 16,384 files and about 21 GiB of file data: more than the host. HTTP/3 has the same hold through QUIC's flow control, with 256 streams to a connection and no per-address connection cap at all. Past the descriptor limit, accepts and upstream connects fail with EMFILE.
Three bounds apply:
Per connection, on HTTP/2 and HTTP/3: eight large static files at once, and a budget for small ones. A
GETon a static route takes a slot of its connection before the file is opened. A file above 576 KiB is streamed with the file open, and takes one of eight file slots, whatever range of it is asked for. A smaller one is read whole, and takes its length out of a budget of 4.5 MiB, eight of the largest. The two are apart so that a page's stylesheets, scripts and images are never kept waiting by large files being sent on the same connection. A request that finds no slot waits for one, holding no file and no buffer: what it waits for is its own client's. AHEADtakes none. A connection from atrusted_proxiespeer has no such slots: a proxy that multiplexes many clients over one HTTP/2 connection would make them wait for each other.Per client address and for the whole process, on every protocol: a budget for what static responses hold. Every static
GET, on HTTP/1.1, HTTP/2 and HTTP/3, also takes the bytes it may hold from a budget derived from the host: 128 KiB for each connection of the connection ceiling, at most an eighth of the memory the process may use, at least 6 MiB. A streamed response is counted as 768 KiB, what it holds when stalled, so the budget also bounds the files held open, to a sixth of the connection ceiling. There is no separate count of open files for that reason: the descriptor budget gives each connection of the ceiling two, so a file counter sized from it would sit far above the sixth the bytes already allow, and never be the bound that applies. One client address may hold an eighth of it, as it may hold an eighth of the connections. The address is the peer's, keyed as the per-IP connection cap keys it, or on a connection from atrusted_proxiespeer the client the request resolves to (the addressX-Real-IPcarries). A request that finds its address's share or the budget spent waits at most 10 s, holding nothing, and is then answered503: what it waits for may be another client's, and a client that does not read keeps what it holds untilsend_stall_secsresets it, five minutes by default. The boot log gives the budget (static responses may hold ...):Host Connection ceiling Budget One address Streamed files, all / one address 16 GiB (the boot log of a 16 GiB macOS host with no descriptor limit; a Linux host with LimitNOFILE65535 derives the same ceiling)16384 2 GiB 256 MiB 2730 / 341 max_connections = 1024(the tests below)1024 128 MiB 16 MiB 170 / 21 512 MiB container (computed, not run) 1000 64 MiB 8 MiB 85 / 10 Waits are counted in
zion_static_budget_waited_total, refusals inzion_static_budget_refused_total. There is no setting:max_connectionssizes the budget with the ceiling.A deadline on a response nothing is taken from, on every protocol. When a response has had a piece ready for
[server] send_stall_secs(default 300) and the client has not taken it (an HTTP/2 or HTTP/3 client that does not open its window, an HTTP/1.1 client that does not read its socket), that one stream is reset (HTTP/2RST_STREAM(CANCEL), HTTP/3H3_REQUEST_CANCELLED) and the connection and its other streams go on; HTTP/1.1 cannot cancel one response, so its connection is closed. Its file, its buffers, its slot and share and its upstream connection are freed, static and proxied routes alike. On HTTP/1.1 a piece counts as taken once the kernel has taken it into the socket's buffer, and the deadline is checked before the connection is polled again: polled first, a connection on macOS found room the kernel had made in that buffer without waking it, handed over one more piece, and so closed at 6.0 s under a 3 s deadline instead of 3.0 s. A body is handed to the HTTP/2 library in pieces of at most 64 KiB, and HTTP/3 sends at most 64 KiB at a time, whatever the size of the body's chunks: the library takes a piece as soon as the window has room for one byte of it, so a larger chunk (a static file read whole is one chunk of up to 576 KiB, a proxied chunk can be hundreds of KiB) had to be taken whole within the deadline, and the last chunk of a response left the stream with no deadline at all. On HTTP/2 a static response also ends its stream only once its last piece has left the library's buffer, with one emptyDATAframe that carries the end, so the deadline covers the whole of it. The time counts from the last piece the client took, not from the start of the response: a client that takes 64 KiB or more in every 300 s is never cut, whatever the size of the response. A stream waiting on its own source (a slow upstream, an event stream with nothing to send) is not waiting on the client, and no deadline applies. Resets and closes are counted inzion_streams_stalled_total.0turns the deadline off. It applies on both listeners (h2c and HTTP/1.1 on the plain one too, which serves no static route).
[server]
send_stall_secs = 300 # 0 = no deadlineMeasured with the debug build on macOS (one run each, tests/static_memory.rs), v0.18.0 against this version:
| Case | v0.18.0 | Now |
|---|---|---|
| One connection, 128 requests for a 2 MiB file, windows closed | 128 descriptors | 8 |
| The same over HTTP/3, no stream credit | not measured | 8 |
| One connection, 128 requests for a 576 KiB file, windows closed | 5 to 87 MiB, 128 begun | 5 to 22 MiB, 8 begun |
| The same, each window opened by one byte | 5 to 90 MiB, 128 begun | 5 to 22 MiB, 8 begun |
| The same through a route that compresses with brotli | 12 to 360 MiB, 128 begun | 12 to 41-85 MiB over three runs, 8 begun |
| One connection, 100 requests for a 32 MiB file | 5 to 80 MiB | 5 to 22 MiB |
A route with precompressed = true, 64 requests for a 2 MiB file | 64 descriptors | 8 |
One address, 16 HTTP/2 connections, 8 requests each for a 2 MiB file, windows closed, max_connections = 1024 | 128 descriptors, 5 to 97 MiB | 21 descriptors, 5 to 30 MiB; the other 107 answered 503 10.1 to 10.8 s in |
| The same over 16 HTTP/3 connections | 128 descriptors, 5 to 80 MiB | 21, 5 to 28 MiB |
| The same over 30 HTTP/1.1 connections, one request each for a 32 MiB file, not read | 30 descriptors | 21 |
| One trusted proxy connection carrying 100 clients, one 2 MiB file each, then 40 requests from one client and 100 more clients | 240 responses begun | 100 on the one connection, 21 for the one client, 170 in all (the budget) |
| A 20 KiB file asked for beside eight stalled 2 MiB responses on one connection | 0.20 s | 0.21 s |
With send_stall_secs = 2, every stalled stream is reset about 2 s in (2.00 s on HTTP/2, 1.95 s on h2c, 2.08 s for the descriptors on HTTP/3), its file closed and the reset counted. A batch client that keeps the default 65,535-byte windows and reads no body until 30 responses for a 200 KiB file have begun gets 23 at once, the 23 reset at 2.06 s and the other seven begun then; with the 64 KiB pieces and the held end both taken out of the code, no stream was reset in 7 s and the seven never began. A 20 KiB file to a window of one byte is reset at 2.06 s (not within 5 s without the held end). A proxied download of 768 KiB whose upstream sends it in one write, read 64 KiB every 600 ms, completes in 7.3 s; handed over in the upstream's chunks, it was reset 4.3 s in, 448 KiB in, though the client never stopped reading. Over HTTP/1.1, 21 clients of one address that stop reading a 32 MiB file (a 16 MiB share, send_stall_secs = 3) have their connections closed at the deadline, and a 22nd request from the address, waiting for the share, is answered 200 3.03 s in (without the deadline, 503 at 11.1 s); a proxied 16 MiB download not read for 4 s gets 450,917 bytes and the close (all of it without the deadline); a reader that takes 64 KiB every 300 ms through a 16 KiB receive buffer gets all of a 2 MiB file in 8.1 s under a 2 s deadline (cut at 4.3 s, 1 MiB in, with a deadline counted from the first piece). A client that reads 64 KiB every 400 ms outlasts a 2 s deadline on HTTP/2 and HTTP/3. When the address's share is held by streams that do not read and send_stall_secs = 3, the 11 requests waiting behind them begin once those are reset (3.1 s in), none refused; 64 requests for a 2 MiB file from one address that reads them are all served in 0.64 s, none refused.
What the three do not cover:
- A proxied route has no per-connection cap and no budget: a client can still hold one upstream connection per stream it does not read, for up to
send_stall_secs, and open new streams after the reset. The per-IP connection cap bounds it, and[upstream.x] max_in_flightwhen it is set. The last piece of a proxied response (64 KiB at most) is handed to the HTTP/2 library with the end of the stream, and what the client does not read of it waits in the library's buffer with no deadline: by the code, at most 64 KiB for each of the 128 streams a connection may hold open (a stream whose bytes are still buffered counts against that cap), the upstream connection free by then. This was not measured. On HTTP/3 the QUIC library holds what it accepted, within the credit the client granted. - About eight client addresses that fill their shares spend the budget for the whole process. After that, static
GETs from every client wait 10 s and get503, untilsend_stall_secsresets the holders (which must then ask again). This replaces the previous outcome, memory exhaustion of the host. Measured withmax_connections = 1024(128 MiB, 16 MiB a share,send_stall_secs = 15), the eight addresses being clients named by a trusted proxy, since on macOS the loopback addresses 127.0.0.2 and up cannot be bound without configuring them as root: eight clients held 168 streamed responses, a ninth got the 2 the budget had left and503for its other 3 at 12.1 s (10 s after it asked), the holders were reset at 15.1 s, and the ninth's next request began at once (asked at 17.0 s). A risingzion_static_budget_refused_totalis the signal to alert on. What an operator can do: lowersend_stall_secs, so that holders that do not read are reset sooner; raisemax_connectionsor the memory the process may use, which sizes the budget; put a proxy that resolves clients intrusted_proxies. - Many clients behind one address (a large NAT) share one address's share, as they share the per-IP connection cap. Behind a proxy of yours, list it in
trusted_proxies. - A client that takes one piece just inside each deadline keeps its stream, at the cost of reading it (64 KiB per 300 s per stream at the default).
- A slot is held for as long as its response is being sent, whether the client reads or not. A ninth large file asked for on one connection gets no response, not even its headers, until one of the eight has been sent in full or reset: behind eight long downloads, for as long as the first of them takes (measured: 8.20 s behind eight 2 MiB downloads each read 64 KiB every 250 ms, the instant the first of them ended), and behind eight paused videos, up to
send_stall_secs. A client that wants the headers of more than eight large responses before it reads the body of any of them (a page that awaits everyfetchof a batch before it reads one) waits untilsend_stall_secsresets the eight it does not read, and those then fail (measured with nine requests for a 2 MiB file sent at once: the last headers came 2.06 s in under a 2 s deadline, 10.06 s in under a 10 s one, as the eight were reset). The same holds for more than 4.5 MiB of small files unread, which a browser does not reach: its windows are larger than such files, so they are sent at once. Over HTTP/1.1 a browser knows it has six connections to a host and queues its requests by priority; over HTTP/2 it believes it has 128 streams, so the wait is zion's, and it follows no priority: requests sent together take the free slots in the order zion has looked at their files, not the order they were sent (in the two runs above, the one left waiting was the first and the seventh sent).
Protecting the upstream
Two opt-in, per-upstream limits keep a struggling backend from taking the proxy down with it (see the resilience guide for how they combine):
max_in_flight: at most N requests inside the upstream; the next gets503+Retry-Afterimmediately instead of one more connection, buffered body and waiting task. Taken after auth and the WAF, so a hostile request cannot use up slots.circuit_breaker: stops sending traffic to a single-endpoint upstream whose real requests are failing, answers503at once, and probes it with one request.
Logs and personal data
The access log, the audit trail and TLS-handshake failure lines carry the client address. [redact] ip writes it as is (default), as its network (203.0.113.0/24, 2001:db8:1::/48), or as a keyed, irreversible, per-client-stable token (hmac, with the key from ip_hmac_key_env); header and query-string values are redacted with [redact] headers / query_params. See Client IP privacy. Log lines go through a bounded queue: a stalled log pipe drops the newest lines (counted in zion_log_lines_dropped_total) instead of stalling requests.
HTTP to HTTPS redirect
Port 80 serves only two purposes:
- ACME challenges: a token Zion's own ACME client issued is answered from memory. Any other
/.well-known/acme-challenge/*request is proxied to the route's upstream only when it is aGETorHEADwith no body, with aHostthe HTTPS listener accepts (on HTTP/1.1 exactly one, valid), and the route has nothing that shortcut would skip (no auth, WAF, restrictions,internal_only, static mode, bulkhead or circuit breaker; see ACME); otherwise it is redirected like everything else - Everything else:
301 Moved Permanentlyredirect tohttps://
The Host header is validated before use in the redirect URL:
- Must be non-empty and <= 253 characters
- Must not contain
/,\,@, newlines, or spaces
Internal-only routes
Routes marked with internal_only = true are restricted to private IPs:
127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12,
192.168.0.0/16, 169.254.0.0/16, ::1External requests receive 403 Forbidden.
Linux-specific options
On Linux, Zion enables additional socket options when the kernel supports them:
TCP_DEFER_ACCEPT: Kernel holds connections until client sends dataTCP_FASTOPEN: TFO for returning clients (requires kernel support)SO_REUSEPORT: Kernel-level connection distribution across listeners
0-RTT replay protection
TLS 1.3 0-RTT is enabled but gated by HTTP method. Non-idempotent methods (POST, PUT, PATCH, DELETE) on early data receive 425 Too Early (RFC 8470). Only GET and HEAD are allowed on 0-RTT data.
See TLS Configuration → 0-RTT Replay Protection for details.
Hop-by-hop header stripping
Zion strips the following hop-by-hop headers from upstream responses before forwarding to clients (RFC 7230 §6.1):
Connection, Keep-Alive, Proxy-Authenticate, Proxy-Authorization,
TE, Trailer, Transfer-Encoding, UpgradeX-Forwarded-For policy (xff_mode)
Outbound XFF behaviour is configured at [server] level. The default (append) is correct when Zion sits behind a sanitising edge (CDN/ALB) that has already vetted the inbound chain. When Zion is the front edge, the default is unsafe: a client can send X-Forwarded-For: 1.2.3.4 and the leftmost entry in the chain forwarded to your upstream will be that attacker-controlled value. Downstream apps that read XFF[0] for ACL or audit will be tricked.
[server]
xff_mode = "rewrite" # one of: "append" | "rewrite" | "drop"| Mode | Inbound XFF | Outbound XFF | Use when |
|---|---|---|---|
append (default) | preserved | one line: the inbound lines joined in order, then the resolved client IP | Zion is behind a trusted edge that already strips/normalises XFF |
rewrite | dropped | single entry: the resolved client IP | Zion is the front edge — guarantees a clean one-hop chain regardless of what the client sent |
drop | dropped | not emitted | Upstreams must not learn the client IP at all |
X-Real-IP is always set from the resolved client IP and never trusted from inbound headers, regardless of xff_mode. The "resolved client IP" is the output of TrustedProxies::resolve_client_ip: the TCP peer IP when it is not in trusted_proxies; otherwise the rightmost X-Forwarded-For entry that is not a trusted-proxy CIDR, or the peer IP when every entry is trusted or there is none. How the header is read:
- Every
X-Forwarded-Forfield line counts, in order, as one list: a proxy that adds a line of its own (HAProxyoption forwardfor) puts the client it saw on the last one. - An entry may be
ip,ip:port,[ipv6]or[ipv6]:port; an empty entry is skipped. A byte that is not ASCII makes only its own entry unreadable. - An entry that cannot be read as an address (
unknown, anything else) stops the walk: a trusted proxy wrote it, the entries to its left are the client's own, and the proxy's address is not the client's. The client is then0.0.0.0, which the built-in internal rule does not admit (all such clients share one per-IP rate-limit bucket), and zion logs a warning, at most three a minute. - An IPv4 peer of a dual-stack
[::]listener (::ffff:a.b.c.d) is taken as its IPv4 address everywhere:trusted_proxies,internal_networks,handshake_rate_allowlist, the per-IP limits andX-Real-IP. An entry of those lists written in the mapped form is read as the IPv4 network it names. X-Forwarded-Foris read even when the request'sConnectionheader lists it.- The HTTPS and plain-HTTP listeners resolve the client the same way.
mTLS client certificate forwarding
When the TLS listener is configured with client-certificate verification (client_ca_path set, client_auth = "required" or "optional"), Zion extracts a stable identifier from the leaf peer certificate and forwards it to upstreams as:
X-Client-Cert-Fingerprint: sha256:<64 hex chars>The value is the SHA-256 of the leaf DER, hex-encoded with a sha256: prefix — Zion's pinned wire format for this header (the prefix names the algorithm so it can never be ambiguous). (nginx's $ssl_client_fingerprint is a similar idea but a SHA-1 digest — do not compare the two values directly.) It is collision-resistant and stable across re-issuance only when the cert bytes themselves are stable; rotating a cert produces a new fingerprint.
Earlier Zion versions emitted X-Client-Cert-DN, computed as a 64-bit XOR-fold of the first 64 DER bytes. That value was advertised as a "DN" but was neither a Distinguished Name nor collision-resistant; it was removed in v0.1.7 and replaced by X-Client-Cert-Fingerprint with no coexistence window. If your upstream still expects the old header, map it at the upstream side from X-Client-Cert-Fingerprint (note: the new value is a fingerprint, not a DN, and downstream identity mapping must be done via your roster).
Injected request-header contract
Zion's contract for the headers it sets or strips on the way to the upstream. Anything an upstream trusts for identity is Zion-owned: any inbound copy from the client is stripped before Zion re-injects the verified value, so these cannot be forged by a client. An inbound copy is stripped under any case and with any byte that is neither a letter nor a digit for any - (X_Client_Cert_Fingerprint, X.Real.IP), since an upstream that names headers the CGI way (RFC 3875, as WSGI and Rack do) reads the underscore spelling as the same variable unless it drops underscore names itself, and PHP also reads the dotted one as it.
| Header | Direction | Meaning | Since |
|---|---|---|---|
X-Forwarded-For | set per xff_mode | client IP chain (see table above) | 0.1 |
X-Real-IP | set (inbound never trusted) | resolved client IP | 0.1 |
X-Forwarded-Proto / X-Forwarded-Host | set | original scheme / the request's host, as received: the request-target's authority when the target has one (absolute-form, HTTP/2 or HTTP/3 :authority), else Host (the field routing and the cache key read); never a value with userinfo (@): such a target is a 400 before routing, such a Host is not forwarded | 0.1 (the target's authority before Host: after 0.17.0) |
X-Request-ID | set if absent, else echoed | request correlation id | 0.1 |
X-Client-Cert-Fingerprint | set on mTLS routes (inbound stripped) | sha256:<hex> of the leaf DER | 0.1.7 (replaced X-Client-Cert-DN) |
X-Client-TLS-JA4 / X-Client-TLS-* | set on TLS-fingerprint routes (inbound stripped) | verified JA4 identity | 0.7.5 |
X-Auth-Subject / X-Auth-Email | set from validated claims (inbound always stripped) | authenticated sub / email | requires --features auth |
Breaking changes to this contract are called out in the CHANGELOG; pin the header names you consume and re-check them on a major upgrade.
Hot-reload
Zion applies changes to zion.toml and to the certificate files referenced by [tls] without restarting the process. An invalid config is rejected and the previous snapshot keeps serving traffic, so the only way a config edit can break production is if it is a valid config that does the wrong thing.
The full contract — what reloads, what is left to a restart, how to verify a reload landed — is in Operations → Hot-reload.
Content-Security-Policy
Per-route CSP headers can be configured. See Routing → Content-Security-Policy.