Skip to content

feat: pair receivers with a code from the Mac and seal the signaling - #21

Merged
th3r-dev merged 3 commits into
devfrom
feat/pairing
Nov 11, 2026
Merged

th3r-dev merged 3 commits into
devfrom
feat/pairing

Conversation

@th3r-dev

Copy link
Copy Markdown
Owner

Fixes the three high findings from the security audit (run 1). Today any device on the network can:

  • stream the Mac's screen,
  • take over another receiver's extended screen,
  • crash signaling with one crafted offer.

What changes for people

  • First connection: the Mac shows a 6-digit code, and the receiver asks for it. After that, the device connects without a code.
  • Menu bar: Forget Paired Devices… disconnects every device and makes each one pair again.
  • Older receivers: a receiver from before this change can't stream from an updated Mac until it updates too. Older Macs still accept updated receivers, which fall back to the plain offer.

How it works

  • Pairing: SPAKE2 with the code, using the spake2 crate on the host. pair.js matches it byte for byte, and a Rust test checks that against vectors from pair.js.
    • The code never goes over the network.
    • Three wrong codes end the attempt, and a code expires after 2 minutes.
    • The Mac also proves it knew the code, so a receiver can't be paired to an impostor.
  • What a device gets: its own device ID and a 32-byte secret, sealed with the SPAKE2 key. The Mac stores them in paired.json with mode 0600.
  • Each connection:
    • The host issues a one-time challenge.
    • The offer is sealed with ChaCha20-Poly1305, using keys derived from the secret and the challenge.
    • The answer comes back sealed the same way.
    • Plain, replayed or tampered offers get 401.
    • The DTLS fingerprints travel inside the sealed SDP, so the video's existing encryption is bound to the paired ends.
  • Layout map: /devices, /screens and /screens/layout need a request signed with the device secret, or must come from the Mac itself (loopback, with no foreign Origin).
  • Browser crypto: the page has no crypto.subtle over plain HTTP. The primitives come from @noble/* 2.4.0, vendored from a lockfile by tools/vendor-crypto/build.sh.
  • Crash fix: str0m offer handling runs under catch_unwind, and the session lock recovers from poisoning. The offer that crashed it is now a regression test.

Testing

  • Automated: cargo test passes (68 tests).
    • An HTTP test runs the whole flow: pair, sealed offer, replay refused, signed /screens.
    • Interop vectors cover SPAKE2, the sealed offer and the request signature.
  • Chrome against a dev host on port 47200:
    • a wrong code shows "2 tries left";
    • the right code pairs and streams;
    • a reconnect needs no code;
    • Cancel returns to the start screen;
    • unsigned /screens and plain offers are refused.
  • Not yet checked by hand:
    • the Mac app's code dialog: the dev run printed the code to the terminal;
    • the Windows and Android apps: the scripts load the same way as on the Mac, and a check confirmed the bundle works when evaluated inside a function.

Not in this PR

The audit's other findings come in a follow-up PR:

  • session cap and connect deadline;
  • listener supervision and file-descriptor limits;
  • /nearby running one sweep at a time, plus the hello deadline;
  • log caps;
  • the display leak;
  • the virtual-display nil crash.

Before this, any device on the network could stream the Mac's screen,
take over another receiver's extended screen with its published device id,
or move the Mac's monitors (security audit, run 1). Now a receiver must be
let in by the owner, and everything it says to the host is protected.

Pairing (crates/host/src/pairing.rs, crates/app/assets/pair.js):
- The first connection asks the Mac to pair. The Mac shows a 6-digit code
  (a dialog in the app, the terminal otherwise) and the receiver asks for
  it. Both sides run SPAKE2 (the spake2 crate; pair.js matches it byte for
  byte), so the code never crosses the network and a listener has nothing
  to guess against. Three wrong codes end the attempt; a code lasts 2 min.
- The host then gives the receiver its own device id and a 32-byte secret,
  sealed with the SPAKE2 key, after proving it knew the code as well. The
  Mac keeps them in ~/Library/Application Support/Mullion/paired.json (0600).
- Every connection: a one-time challenge, then the offer sealed with keys
  from the secret and the challenge (ChaCha20-Poly1305), and the answer
  sealed back. Unpaired offers, replays and tampering are refused. The SDP
  carries the DTLS fingerprints, so the video's own encryption is now bound
  to the paired ends.
- /devices, /screens and /screens/layout take a request signed with the
  secret (X-Mullion-Auth), or come from this Mac itself (loopback without a
  foreign Origin), so the menu's Arrange Screens still works.
- Menu: Forget Paired Devices… ends every session and makes each device pair
  again.
- The page has no crypto.subtle over plain http, so the primitives come from
  @noble/curves, hashes and ciphers 2.4.0, vendored by
  tools/vendor-crypto/build.sh from a lockfile (vendor/noble.js, 50 KB).

Also from the audit:
- A crafted offer made str0m panic while the shared session lock was held,
  which poisoned it and took signaling and the menu down until restart.
  The offer is now built under catch_unwind and the lock recovers from
  poisoning; the crashing offer is a regression test.
- The Host header reaches the receiver page only as address characters.

Checked: 68 tests pass, including a Rust test with vectors from pair.js for
SPAKE2, the sealed offer and the request signature, and an HTTP test of the
whole flow. In Chrome against a dev host: wrong code (2 tries left), right
code, streaming; reconnect without a code; unsigned /screens and plain
offers refused.
@th3r-dev

Copy link
Copy Markdown
Owner Author

Evidence

I captured this on 2026-11-12 against a dev host built from this branch, with the receiver page open in Chrome on the same Mac. The files are in docs/evidence/pairing/.

For privacy, the Mac's host name is shown as [Mac name]. The stream itself isn't shown because it's this Mac's desktop; its numbers are below.

1. First connection: the page asks for the code the Mac shows

Code prompt: 'Code shown on [Mac name]' with a 6-digit field, Pair and Cancel

2. A wrong code uses up one of three tries

Message: That code is not the one on the Mac. 2 tries left.

3. Host log (host-log.txt)

pairing requested by Mac
Pairing code for Mac: 263 091
pairing Mac: wrong code (2 attempts left)
paired Mac
offer from 10.43.77.126:62817 answered (Mirror)
#1 ice: Checking
#1 ice: Completed
pipeline started for Main: 1920x1080 @ 60 fps, 10000 kbps
offer from 10.43.77.126:62817 answered (Mirror)      <- reconnect, no code asked
#2 ice: Completed
pipeline started for Main: 1920x1080 @ 60 fps, 10000 kbps

4. Checks from the page (browser-checks.json)

Check Result
Stream after pairing streaming, 1920x1080, 333 frames
Reconnect streaming, no code asked
Signed GET /screens 200
Unsigned GET /screens from the LAN 401
Unsigned GET /devices from the LAN 401
Plain, unsealed POST /offer 401: "Pair this device with the Mac first."

5. Tests (cargo-test.txt)

68 tests pass, including:

  • js_and_rust_agree: pair.js and the Rust spake2 crate derive the same key, confirmation, sealed offer and request signature (vectors);
  • paired_host_takes_only_sealed_offers_and_signed_layout_requests: the whole flow over HTTP, with a replayed offer refused;
  • str0m_panic_on_an_offer_is_contained: the audit's crashing offer now comes back as an error;
  • store_survives_a_restart_and_is_private: paired.json is 0600 (checked here too).

6. CI on this PR: macOS, Windows and Android builds all pass.

Not shown: the Mac app's code dialog (the dev host printed the code to the terminal), and the Windows and Android apps by hand. The beta built from this merge will cover those.

@th3r-dev

Copy link
Copy Markdown
Owner Author

Evidence: where the code comes from

The code is shown on the Mac the device connects to. To capture it, I built Mullion.app from this branch, signed it like the releases, and ran it as the menu bar app on port 47201, next to the installed one. The device was the receiver page in Chrome, named "iPad test". Files: docs/evidence/pairing/.

1. The device asks to pair, and the Mac shows the code

Mac dialog: 'iPad test wants to show this Mac. Enter this code on iPad test: 835 050. The code works for 2 minutes. If you are not connecting iPad test, click Don't Allow.' Buttons: Don't Allow, OK

2. The person types that code on the device

Receiver page with 835050 typed in the code field, and a Pair button

3. Paired and streaming, and the dialog closed by itself (mac-app-log.txt)

pairing requested by iPad test
paired iPad test
offer from 10.43.77.126:52550 answered (Mirror)
#1 ice: Completed
pipeline started for Main: 1920x1080 @ 60 fps, 10000 kbps

The page showed streaming, 1920x1080, 417 frames. Four seconds after the code was accepted, the app had no dialog on screen. That checks the automatic close, which the first comment couldn't show.

The Mac's host name is replaced with [Mac name], and the stream isn't shown because it's this Mac's desktop. Afterwards I quit the test app and removed its test pairing.

@sonarqubecloud

Copy link
Copy Markdown

❌ The last analysis has failed.

See analysis details on SonarQube Cloud

@th3r-dev
th3r-dev merged commit 6d9e89b into dev Nov 11, 2026
5 of 6 checks passed
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.

1 participant