Harden daemon TCP transport: require loopback Host + reject cross-origin (CSRF/DNS-rebinding)#145
Merged
BunsDev merged 2 commits intoMay 30, 2026
Conversation
…P transport (CSRF/DNS-rebinding) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
is_loopback_host accepted any authority starting with "127.", so a hostname like 127.evil.com passed the Host/Origin guard and defeated its DNS-rebinding defense. Parse the host as an IpAddr and ask is_loopback(); keep the localhost literal.
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.
Summary
coven daemon serve --tcp <addr>serves the full unauthenticated/api/v1over loopback HTTP.bind_tcp_listeneralready refuses non-loopback binds, but the request handler did not checkHostorOrigin— so a web page the user visits could drive the daemon via a cross-origin "simple" request (CSRF), and DNS-rebinding (a foreignHostrebound to 127.0.0.1) could reach it. This adds a loopback guard to the TCP transport only; the Unix socket path is filesystem-gated and unchanged.Why
docs/AUTH.mdstates the API must not be exposed "on localhost TCP ... or a browser page" without "an explicit additional auth and pairing design," and notes there is "no CSRF/origin policy." The--tcpfeature (documented for "cockpit via Vite proxy") ships exactly that browser-reachable surface. This guard is the minimal origin/pairing design for it.Changes (
crates/coven-cli/src/daemon.rs)read_http_headersnow also capturesHostandOrigin.handle_http_streamgains anenforce_loopback_guardflag. On the TCP path it:Hostis not a loopback authority (127.x/localhost/::1) →403(defeats DNS-rebinding);Origin→403(defeats browser CSRF; a CLI/Vite-proxy client sends no cross-originOrigin).false(unaffected). Addswrite_forbidden(403) plus smallhost_is_loopback/origin_is_loopback/strip_port/is_loopback_hosthelpers.No new dependencies, no
unsafe, Unix-gated.Verification
cargo fmt,cargo clippy --workspace --all-targets -- -D warnings(clean), andcargo test --workspace --lockedall green on Linux: 697 pass, 0 fail. Four new tests cover the cross-origin block, the foreign-Host block, the loopback-origin allow, and the Unix path ignoringOrigin.Tracked by #143.
Note: PRs are frozen until July per CONTRIBUTING — opening this for visibility since it is a small, isolated security fix for the documented TCP/browser gap. Completely fine to close or hold until the window reopens; the branch will keep.