Repository navigation
fix(server): treat a loopback request with a foreign Host or a forwarding header as proxied - #252
Merged
Merged
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
…no Host as proxied From an adversarial review of the proxy check: - Host went through a URL parser, so `public.example@localhost` and `localhost/[email protected]` came out as localhost and a visitor was taken for this computer. Host is now matched as a name or bracketed address with an optional port. - A request without Host (HTTP/1.0 through a proxy) was taken for local. - `localhost.` and `[::ffff:127.0.0.1]` are names for this machine too. Guide: both proxy examples drop a visitor's Tailscale-User-Login (run against real nginx and Caddy: passed through without the line, gone with it), and the check to run is a 401 on /api/session, since /api/health shows no `via` once a token is set.
…warded-for # Conflicts: # CHANGELOG.md
…warded-for # Conflicts: # CHANGELOG.md
devswha
added a commit
that referenced
this pull request
Oct 1, 2026
Release v0.3.40: moves the Unreleased notes under 0.3.40 and bumps `package.json` and `herdr-plugin.toml`. What's in it: - Fixes from #249, #251, #252, #263, #264, #265, #267. - The iPhone CJK and text-symbol fix (#272). - Emoji cell widths matching herdr (#273). Every changelog entry already ends with its PR link. All these PRs are by @devswha, so no credits to add. No remote bundle change: `REMOTE_BUNDLE_VERSION` stays 9. The Windows PC part of #264 and #265 reaches a PC with the next remote bundle, as its changelog entry says.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #250
What was wrong
A loopback request with no
X-Forwarded-Forcounts as this computer and gets full access. A reverse proxy on the same PC that does not send that header made every visitor look local, so with no token set, pairing a device did not close the server. Reproduced with nginx 1.31.6; the issue has the table from before this change.What changes
server/access.ts, one call inserver/index.ts): a loopback request is treated as proxied when it carries any forwarding header (X-Forwarded-For,X-Forwarded-Host,X-Forwarded-Proto,X-Real-IP,Forwarded,Via) or aHostthat is not a name for this machine (localhost,*.localhost,127.x.x.x,[::1]). Claiming to be proxied only removes trust, so a forged header gains nothing. This closes the configuration people end up with once the app works behind nginx (they must keepHost, or the browser getsinvalid_origin). It also stops a page on another hostname that resolves to 127.0.0.1 from being taken for this computer.Host, sendX-Forwarded-ForandX-Forwarded-Proto, and pass the WebSocket upgrade. It says plainly that a proxy sending neither signal makes every visitor count as this computer, so set a token first. The FAQ bullet points there.What is not fixed, and why
proxy_pass(rows A and B below) is still taken for this computer. It rewritesHostto127.0.0.1:7317and adds no header, so the request is byte-for-byte what a local client sends. Only a token closes it; the guide and changelog say so.Reachability after this change
nginx 1.31.6 and Caddy 2.11.4 (docker, host network) in front of
createServer({ port: 0, hostname: "127.0.0.1", token, stateDir }), requests sent to the proxy asapp.example.testwith no cookie or token unless the row says so. "+Origin" sendsOriginandSec-Fetch-Site: same-originlike a browser on the proxy's address. "WS + input" opens/ws, attaches a pane and sends aninputframe.proxy_passHostproxy_passHostproxy_passHostproxy_passHostproxy_pass, with the tokenHost, with the tokenChanged by this PR: the two C rows "one device paired" and "Tailscale login known" went from 200 /
input typedeverywhere to 401. Every other cell is the same as before.D is the guide's nginx example (TLS listener,
$scheme= https) and E is the guide's Caddy example withtls internal; both were run as written apart from ports, certificate paths and host name. The PC list stream (/api/machines/events) was also read through D.Compatibility
http://localhost:7317,http://127.0.0.1:7317,*.localhost: still local (contract test).Host(localhost:5173) and adds no header: still local. Opened from another machine withvite --host, the visitor is no longer taken for this computer.tailscale serve: already sentX-Forwarded-For; unchanged./etc/hosts(sayhttp://mybox:7317→ 127.0.0.1) is no longer local: it is open until a device is paired and needs pairing after.http://localhost:7317always works.Commands
Unverified
Host.