Repository navigation
Description
What happens
The server decides that a request comes from "this computer" when the connection is from a loopback address and the request has no X-Forwarded-For header (decideAccess in server/access.ts). "This computer" gets full access with nothing else to show, and keeps it after devices are paired.
A reverse proxy running on the same PC connects from loopback too. If it does not add X-Forwarded-For, every visitor of the proxy counts as this computer. nginx's proxy_pass adds no such header by default (it also replaces Host with the upstream address). Caddy's reverse_proxy adds it by default.
Who is affected
Only this combination:
- a reverse proxy on the same PC as herdr web ui, reachable by other people (a LAN or a public domain),
- that sends no
X-Forwarded-For, - and no token set (
HERDR_WEB_TOKEN).
In that setup, pairing a device does not close the server to strangers, although the guide says it does. Anyone who reaches the proxy can read the session and pane text and, without a browser (no Origin header), type into panes and create workspaces.
Not affected: the default install on 127.0.0.1, tailscale serve (it sends X-Forwarded-For), Caddy with default settings, an SSH tunnel, and any setup with a token.
A token protects in every case measured: with HERDR_WEB_TOKEN set, every request without it is refused, through every proxy configuration.
Reproduce
Measured on main at 261b88d with nginx 1.31.6 (docker, host network) in front of createServer({ port: 0, hostname: "127.0.0.1", token, stateDir }). Requests go to the proxy as app.example.test, with no cookie and no token unless the row says so.
# A: nginx default
location / { proxy_pass http://127.0.0.1:7317; }
# B: A plus the usual WebSocket lines
# proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade;
# C: B plus proxy_set_header Host $http_host;
# D: C plus proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; (TLS listener)Quick check with one device paired and no token:
curl -s -o /dev/null -w '%{http_code}\n' http://<proxy>/api/session # 200 through A, B, C; 401 through D
curl -s http://<proxy>/api/health # "via":"local" through A, B, C"+Origin" columns send Origin and Sec-Fetch-Site: same-origin as a browser on the proxy's address would. "WS + input" opens /ws, attaches a pane and sends an input frame; "input typed" means the text showed up in the pane.
| state | via | GET session | GET pane/read | POST pane/input | POST pane/input +Origin | POST workspace/create | POST workspace/create +Origin | POST devices/pair (wrong code) | WS + input | WS + input +Origin |
|---|---|---|---|---|---|---|---|---|---|---|
| no token, nothing paired | direct to 127.0.0.1, no proxy | 200 | 200 | 200 | 200 | 200 | 200 | 401 invalid_code | 101, input typed | 101, input typed |
| no token, nothing paired | A: bare proxy_pass |
200 | 200 | 200 | 403 invalid_origin | 200 | 403 invalid_origin | 401 invalid_code | 426 | 403 |
| no token, nothing paired | B: A + WebSocket upgrade | 200 | 200 | 200 | 403 invalid_origin | 200 | 403 invalid_origin | 401 invalid_code | 101, input typed | 403 |
| no token, nothing paired | C: B + browser's Host |
200 | 200 | 200 | 200 | 200 | 200 | 401 invalid_code | 101, input typed | 101, input typed |
| no token, nothing paired | D: C + X-Forwarded-For, X-Forwarded-Proto, TLS |
200 | 200 | 200 | 200 | 200 | 200 | 401 invalid_code | 101, input typed | 101, input typed |
| no token, one device paired | direct to 127.0.0.1, no proxy | 200 | 200 | 200 | 200 | 200 | 200 | 401 invalid_code | 101, input typed | 101, input typed |
| no token, one device paired | A: bare proxy_pass |
200 | 200 | 200 | 403 invalid_origin | 200 | 403 invalid_origin | 401 invalid_code | 426 | 403 |
| no token, one device paired | B: A + WebSocket upgrade | 200 | 200 | 200 | 403 invalid_origin | 200 | 403 invalid_origin | 401 invalid_code | 101, input typed | 403 |
| no token, one device paired | C: B + browser's Host |
200 | 200 | 200 | 200 | 200 | 200 | 401 invalid_code | 101, input typed | 101, input typed |
| no token, one device paired | D: C + X-Forwarded-For, X-Forwarded-Proto, TLS |
401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 invalid_code | 401 | 401 |
| token set | direct to 127.0.0.1, no proxy | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 invalid_code | 401 | 401 |
| token set | A: bare proxy_pass |
401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 invalid_code | 401 | 401 |
| token set | B: A + WebSocket upgrade | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 invalid_code | 401 | 401 |
| token set | C: B + browser's Host |
401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 invalid_code | 401 | 401 |
| token set | D: C + X-Forwarded-For, X-Forwarded-Proto, TLS |
401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 invalid_code | 401 | 401 |
| no token, nothing paired, Tailscale login known | direct to 127.0.0.1, no proxy | 200 | 200 | 200 | 200 | 200 | 200 | 401 invalid_code | 101, input typed | 101, input typed |
| no token, nothing paired, Tailscale login known | A: bare proxy_pass |
200 | 200 | 200 | 403 invalid_origin | 200 | 403 invalid_origin | 401 invalid_code | 426 | 403 |
| no token, nothing paired, Tailscale login known | B: A + WebSocket upgrade | 200 | 200 | 200 | 403 invalid_origin | 200 | 403 invalid_origin | 401 invalid_code | 101, input typed | 403 |
| no token, nothing paired, Tailscale login known | C: B + browser's Host |
200 | 200 | 200 | 200 | 200 | 200 | 401 invalid_code | 101, input typed | 101, input typed |
| no token, nothing paired, Tailscale login known | D: C + X-Forwarded-For, X-Forwarded-Proto, TLS |
401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 unauthorized | 401 invalid_code | 401 | 401 |
| token set | A: bare proxy_pass, with the token |
200 | 200 | 200 | 403 invalid_origin | 200 | 403 invalid_origin | 401 invalid_code | 426 | 403 |
| token set | B: A + WebSocket upgrade, with the token | 200 | 200 | 200 | 403 invalid_origin | 200 | 403 invalid_origin | 401 invalid_code | 101, input typed | 403 |
| token set | C: B + browser's Host, with the token |
200 | 200 | 200 | 200 | 200 | 200 | 401 invalid_code | 101, input typed | 101, input typed |
| token set | D: C + X-Forwarded-For, X-Forwarded-Proto, TLS, with the token |
200 | 200 | 200 | 200 | 200 | 200 | 401 invalid_code | 101, input typed | 101, input typed |
Reading the table:
- Rows "one device paired" through A, B and C are the problem: 200 where D answers 401.
- Through A and B a browser cannot use the app anyway (
invalid_origin, becauseHostis the upstream address), so someone setting nginx up will addHost. That gives C, which works completely and is open. - "Tailscale login known" behaves the same: D asks for pairing, A to C do not.
- "nothing paired" with no token is open by design through any proxy, and the server warns about it at startup when bound off loopback. Behind a proxy it is bound to loopback, so no warning is printed.
POST /api/devices/pairis open by design and answeredinvalid_codeeverywhere.
What can be fixed
The server cannot tell configuration A or B from a local client: the request looks the same. It can tell C, because the Host is not a loopback name. So:
- treat a loopback request whose
Hostis not a loopback name, or that carries another proxy header, as proxied; - give the guide exact Caddy and nginx examples and say plainly that a proxy without
X-Forwarded-Forneeds a token.
Activity