fix: allow ws:// to a loopback Companion from https pages - #723
Merged
Merged
Conversation
Since Eyevinn#707 the Companion WebSocket always uses wss:// on https pages, which breaks the common setup of Companion running on the same machine as the browser, since it serves plain ws://. Browsers treat loopback hosts (localhost, *.localhost, 127.0.0.0/8, [::1]) as potentially trustworthy and allow ws:// to them from https pages, and the traffic never leaves the machine, so use ws:// for loopback hosts and keep wss:// for everything else. The scheme is still chosen from the page protocol and the validated host, never from an incoming ws:// or wss:// prefix. The protocol prefix shown in the connect and save-preset modals now reflects the host being entered. Co-Authored-By: Claude Opus 5.5 <[email protected]>
birme
approved these changes
Oct 5, 2026
birme
left a comment
Contributor
There was a problem hiding this comment.
LGTM — reviewed as part of daily-backlog-pr Phase 3.5 orphan-PR housekeeping (full code-reviewer pass on a clean clone; npm ci/lint/typecheck/test all green, 326 tests).
The security core checks out: the ws:// relaxation is decided only in isLoopbackCompanionHost and is restricted to localhost / *.localhost / 127.0.0.0/8 / [::1] — suffix-confusion hosts (e.g. localhost.evil.com, 127.0.0.1.evil.com) are correctly rejected and covered by tests, and the real connection always flows through buildCompanionWsUrl (fail-safe to wss for anything stricter). No blocking issues.
Non-blocking suggestions for a follow-up (not gating this merge):
src/utils/call-url.ts:76— the127(?:\.\d{1,3}){3}regex doesn't bound octets to 0–255 (harmless, but tightening would match 127.0.0.0/8 exactly).- A one-line comment noting the
*.localhosttrust assumption (matches the browser's own model).
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.
Since #707 the Companion WebSocket always uses wss:// on https pages, which breaks the common setup of Companion running on the same machine as the browser, since it serves plain ws://. Browsers treat loopback hosts (localhost, *.localhost, 127.0.0.0/8, [::1]) as potentially trustworthy and allow ws:// to them from https pages, and the traffic never leaves the machine, so use ws:// for loopback hosts and keep wss:// for everything else.
The scheme is still chosen from the page protocol and the validated host, never from an incoming ws:// or wss:// prefix. The protocol prefix shown in the connect and save-preset modals now reflects the host being entered.