Skip to content

feat(runtime): session-only browser keys and opt-in for pairing from plain-http pages (host) - #27540

Merged
OrcaWin merged 2 commits into
mainfrom
np/d2b-web-session-host
Oct 11, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
np/d2b-web-session-host

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​559 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​559
Prod 17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​297 $\color{#cf222e}{\Huge{\mathbf{−}}}$​52 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​245

ELI5

A browser can pair with an Orca server from a plain http:// page on another machine, for example http://192.168.1.20:6768. Anyone on that network path can swap that page for a fake one and steal the pairing code typed into it. This PR makes the server:

  • refuse new pairings from such pages unless the operator opts in;
  • support a "this browser session only" sign-in: the browser keeps a key in memory, and the server forgets it when the server restarts or the tab has been gone for 12 hours.

Browsers that are already paired keep working exactly as before.

What Changed

This is the host (server) half. The browser half is the next PR in the stack.

  • New optional sign-in flag ephemeral: true on pairing.registerDeviceKey. It is advertised as the new capability pairing.device-key-ephemeral.v1.
    • The keyed device row created this way is marked ephemeral.
    • The host drops ephemeral rows when it starts, because the browser's in-memory key died with the old session. The write is durable.
    • A sweep every 5 minutes removes ephemeral rows that have no live socket and have been idle for more than 12 hours. Idle time counts from the last connect or disconnect. The sweep also cuts any socket still bound to a removed row.
    • After that, key sign-in for the row gets the existing sealed device_revoked verdict, so the browser drops its key.
  • Plain-http page check: web client only, never phones.
    • React Native phones send an http://<host>:<port> Origin on every LAN WebSocket, so the Origin alone cannot identify a browser. The updated web client marks every WebSocket it opens with ?orca-client=web. The host records the marker and that socket's Origin.
    • Only a marked socket from an http:// page on a non-loopback host, claiming a pairing code for the first time (a never-used pending code), is refused. The refusal is a sealed e2ee_error {code:'insecure_origin'} plus a close with 4001 "Insecure web origin", which does not trigger the "unpaired device" prompt.
    • The operator opts in by starting the desktop app or orca serve with ORCA_ALLOW_INSECURE_WEB_PAIRING=1.
    • Unchanged:
      • phones over direct LAN (an http Origin with no marker) and over Relay;
      • native clients;
      • already-paired rows;
      • https:// pages;
      • localhost, *.localhost and 127.x pages.
    • Released hosts ignore the query string, so the marked upgrade still connects to them.
  • Refactor: reading the registry file moved into device-registry-file-read.ts, with no behaviour change, to keep device-registry.ts under the size cap.

Why

  • Why gate only first claims: the owner's rule is that existing connections are never cut. An http-LAN browser that is already paired keeps working. Only a new pairing on an exposed page needs the operator's explicit OK.
  • Why a marker plus the Origin: React Native also sends an http Origin, so the Origin alone would refuse first-time QR pairing from released phones. Only the web bundle adds the marker. The host needs both the marker and an insecure Origin. Sec-Fetch headers can't be used instead, because browsers don't send them to plain-http LAN origins.
  • Why an environment variable: it is the smallest opt-in that reaches the desktop app, orca serve, and managed servers over SSH alike. A settings toggle and a serve flag can follow without changing the host check.
  • Why a host-side sweep rather than a browser timer: the host must expire the credential even if the tab simply disappears.
  • Why a new capability: registerDeviceKey params are strict on older hosts, so a browser sends ephemeral only to a host that advertises it.

Linked Issue

Part of #17399.

Visual Proof

N/A: host only; the browser warning and messages are in the stacked web PR.

Testing

  • src/main/runtime/ephemeral-device-rows.test.ts:

    • forks marked ephemeral only when asked;
    • restart drops them, persistently;
    • a token row can't be ephemeral;
    • the idle sweep skips live and recent rows.
  • src/main/runtime/rpc/web-session-pairing.test.ts, through the real socket wiring and v2 crypto:

    • an http-LAN first claim gets sealed insecure_origin, with no auth and the row still pending;
    • opt-in lets it through;
    • an already-paired row from the same page connects;
    • https, loopback and native clients connect;
    • a phone with an http LAN Origin and no marker pairs, for both mobile and runtime scope;
    • a phone over Relay pairs;
    • an ephemeral row survives while its socket is live, is swept once idle, and then key auth gets device_revoked;
    • the sweep cuts bound sockets.
  • src/shared/web-origin-security.test.ts: http, https, loopback and odd origins.

  • Cross-version (tests/e2e/cross-version-wire/cross-version-web-upgrade-marker.unit.test.ts), over real sockets:

    • a released host's WebSocket transport accepts the marked upgrade and receives its frames;
    • this host records the marker only for the marked socket, never for a phone-style socket that sends the same Origin.
  • Cross-version (tests/e2e/cross-version-wire/cross-version-web-session-pairing.unit.test.ts):

    • the released host does not advertise the new capability, so no browser sends it ephemeral;
    • a released registry keeps the ephemeral keyed row (token-less, inert) and keeps token rows working;
    • this host then drops the row on restart.
  • Existing device-key, registry and runtime RPC suites pass. pnpm tc, oxlint and check:code-quality:changed pass.

  • Automated tests added/updated

Agent skill upstream boundary

  • Not applicable.

Notes

  • SSH: a managed server reads the same environment variable. Its pages are normally reached over an SSH tunnel on loopback, which is not gated.
  • Old clients and a new host:
    • Released web clients send no marker, so they are never gated.
    • Released phones are never gated either; the first version of this PR would have refused them.
    • Only the updated web client, on a new pairing from an http-LAN page, needs the opt-in.
  • Windows: a sweep removal and the restart drop are one durable registry write each. Nothing new runs on the auth path.

m4air added 2 commits October 11, 2026 14:02
…om plain-http pages (host)

- pairing.registerDeviceKey accepts ephemeral: true (advertised as
  pairing.device-key-ephemeral.v1). Such keyed rows are dropped when the host
  restarts and after 12 hours with no live socket; a sweep removes them and cuts
  any socket still bound to them, so later key auth gets device_revoked.
- The WebSocket upgrade Origin is recorded per socket. A first pairing (a
  never-used pairing code) from an http:// page on another machine is refused
  with a sealed insecure_origin error unless the operator sets
  ORCA_ALLOW_INSECURE_WEB_PAIRING=1. Already-paired browsers, https and loopback
  pages, and native clients are unchanged.
- Registry file reading moved to device-registry-file-read.ts to keep the
  registry under the size cap.
…er phones

React Native sends an http Origin on every LAN WebSocket, so the Origin alone
refused first-time QR pairing from released phones. The web bundle now marks
its upgrade with ?orca-client=web; only a marked socket from an http page on
another machine is gated. Released hosts ignore the query string.
@OrcaWin
OrcaWin force-pushed the np/d2b-web-session-host branch from b2dff1a to e3e9fb9 Compare October 11, 2026 21:03
@OrcaWin
OrcaWin changed the base branch from np/d2b-connection-handle to main October 11, 2026 21:03
@OrcaWin
OrcaWin marked this pull request as ready for review October 11, 2026 21:40
@OrcaWin
OrcaWin merged commit fee083f into main Oct 11, 2026
60 of 62 checks passed
nwparker added a commit that referenced this pull request Oct 17, 2026
…s again (#29984)

Partially reverts #27540 and the plain-http part of #27552, which broke web
pairing on upgrade for 1.4.227 users who open Orca at a LAN or Tailscale address:

- The host no longer refuses a first pairing from a plain-http page on another
  machine (insecure_origin, ORCA_ALLOW_INSECURE_WEB_PAIRING).
- Such a page keeps its pairing code in local storage and signs in with it, as
  in 1.4.227, so reloads, new tabs and bookmarks stay paired; no notice.
- Session-only browser keys (pairing.device-key-ephemeral.v1, the idle sweep)
  stay for browsers without Ed25519.
- A web client whose credentials are refused shows the host's reason instead
  of an empty workspace and "Session restore failed".
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