Skip to content

Security and limits

David Reed edited this page Nov 20, 2026 · 2 revisions

A Wisp server opens sockets to wherever its clients ask. This page covers what holyWisp lets them reach, how it decides who a client is, the limits that keep one client from taking the server, the reputation table, passwords, the terminal stream gate and the systemd sandbox. Every option here is a config key and a --flag; Configuration has the syntax and ranges. The code behind it is src/server/egress.c, src/common/net.c (hw_addr_classify), src/server/stream.c and src/server/conn.c.

The defaults are meant for a public relay: everything that is not public unicast is refused, flood protection and reputation are on, any web page may connect, and nobody needs a password.

Egress policy

A stream may reach a public unicast address and nothing else unless you allow it. The check runs on the resolved addresses, after DNS, one address at a time: a name that resolves to one public and one private address connects to the public one only. A name whose addresses are all refused gets CLOSE 0x48 and the log says why:

[info] egress: 127.0.0.1: blocked localhost:5782 (loopback)

Address classes

Class IPv4 IPv6 Allowed by
public everything not below 2000::/3, less the reserved parts below always
loopback 127.0.0.0/8 ::1 allow-loopback
private 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 100.64.0.0/10 (CGNAT) fc00::/7 allow-private
link-local 169.254.0.0/16 fe80::/10 allow-link-local
unspecified 0.0.0.0/8 :: never
multicast and broadcast 224.0.0.0/4, 255.255.255.255 ff00::/8 never
reserved 240.0.0.0/4, 192.0.0.0/24, 192.0.2.0/24, 192.88.99.0/24, 198.18.0.0/15, 198.51.100.0/24, 203.0.113.0/24 2001::/23, 2001:db8::/32, 3fff::/20, everything outside 2000::/3 never

All three allow-* keys are off by default. For a relay on a LAN that should reach that LAN, turn on allow-private and nothing else.

IP literals

A CONNECT whose hostname is an IP address needs allow-direct-ip = on (off by default), and then still passes the class check above. Without it the stream is closed 0x48 and the log says blocked direct IP. Only the canonical dotted quad is an IPv4 literal. A name whose last label is a number (0x7f.1, 2130706433, 1.2.3) is closed 0x41 before any lookup, because a resolver's inet_aton would turn it into an address without asking DNS. An IPv6 literal may hold only hex digits, colons and dots, so fe80::1%eth0 is refused too.

IPv4 inside IPv6

An IPv6 address that carries an IPv4 one is judged by the IPv4 address:

Form Classified as
IPv4-mapped ::ffff:a.b.c.d exactly the IPv4 address
NAT64 64:ff9b::/96, IPv4-compatible ::a.b.c.d, IPv4-translated ::ffff:0:a.b.c.d, 6to4 2002::/16, an ISATAP interface id the IPv4 address's class when that is not public; reserved when it is

So ::ffff:10.0.0.1 and 64:ff9b::a00:1 are both private, ::ffff:8.8.8.8 is public, and 64:ff9b::808:808 is reserved: the server does not act as anyone's translator.

Hostnames

Hostnames go to the resolver as the client gave them, after these checks, each of which closes the stream 0x41: an empty host, a host over 255 bytes (a terminal stream's command line may have 4096, see Twisp gate), a NUL byte, a byte outside A-Z a-z 0-9 . - _ : [ ], port 0, and the numeric names above. DNS options (dns-server, dns-order, caching, max-pending-lookups-per-ip) are on Proxies-and-WARP.

With an upstream proxy, the check still runs here first, on the addresses this server resolved, and then the proxy is handed the hostname so it can resolve and route by name. The proxy resolves it again and may see other addresses; a proxy that can reach private networks has to check what it resolved itself. Proxies-and-WARP has proxy-only-to and its exception for a router's name gate.

Host and port filters

Key Value Repeatable
allow-host name, or *.name (or .name) for its subdomains yes, up to 1024 names per list
block-host the same yes
allow-port 443, or a range 8000-8999 yes
block-port the same yes

How they combine:

  • When any allow-host is set, only hosts on that list pass, and block-host is not consulted.
  • With no allow-host, a host on block-host is refused.
  • Ports work the same way: a non-empty allow-port list is the whole answer, otherwise block-port refuses.
  • example.com matches that name only; *.example.com matches every subdomain and not example.com itself. List both for both.
  • Names are compared lower-cased, without trailing dots, against the hostname as the client sent it, before DNS. An IP literal is compared as text.
  • A hostname too long to compare whole is not on any allow list and is on every non-empty block list.

A refused stream is closed 0x48 and counted in /stats as blocked.filter. These lists, allow-origin and warp-bypass-host can live in a policy-file, which the server reads again within a few seconds of a change without dropping anyone; see Configuration.

A typical lock-down for a relay that should only carry web traffic:

allow-port = 80
allow-port = 443
block-host = *.internal.example.org

The client's address

Every per-client limit and the reputation table are keyed by the client's address. By default that is the socket's peer. Behind a reverse proxy, every client would then be the proxy, so name the proxy:

Key Default What it does
trusted-proxy none A CIDR or address whose requests may name the client in a header. Repeatable, up to 64.
trusted-header X-Forwarded-For The header to read. Repeatable, up to 8, read in order: the first one the request carries is used.
trusted-headers-reset off on empties the header list (removing the default) before the trusted-header lines add theirs.
trusted-proxy-secret none Headers count only when the request also carries X-HolyWisp-Proxy-Secret with this value.
parse-real-ip on Off ignores the headers entirely.

The header is read the way a proxy chain writes it. Every instance of the header is joined into one list and walked from the right, the end the nearest proxy wrote. Entries that are trusted proxies are skipped; the first one that is not is the client. An entry may be ip, ip:port, [v6] or [v6]:port. An entry that is not an address (unknown, a name, an empty one) ends the walk, and the peer itself is the client. From a trusted proxy, a header too long for the server to keep whole is refused with 400.

For example, with trusted-proxy = 127.0.0.1 and a request from 127.0.0.1 carrying X-Forwarded-For: 203.0.113.5, 198.51.100.7, the client is 198.51.100.7: the proxy appended it, and 203.0.113.5 is whatever the client itself sent.

Name a header other than X-Forwarded-For only if the proxy in front overwrites it. CF-Connecting-IP is safe behind Cloudflare and nowhere else, because any other proxy passes the client's own copy through. On a host where other local processes share 127.0.0.1 with the proxy, set trusted-proxy-secret and have the proxy send it; without the secret, the request counts as coming from the proxy itself. The npm wrapper does this for you with a secret per start (Node-package). Reverse-proxy has nginx and Caddy configs.

Two places never read these headers: the max-handshakes-per-ip count, which is taken at accept by the socket's peer (and skips trusted proxies), and the WebTransport listener, where the client is the UDP peer whatever trusted-proxy says.

Origin allowlist

A browser always sends the Origin of the page that opened the WebSocket. With allow-origin set, an upgrade whose Origin is not on the list is refused 403 origin not allowed. A request with no Origin at all is not refused, since only browsers send it and a native client speaks for itself.

allow-origin = https://app.example.org
allow-origin = http://localhost:5173

Each value is scheme://host[:port], compared case-insensitively, up to 32. With none (the default) any web page can use the relay through its visitors' browsers, and whatever that page does is held against the visitor's address. A public relay leaves it empty; a relay for one site should list that site.

Admission at the upgrade

Each new connection goes through these checks in this order. The first that fails decides the answer.

Check Key (default) Answer Needs flood-protection
connections from this peer still sending their HTTP head max-handshakes-per-ip (128) 429, empty, at accept yes
the whole head within handshake-timeout-ms handshake-timeout-ms (10000) connection closed no
Origin on the list allow-origin (any) 403 no
the client's address from a trusted proxy trusted-proxy 400 if the header was cut no
new upgrades per address per window connections-limit-per-ip (200), connection-window-s (10) 429, Retry-After no
reputation tier reputation-strict (81) 403 blocked no
open connections per address max-concurrent-connections-per-ip (5000) 429, Retry-After yes
open connections in all max-concurrent-connections (50000) 503 yes
v1 with a password required password-required 426 no

A refused upgrade is not a reputation event. connections-limit-per-ip and connection-window-s are both set or both 0. Real output for the rate limit, from a server with --connections-limit-per-ip 3:

HTTP/1.1 429 Too Many Requests
Content-Type: text/plain; charset=utf-8
Content-Length: 11
Cache-Control: no-store
Retry-After: 10
Connection: close

rate limit

WebTransport sessions go through the same checks, after the QUIC handshake has validated the address (WebTransport).

Limits on streams

Limit Key (default) Counted per When hit A violation
open streams max-streams-per-conn (2048; 16 for a THROTTLE client) connection CLOSE 0x49 no
CONNECTs per second max-connects-per-source-per-second (500) client address CLOSE 0x49 yes, and a burstRate event
lookups in the resolver max-pending-lookups-per-ip (128) client address CLOSE 0x49 yes
connects in progress max-in-flight-syns-per-ip (512) client address CLOSE 0x49 yes
connects in progress max-in-flight-syns (4096) server CLOSE 0x49 no
connects per second max-connects-per-dest-per-second (100) destination ip:port that address skipped, 0x49 if none is left no
connects per minute max-connects-per-dest-per-minute (3000) destination ip:port the same no
SYN-flood signature syn-signature (on) and its keys connection and destination the connection is closed synSignature event
time to connect connect-timeout-ms (15000) stream CLOSE 0x43 (resolving: 0x42) no

Every key in this table but max-streams-per-conn, max-pending-lookups-per-ip and connect-timeout-ms needs flood-protection = on (the default); off turns them all off at once. A value of 0 turns one limit off. The per-destination limits and destination reputation are applied to every resolved address before it is dialled, so a name whose first address is a decoy cannot carry the rest past them.

The SYN-flood signature watches, per connection and per destination, the outcome of recent TCP connects. Within syn-signature-window-ms (2000), once there are syn-signature-min-samples (128) of them and at least syn-signature-failed-ratio (0.75) failed, the client is taken for a scanner or a flood: the connection is closed and both the client and the destination are scored.

A violation is something the client did on its own account. Each one adds a protocolViolation event to its reputation, and after ws-close-after-violations (64) on one connection, the connection is closed (0 never closes). With log-blocked-dials = on, every failed dial is logged at info with the client's address.

Queues and slow clients

These keep a client from making the server hold memory. Protocol explains the mechanics.

Key Default When passed
ws-write-high-water 8 MiB the connection's remotes stop being read; at twice it, the client is not read either
client-write-timeout-s 120 a client that reads nothing of its queue for this long is closed
idle-timeout-s 0 (off) a connection with no streams that has sent nothing for this long is closed (1001)
stream-queue-max 128 MiB the stream is closed 0x49
conn-queue-max 256 MiB the client is not read until the queue is at half
server-queue-max 4 GiB every connection that would queue more pauses
server-queue-max-per-ip 1 GiB the connections of that address pause

None of these drop data. Only stream-queue-max closes a stream, and a client that keeps to its CONTINUE window or upload credit never reaches it.

Bandwidth

bandwidth-limit-kbps (0, off) caps each client address, across all its connections and all workers. Uploads and downloads draw on the same budget, with one second of burst. Past it, the connection stops reading from the client and from its remotes until the budget catches up. Nothing is dropped. At 800 kbps a client gets 100 kB/s in total.

Reputation

Every client address and every destination ip:port has a score from 0 to 100. Events add or subtract their weight; the score falls by reputation-decay-per-hour (1) points an hour. reputation = on by default.

Event Raised when Source weight Destination weight
authFailure a wrong password, or none when one is required 10
twispNoAuth a terminal stream asked for without v2 and a login, while enable-twisp is on 40
synSignature the SYN-flood signature matched 25 30
burstRate over max-connects-per-source-per-second 5 (5)
protocolViolation any violation (see above) 5
privateEgress a CONNECT to an address the egress policy refuses by class 0 (20)
successfulStream a stream connected -2
requestKnownBadDest a destination at the STRICT tier was refused for this client 0

requestKnownBadDest weighs 0 by default for the reason privateEgress does: any web page can make its visitor's browser ask for any destination. Only synSignature is ever recorded against a destination, so the destination weights in parentheses have no effect today. A destination also gains 1 point for each client address that has not scored it before.

Change a weight with reputation-weight = EVENT:N (sources) or reputation-dest-weight = EVENT:N (destinations), N from -100 to 100:

reputation-weight = privateEgress:15
reputation-weight = authFailure:20

The score maps to a tier:

Tier Key (default) Effect on a client Effect on a destination
normal below reputation-warn none none
WARN reputation-warn (21) none but the log line below none but the log line below
THROTTLE reputation-throttle (51) streams per connection capped at 16 (or max-streams-per-conn if lower), announced in INFO 0xE3 none
STRICT reputation-strict (81) the upgrade is refused 403 blocked the address is skipped, CLOSE 0x48

A threshold of 0 turns that tier off. The tier is read once per connection, at the upgrade, so a connection that is already open keeps its tier.

Each time a score rises into a higher tier (WARN, THROTTLE or STRICT), the server writes one warn line naming the event that raised it, at most 20 a second per statement:

[warn] reputation: 203.0.113.7: entered tier warn (authFailure)
[warn] reputation: destination 198.51.100.4:443: entered tier strict (synSignature, from 203.0.113.7)

reputation-store names a JSON file (empty, the default: kept in memory only). It is written every reputation-save-interval-s (30; 0 never) and at shutdown, through a temporary file and a rename, mode 0600, and loaded at start. The packages set /var/lib/holywisp/reputation.json. Entries under 5 points not seen for reputation-evict-after-days (7) are dropped. To clear a score, stop the server, remove the address from the file (or the file) and start it again.

Real output: nine wrong passwords from 127.0.0.1 took its score to 88, and the next upgrade was refused.

$ curl -i -H 'Upgrade: websocket' -H 'Connection: Upgrade' -H 'Sec-WebSocket-Version: 13' \
    -H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' -H 'Sec-WebSocket-Protocol: wisp-v2' http://127.0.0.1:5746/
HTTP/1.1 403 Forbidden
Content-Type: text/plain; charset=utf-8
Content-Length: 8
Cache-Control: no-store
Connection: close

blocked

and in the server's log:

[warn] reputation: 127.0.0.1: refused, score 88 (strict)

What a client is held responsible for

Only what it did on its own account. Running into a limit that all clients share is refused and counted in /stats, and is neither a violation nor a reputation event, for the client or for the destination: the server-wide SYN cap, the per-destination connect windows, max-streams-per-conn, max-concurrent-connections, the queue budget, and a full password queue. If those were scored, one client could get a destination refused for everyone, or get other clients closed by its own flood.

Two requests are refused (0x48) without being scored, because any web page can make its visitor's browser send them: a CONNECT to a private address (privateEgress weighs 0 by default) and a terminal stream on a server with enable-twisp = off. That is also why allow-origin exists: without it, a hostile page's rate-limit events land on its visitors' addresses.

What is scored: a wrong or missing password, its own per-address caps (CONNECT rate, lookups, connects in progress), the SYN-flood signature, and probing a terminal stream that is on. Asking for a destination at the STRICT tier is recorded too (requestKnownBadDest), but weighs 0 unless you give it a weight.

Passwords

password-user = USER:PASS adds a v2 user (repeatable, up to 64). The user name is 1 to 63 bytes; an empty password is refused at start, since the password extension cannot tell it from none. PASS is either the password itself or a crypt(3) hash starting with $. password-required = on turns away every client that does not log in; it needs at least one user. With users configured but password-required = off, a login is optional, and Twisp is the only thing it opens.

A plain password is compared in constant time. A hash is checked by crypt_r on two threads of their own, never on a worker loop, because a good hash takes tens of milliseconds on purpose. A name that does not exist is hashed against some user's salt anyway, so the time an answer takes does not tell which names exist. At most 64 checks wait their turn; past that a login is answered CLOSE 0x49 and not held against the client. A failed login is logged without the user name it tried:

[info] auth: 127.0.0.1:60950: bad password

Make a hash with any tool your libc's crypt(3) understands. $6$ (SHA-512) works on every Linux; $y$ (yescrypt) and $2b$ (bcrypt) need libxcrypt, which current Debian, Ubuntu and Fedora have. On macOS the system crypt(3) knows only the traditional DES form and none of these $id$ formats, so the server refuses a $5$, $6$, $y$ or $2b$ password at start: use plain passwords there. Windows has no crypt(3), and the server refuses any hashed password at start.

$ openssl passwd -6 'correct-horse'
$6$...
password-user = demo:$6$<salt>$<hash>
password-required = on

The config file that holds these is installed root:wisp mode 0640 and is never logged; a config error names the key, not the value (Install-and-run). Clients log in with holywisp-client --user NAME and the password from --pass-file or $HOLYWISP_PASSWORD (Client-and-benchmarks).

Twisp gate

Twisp terminal streams run the client's command line on a pseudo-terminal as the server's user (Protocol has the packets). Nothing in the config narrows what the command may be, so access control is the gate alone, and all three parts must hold:

  1. enable-twisp = on (off by default).
  2. The connection is Wisp v2.
  3. The client logged in with a configured password-user.

The server refuses to start with enable-twisp unless enable-v2 is on and a password-user exists, and refuses it on Windows. A terminal CONNECT that fails the gate is closed 0x48; while enable-twisp is on that is also a twispNoAuth event (40 points, so two of them reach THROTTLE and three reach STRICT). Past the gate, a terminal CONNECT counts against max-connects-per-source-per-second like a TCP or UDP one (0x49 and a burstRate event past it). Its command line, carried where a host name would be, may be up to 4096 bytes with no NUL, and is split as a shell would into at most 64 arguments; the host rules (255 bytes, the allowed characters) do not apply to it. Every terminal that opens is logged with the program it ran:

[info] twisp: <peer>: stream 1 exec bash (pid 12345)

Leave it off unless you need a shell through the relay.

The systemd sandbox

The packages install deploy/systemd/holywisp.service, which assumes that a memory-safety bug in the server is possible and bounds what a compromised process, or a shell that Twisp started, can do. It runs as the wisp user with no capabilities and NoNewPrivileges=yes, a read-only filesystem except /var/lib/holywisp, only AF_INET and AF_INET6 sockets, the @system-service system calls less the privileged groups, and MemoryMax=1G, TasksMax=512. systemd-analyze security rates it about 1.3, "OK". The systemd unit and its sandbox on Install and run lists every directive and how to add a capability with a drop-in.

Do not loosen it to make Twisp more useful or to work around a bug. A port under 1024 needs CAP_NET_BIND_SERVICE and udp-warp-marks needs CAP_NET_ADMIN, each added alone; without CAP_NET_ADMIN the server starts and logs that its UDP goes out unmarked (Proxies-and-WARP).

Watching it

GET /stats (Stats-and-monitoring) counts every refusal on this page:

Field Counts
refused.connectionRate upgrades over connections-limit-per-ip
refused.connectionLimit upgrades over the per-address or total connection caps, and accepts over max-handshakes-per-ip
refused.reputation upgrades refused for a STRICT score
blocked.filter, blocked.egress streams refused by the host and port filters, and by the egress policy (direct IP included)
throttled.source CONNECTs over the per-source rate or the stream cap
throttled.dest, throttled.syns, throttled.lookups the per-destination windows, the SYN caps, the lookup cap
queueBudget.pauses connections paused by server-queue-max or its per-address share
synSignatures, wsClosedViolations, authFailures signature matches, connections closed for violations, failed logins
reputation.sources, reputation.destinations entries in the reputation table

A relay behind a proxy that shows every client as the proxy's address is the most common cause of a whole site being rate-limited at once: check trusted-proxy. Troubleshooting goes from a 403, a 429 or a close code to its cause.

Clone this wiki locally