Skip to content

docs: add the web screens protocol spec - #3537

Open
vpetersson-bot wants to merge 10 commits into
masterfrom
docs/web-screens-protocol
Open

vpetersson-bot wants to merge 10 commits into
masterfrom
docs/web-screens-protocol

Conversation

@vpetersson-bot

@vpetersson-bot vpetersson-bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What this adds

docs/web-screens-protocol.md, a draft v1 protocol spec for web screens. A web screen is a TV or kiosk that only opens https://web.anthias.io:

  • it shows a pairing code;
  • the operator types that code into an Anthias controller and confirms a verification code;
  • from then on the controller manages it over a direct WebRTC data channel on the LAN.

This PR is documentation only. No code changes.

Why a spec first

Three components will be built against it in parallel:

  • a small rendezvous and signalling relay;
  • the controller side, which includes a new anthias-webrtc process;
  • the browser client.

All three need the same wire formats, state machines, signing rules and test vectors first.

What it covers

  • Ground rules:
    • the relay carries only pairing and signalling, never manifests, commands, health or media, with no fallback that does;
    • no TURN and no external STUN server;
    • the TV never makes an HTTP connection to the controller.
  • The supported browser and OS matrix, and the risk that Chrome brings WebRTC under Local Network Access permission checks. The managed-policy fallback is marked as a pending product decision.
  • Pairing:
    • Magic Wormhole style: the TV shows a 12-symbol code. A 4-symbol lookup goes to the relay; an 8-symbol secret never leaves the screen.
    • The controller and TV run SPAKE2 (python-spake2 0.9 on the controller, the RustCrypto spake2 0.4 crate as WASM on the TV), bound to both identity keys, with key confirmation.
    • The TV allows one attempt per code, and the online guessing bound is written out.
  • The relay:
    • REST (time, pair, claim, statement, fresh-consent restore, unpair, list) and a WebSocket with challenge-response authentication;
    • its notices are advisory only;
    • an end-to-end signed envelope with a session and negotiation state machine. Every offer echoes a fresh challenge from the TV.
  • Unpairing: only a revocation signed by the pinned peer unpairs. /reset is non-destructive when loaded, refuses to run in a frame, and needs a controller token or the TV's id prefix. Replace screen covers a TV that has lost its storage.
  • The WebRTC session: pre-negotiated channels on both peers, message-size limits, and DTLS certificates per session, authenticated by the signed SDP.
  • Data-channel messages: the signed manifest, applied all at once; acks, commands, health and heartbeat.
  • Media:
    • addressed by SHA-256, and authorised per TV;
    • an in-band end-of-file frame;
    • a download completes only once the whole range is flushed and hashed;
    • a fair queue on the controller.
  • The anthias-webrtc process: what it owns, its internal API, a durable event outbox, and how it works with bridge networking (a published UDP range, and host candidates rewritten from the host agent's ip_addresses).
  • Supporting sections: failure behaviour and statuses, limits and timers, a threat model, reference deployments (the relay on Cloudflare Workers and Durable Objects, the client on Cloudflare Pages with its CSP and frame-ancestors served as response headers), release gates, and test vectors.

How it was checked

  • Test vectors: generated with Python cryptography from fixed private scalars, and every signature was verified after generation.
    • The signatures use deterministic ECDSA (RFC 6979), so other implementations can check them byte for byte.
    • Browser tests verify them rather than reproduce them, because WebCrypto signs with a random nonce.
  • Flow-control values and the bridge-networking setup: both come from spikes.
    • Setup: Chrome 158 in kiosk mode on a public HTTPS origin, with aiortc on the same LAN, both on the host and in a container on Docker's default bridge network with UDP 40000–40049 published.
    • Results: 512 MB transferred with no losses, at about 35–41 MB/s.
    • A plain fetch() to the LAN address was held by a Local Network Access prompt; the WebRTC data channel was not.
    • Without rewriting the candidates, the bridged setup doesn't connect. The spec records the small aioice override this needs.
  • Not covered by the spikes: ChromeOS, Windows, a Pi under load, and capacity at full load. These are listed as release gates in the spec.

🤖 Generated with Claude Code

Web screens are TVs that only open tv.anthias.io, pair by showing a
code that the operator types into a controller, and are then managed
over a direct WebRTC data channel on the LAN. This spec is what the
relay, the controller and the web client get built against: the relay
REST and WebSocket API, the signed signalling envelope, the check code,
the data-channel messages and media transfer, and the boundary of the
new anthias-webrtc process. It includes test vectors.

No code changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
@vpetersson-bot
vpetersson-bot requested a review from a team as a code owner November 30, 2026 17:03
Copilot AI lite review requested due to automatic review settings November 30, 2026 17:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

aiortc was run in a container on Docker's default bridge network, with
UDP 40000-40049 published and the host candidates rewritten to the
host's LAN address. Kiosk Chrome on a public origin connected with no
Local Network Access prompt, at 35-39 MB/s against 38-41 MB/s for
aiortc running on the host. Without the change to the candidates it
did not connect at all.

The spec now records that aioice needs a small override for both the
port range and the advertised address, that ports are freed when a
session closes (so 50 is a cap on concurrent sessions), that candidates
are IPv4 only in v1, and that aiortc must be given an empty ICE server
list explicitly, because its default uses a public STUN server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
Copilot AI lite review requested due to automatic review settings November 30, 2026 17:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

An independent review found that the trust lifecycle and several
recovery rules weren't tight enough to build against. This revision:

- gates pairing on operator verification: a commitment-based SAS with
  fresh randomness on both sides, typed by the operator, and nothing
  released until both sides are verified;
- makes relay notices advisory, so only a revocation signed by the
  pinned peer can unpair, and adds a co-signed binding statement that
  restores bindings after relay data loss;
- documents the supported browser matrix and the risk of Chrome
  bringing WebRTC under Local Network Access;
- makes /reset non-destructive on load, refuses it in a frame, and
  requires a controller token or a tv_id prefix;
- treats DTLS certificates as per-session, authenticated by the signed
  SDP, so they can rotate freely;
- addresses media by SHA-256, ends files with an in-band end frame,
  and finishes a download only once the full range is flushed and
  hashed;
- lengthens pairing codes to 10 symbols, adds global abuse limits,
  replaces timestamp windows with wake challenges, and adds a durable
  event outbox, per-TV media authorisation and message-size limits;
- records failure behaviour, a threat model, release gates, and a
  reference deployment of the relay in Rust on Fly.io.

Test vectors are regenerated for every changed derivation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
Copilot AI lite review requested due to automatic review settings November 30, 2026 17:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

@vpetersson-bot
vpetersson-bot requested a lite review from Copilot November 30, 2026 17:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

The verification code in the previous revision could be computed by
whoever claimed the TV, so typing it proved nothing to the TV. Pairing
now follows the Magic Wormhole pattern instead. The TV shows a 12-symbol
code: a 4-symbol lookup that goes to the relay, and an 8-symbol secret
that never leaves the screen. The controller and TV run SPAKE2 with the
secret as the password, bound to both identity keys and the pairing id,
and finish with key confirmation, controller first. The TV allows one
attempt per code. python-spake2 0.9 and the RustCrypto spake2 0.4 crate
were checked to interoperate before naming them.

Also:
- the relay no longer stores or delivers revocations, and orphaned
  bindings expire;
- restoring a binding needs fresh signed consent from both peers over a
  relay challenge, never an old statement alone, and never overwrites a
  different current binding;
- envelopes carry a negotiation number, with explicit rules for the
  initial offer and for ICE restarts;
- split ctl messages are sized by encoded bytes, with limits on open
  assemblies, their total size and their lifetime;
- section 12 states the online guessing bound under a global claim cap.

Test vectors are updated for the new code format, key confirmation,
envelopes and restore consent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
Copilot AI lite review requested due to automatic review settings November 30, 2026 17:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

The guessing bound in section 12 relied on the relay enforcing its own
global claim cap, and on a 10-minute code lifetime that doesn't limit
attempts once a failure burns the code and issues a new one.

Each TV now keeps a persistent count of failed PAKE runs. After the
k-th consecutive failure it waits min(5 s * 2^k, 15 min) before asking
for a new code, and it accepts at most 48 failed runs in any rolling
24 hours before pausing pairing. A success or a local reset clears the
count. Section 12 now states the per-TV bound, 48 * 2^-40 per day,
which holds even against a malicious relay, and labels the fleet-wide
estimate as assuming an honest relay. Gate G6 tests the counter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
Copilot AI lite review requested due to automatic review settings November 30, 2026 17:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

tv.anthias.io is deployed with the existing Pages workflow in the
Anthias-Web repo, and GitHub Pages can't send response headers. The
spec stops relying on them:

- framing is refused by the app itself (it does nothing when
  window.top isn't window.self), since frame-ancestors only works as a
  header; /reset still needs a token or the typed tv_id prefix;
- the CSP becomes a meta element, listed in full, with
  'wasm-unsafe-eval' for the SPAKE2 WebAssembly, and with what a meta
  CSP can't enforce spelled out;
- without COOP/COEP there is no SharedArrayBuffer, which nothing in the
  protocol needs, and dependencies that need it are ruled out;
- client routes rely on the existing 404.html copy and the service
  worker, with reset parameters kept in the fragment;
- deploy access in the threat model becomes the GitHub repo and org:
  branch protection, a protected github-pages environment, who can
  change the custom domain, and verifying anthias.io in the org.

Section 14 now covers both reference deployments, and gate G6 tests
the CSP and the framing check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
Copilot AI lite review requested due to automatic review settings November 30, 2026 17:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

The reference relay moves from Rust on Fly.io to TypeScript on
Cloudflare Workers with Durable Objects, in the account that holds the
anthias.io DNS.

- Section 14.1 describes the objects: one per controller, holding the
  controller's socket and its TVs' sockets; one per unpaired TV, since
  an object holds at most 32,768 hibernated sockets; and a registry for
  lookups, the global caps and failed-claim limits. All of them use the
  WebSocket Hibernation API and SQLite storage.
- Deploys use deferred code updates, so hibernated sockets stay
  connected and there is no fleet-wide socket drop.
- Losing relay storage is now described as unlikely; restore by fresh
  consent still applies.
- Ping and pong are byte-exact so the relay can answer them without
  waking an object.
- Sockets carry their own id as an untrusted routing hint, and close
  code 4302 asks a client to reconnect at once after routing changes,
  for example right after a claim.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
Copilot AI lite review requested due to automatic review settings November 30, 2026 17:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

The socket routing hint is untrusted, so anyone who knows a
controller_id could open sockets into that controller's Durable
Object. The Worker now rate-limits unauthenticated connections per IP
before routing, each object allows at most 64 sockets waiting to
authenticate (close 4503) with a 10 s deadline (close 4408), and
waiting sockets are kept out of the object's state so it can still
hibernate. Gate G6 tests a flood against a controller's bound TVs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
Copilot AI lite review requested due to automatic review settings November 30, 2026 17:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

The managed client is served from web.anthias.io rather than
tv.anthias.io. No signed test vector or label includes the origin, so
none change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
Copilot AI lite review requested due to automatic review settings November 30, 2026 19:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

web.anthias.io now deploys only through deploy-cloudflare.yml, so
response headers are available again. The CSP is served from the
_headers file, with frame-ancestors 'none' as the primary guard against
framing; the meta copy stays as a fallback and the window.top check
stays as defence in depth. connect-src now names the Google Analytics
and Sentry endpoints the client already uses. Routing uses the
_redirects rewrite instead of the 404.html copy. The threat model's
deploy access becomes the Cloudflare account and the repo's deploy
token, the GitHub domain-verification note is gone, and gate G6 checks
the headers on the deployed response.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
Copilot AI lite review requested due to automatic review settings November 30, 2026 21:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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