term_ws Origin check: default closed + drop spoofable X-Forwarded-Host#8
Merged
Merged
Conversation
Security review of the previous fix flagged two issues, both addressed: - Fail-open was unsafe on a shell-granting socket: when the public origin was "undeterminable" (loopback Host + empty allowlist) the check allowed any Origin, i.e. cross-site WebSocket hijacking. Now DEFAULT CLOSED — a present browser Origin matching neither the Host nor DASHBOARD_ALLOWED_ORIGINS is refused. Deployments behind a Host-rewriting proxy MUST set DASHBOARD_ALLOWED_ORIGINS (the live deploy already does, via the systemd drop-in). - Removed X-Forwarded-Host trust (a client can spoof it where the proxy doesn't strip it). Rely on Host match + the explicit allowlist only. Verified: same-origin -> 101; allowlisted Origin behind rewritten Host -> 101; cross-origin -> 403; X-Forwarded-Host spoof -> 403; missing Origin (native client) -> 101; unconfigured rewritten-Host + real Origin -> 403. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Tightens the /api/term WebSocket Origin guard to default-closed and removes trust in the client-spoofable X-Forwarded-Host header, in response to the security review of #7.
Changes:
blocked_originno longer fails open when the Host is loopback and no allowlist is configured; any mismatched browser Origin is now refused.X-Forwarded-Hostis no longer consulted; onlyHostandDASHBOARD_ALLOWED_ORIGINSare trusted..env.exampledocumentation updated to describe the new default-closed semantics and explicitly note thatX-Forwarded-Hostis not trusted.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/term.rs | Removed XFH/loopback fail-open branch and is_loopback_host helper; simplified blocked_origin to same-Host or allowlist only, with a more actionable 403 reason. |
| .env.example | Updated DASHBOARD_ALLOWED_ORIGINS docs to reflect default-closed behavior and the dropped XFH trust. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Addresses the automated security review of #7: (1) the fail-open path was unsafe on a shell-granting WebSocket (cross-site WS hijacking when the public origin was undeterminable) — now default closed; (2) removed X-Forwarded-Host trust (client-spoofable). Deployments behind a Host-rewriting proxy must set
DASHBOARD_ALLOWED_ORIGINS(the live deploy already does). Verified: same-origin→101, allowlisted-behind-rewritten-Host→101, cross-origin→403, XFH-spoof→403, missing-Origin→101.🤖 Generated with Claude Code