Repository navigation
fix: keep the phone page from hanging on "Connecting to PC" (#259) - #266
Merged
Merged
Conversation
The embedded phone page was hashed with CRLF line endings on Windows checkouts while browsers hash LF, so the CSP blocked the script. Also bound every step of the phone handshake with clear messages, retry and a probe, and log refusal reason codes. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
6 tasks
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.
Refs #259
Root cause (reproduced)
The phone page's only
<script>is allowed by a SHA-256 in the Content-Security-Policy.CompanionPagehashed the embedded HTML as it is stored in the assembly, but browsers hash the script after HTML line-ending normalization (CRLF becomes LF). When the resource has CRLF (Windows checkout withcore.autocrlf, which is how Windows builds get it), the hash never matches, the browser blocks the script ("Refused to execute a script because its hash ... does not appear in the script-src directive") and the page stays forever on its initial "Conectando ao PC…" with no error, exactly the issue's symptom.Reproduced on this Mac by running the real
PhoneLinkServer(throwaway harness, outside the repo) and driving the served page with Playwright WebKit and Chromium: LF resource connects in both; CRLF resource is blocked in both and stays on "Conectando ao PC…". After the fix, CRLF resources connect in both.Other suspects checked and ruled out with the real server: Safari upgrade headers (
permessage-deflate,Connection: Upgrade), Host/Origin exact match, 101 response, single-use key not consumed by the page fetch (the page GET only checks validity), hand-written parser accepts real Safari request headers.Changes
CompanionPage.Composenormalizes line endings to LF before hashing;.gitattributeskeepsCompanion/*LF.GET /<session>/pingprobe (204/410, consumes nothing) separates unreachable from expired. A script that cannot start now shows an on-screen message (also the static default text says the browser could not run the page).PhoneAttemptevents show "Estado" on the QR dialog (page opened / refused / handshake failed + short code);PhoneLinkServertakes a trace callback wired to the localstartup.logwith reason codes only (no keys, session ids, URLs, content). Security design of feat: use a phone for navigation and text input over local P2P #223 unchanged (fragment key, HKDF, counters, single use).PhoneChannelTests.Companion_page_hash_*(CRLF regression),PhoneServerProtocolTests(Safari-style raw requests against the real server, CSP hash vs served script, no secrets in the trace),PhoneJourneyTests(dialog status).Manual evidence (not part of CI; not a real iPhone)
WebKit and Chromium via Playwright against the real server: normal pairing, waiting for permission (countdown and hint at 30 s), open timeout then retry, session gone (unreachable message). Real iPhone/Android checks remain manual and are listed as not hardware-validated in docs/TESTING.md.
🤖 Generated with Claude Code