Skip to content

term_ws Origin check: default closed + drop spoofable X-Forwarded-Host#8

Merged
falkoro merged 1 commit into
masterfrom
fix/term-origin-default-closed
May 30, 2026
Merged

term_ws Origin check: default closed + drop spoofable X-Forwarded-Host#8
falkoro merged 1 commit into
masterfrom
fix/term-origin-default-closed

Conversation

@falkoro
Copy link
Copy Markdown
Owner

@falkoro falkoro commented May 30, 2026

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

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>
Copilot AI review requested due to automatic review settings May 30, 2026 15:44
@falkoro falkoro merged commit 58a137a into master May 30, 2026
@falkoro falkoro deleted the fix/term-origin-default-closed branch May 30, 2026 15:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_origin no longer fails open when the Host is loopback and no allowlist is configured; any mismatched browser Origin is now refused.
  • X-Forwarded-Host is no longer consulted; only Host and DASHBOARD_ALLOWED_ORIGINS are trusted.
  • .env.example documentation updated to describe the new default-closed semantics and explicitly note that X-Forwarded-Host is 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants