@johnhenry/wsh 0.44.1 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +382 -39
- package/bin/wsh-mcp.mjs +3 -1
- package/package.json +13 -1
- package/src/cbor.mjs +40 -7
- package/src/client.mjs +79 -20
- package/src/errors.mjs +90 -0
- package/src/host-backends.mjs +23 -0
- package/src/host.d.ts +1 -1
- package/src/index.d.ts +68 -0
- package/src/index.mjs +5 -0
- package/src/key-options.mjs +3 -1
- package/src/mcp-stdio.d.ts +2 -0
- package/src/mcp-stdio.mjs +4 -2
- package/src/memory-host.d.ts +12 -1
- package/src/memory-host.mjs +8 -21
- package/src/messages.gen.mjs +1 -0
- package/src/objects-core.mjs +805 -0
- package/src/objects.d.ts +152 -0
- package/src/objects.mjs +97 -0
- package/src/page-host.d.ts +213 -0
- package/src/page-host.mjs +381 -0
- package/src/pipe-relay-node.mjs +43 -0
- package/src/pipe-relay.d.ts +19 -4
- package/src/pipe-relay.mjs +108 -39
- package/src/reverse-host.d.ts +4 -0
- package/src/reverse-host.mjs +14 -4
- package/src/rpc-virtual.mjs +127 -0
- package/src/rpc.mjs +34 -2
- package/src/server/connection.mjs +70 -10
- package/src/server/index.d.ts +41 -2
- package/src/server/index.mjs +5 -2
- package/src/server/password.mjs +142 -0
- package/src/server/reverse-host.mjs +7 -2
- package/src/server/username.mjs +57 -0
- package/src/session.mjs +2 -1
- package/src/testing.d.ts +50 -0
- package/src/testing.mjs +27 -0
- package/src/webmcp.mjs +694 -0
package/README.md
CHANGED
|
@@ -229,6 +229,14 @@ restricted host with no shell. `fs.root` confines every path: `..`, absolute
|
|
|
229
229
|
paths and symlinks pointing out of it are refused -- for `write` and `rename`
|
|
230
230
|
(both paths) exactly as for `read`.
|
|
231
231
|
|
|
232
|
+
**Login names (`usernamePattern`).** A host admits only names of an OS account's shape, `^[A-Za-z_][A-Za-z0-9_.-]{0,63}$`, because a name reaches
|
|
233
|
+
`exec` environments, file paths and logs. A host that does not map names to accounts (a page, or a mesh peer named by a base64url identity
|
|
234
|
+
hash, which may start with a digit or `-`) says what it admits: `createWshServer({ usernamePattern: /^[A-Za-z0-9_-]{1,64}$/ })`, also on
|
|
235
|
+
`createMemoryHost` and `createConnectionFactory`. Off unless given. **Not loosened by any pattern:** a name is 1 to 256 characters with no control
|
|
236
|
+
character, no `/` or `\`, and is not `.` or `..`, and a pattern that matches the empty name is refused at start. The pattern is the embedder's
|
|
237
|
+
decision: whatever `exec`, `fs` or `authorize` do with the name is theirs to keep safe, and a wider pattern widens what they must handle
|
|
238
|
+
(`createReverseHost` and the Rust `wsh-server` keep the default shape).
|
|
239
|
+
|
|
232
240
|
**Client environment (`clientEnv`).** A client may ask for environment
|
|
233
241
|
variables with `openSession({ env })`. Since 0.36 the host accepts only
|
|
234
242
|
`TERM`, `COLORTERM`, `LANG`, `LANGUAGE` and `LC_*` by default (the shape of
|
|
@@ -481,6 +489,19 @@ unix_connect = ["/var/run/docker.sock", "/run/user/1000/wsh/"] # OpenUnix: exac
|
|
|
481
489
|
unix_listen = ["/run/user/1000/wsh/"] # ListenUnix: sockets a client may ask the host to create
|
|
482
490
|
unix_replace_stale = false # replace a stale socket file only if the request asks AND this is true
|
|
483
491
|
unix_max_listeners = 4 # per client connection
|
|
492
|
+
# TCP reverse tunnels (`enable_reverse_tunnels = true`) and UDP flows: the Node host's bounds and defaults
|
|
493
|
+
reverse_ports = [0, "1024-65535"] # ports a client may ask for; a list REPLACES this default, so below 1024 only when named
|
|
494
|
+
reverse_max_listeners = 4 # per client connection
|
|
495
|
+
reverse_max_connections_per_listener = 16
|
|
496
|
+
reverse_backlog = 8 # listen(2) backlog
|
|
497
|
+
reverse_idle_secs = 300 # an accepted connection quiet for this long is closed; 0 = never
|
|
498
|
+
udp_max_flows = 16 # per client connection
|
|
499
|
+
udp_packets_per_second_per_flow = 500
|
|
500
|
+
udp_packets_per_second_per_client = 2000
|
|
501
|
+
udp_bytes_per_second_per_client = 4194304 # both directions; the amplification bound. 0 on any rate = no limit
|
|
502
|
+
udp_idle_secs = 60 # no datagram in either direction for this long closes the flow (at least 1)
|
|
503
|
+
udp_datagrams = true # offer `gateway-datagram` on WebTransport: a client that lists it too gets UDP payloads as datagrams; false = control stream only
|
|
504
|
+
udp_oversize = "reliable" # a payload over one datagram: "reliable" (control stream, ordered, retransmitted) or "drop"
|
|
484
505
|
max_buffered_bytes = 4194304 # per connection, for a peer without gateway-credit (at least 262144)
|
|
485
506
|
max_client_buffered_bytes = 33554432
|
|
486
507
|
```
|
|
@@ -561,7 +582,8 @@ in memory: the TCP, DNS, UDP and unix-socket parts of `gateway`, `relay`, WebTra
|
|
|
561
582
|
- `dataStreams` (default `true`) -- whether to offer client-opened QMux data streams. **Set it to `false` for a peer that
|
|
562
583
|
cannot open them: the released Rust client over WebSocket** (`wsh`, `rust-v0.6.0`: "WebSocket transport does not support
|
|
563
584
|
real data streams for this server", #132). Exec output then rides `SessionData` (`data_mode: "virtual"`, as over a relay
|
|
564
|
-
bridge) and `stream-announce`
|
|
585
|
+
bridge) and `stream-announce` is not offered; rpc is stated as `rpc-virtual` instead of `rpc` (see
|
|
586
|
+
[RPC channels](#rpc-channels-object-mode)). It is an option rather than a negotiation because no released
|
|
565
587
|
client says whether it can open streams: the Rust client's `Hello` carries only `mcp` and `file-transfer`. The JS client works
|
|
566
588
|
either way. `host.accept(socket, { dataStreams })` overrides it per connection.
|
|
567
589
|
|
|
@@ -571,7 +593,8 @@ host's first bytes are held until it opens). `accept()` of an in-page host throu
|
|
|
571
593
|
|
|
572
594
|
**`rpc`** takes handler functions only, `rpc: { calc: (channel, ctx) => channel.onRequest('add', ({ a, b }) => a + b) }`
|
|
573
595
|
(the `RpcChannel` is the one `@johnhenry/wsh/server` hands its handlers), with `rpcMaxMessageBytes` (default 1 MiB) and
|
|
574
|
-
`rpcMaxInflight` (default 64). Clients use `client.openRpc('calc')` unchanged.
|
|
596
|
+
`rpcMaxInflight` (default 64). Clients use `client.openRpc('calc')` unchanged. `createReverseHost({ rpc, rpcMaxMessageBytes,
|
|
597
|
+
rpcMaxInflight })` takes the same option, so a host behind a relay can offer rpc (it needs `reportFeatures`, the default).
|
|
575
598
|
|
|
576
599
|
**`sessions`** (`true` or `{ detachTtlMs, maxDetached, ringBytes }`) keeps *exec* sessions alive across a dropped link
|
|
577
600
|
or `client.detach()`, so `resumeSession()` / `attachSession()` work unchanged: the same Attach / Resume / Detach
|
|
@@ -594,6 +617,7 @@ bundler drop what you do not use.
|
|
|
594
617
|
| `@johnhenry/wsh/memory` | `createMemoryHost()`, a host in this realm (above) |
|
|
595
618
|
| `@johnhenry/wsh/host` | the pieces under it, for your own transport: `createConnectionFactory(config)` -- the connection handler `createWshServer`, `createMemoryHost` and `createReverseHost` all run -- plus `bindSocket(socket, ready, { dataStreams })`, `resolveBackends()`, `resolveHostKey()`, `buildAuthorizer()` and `authMethods()`. It does not import the client |
|
|
596
619
|
| `@johnhenry/wsh/reverse` | `createReverseHost()` for a page or Worker: dial out to a relay and serve the operator it bridges. The same function `@johnhenry/wsh/server` exports, minus `exec: true` and `fs: { root }` |
|
|
620
|
+
| `@johnhenry/wsh/testing` | the QMux record and frame codec (`encodeStream`, `encodeRecord`, `RecordDecoder`, `decodeFrames`, the varint and the other frame encoders), for a test that reads, alters and re-wraps what travels on a connection. **Experimental: not part of the stable API**; it may change or disappear in any release |
|
|
597
621
|
| `@johnhenry/wsh/server` | Node only |
|
|
598
622
|
|
|
599
623
|
```js
|
|
@@ -617,13 +641,17 @@ optional ML-KEM backend, is left out of the measurement. What a page ships is wh
|
|
|
617
641
|
<!-- bundle-size:start (generated by `npm run size -- --update`; do not edit) -->
|
|
618
642
|
| browser bundle | minified | gzip |
|
|
619
643
|
| --- | ---: | ---: |
|
|
620
|
-
| `@johnhenry/wsh` (whole entry point) |
|
|
621
|
-
| `@johnhenry/wsh/memory` (whole entry point) |
|
|
622
|
-
| `@johnhenry/wsh/host` (whole entry point) |
|
|
623
|
-
| `@johnhenry/wsh/reverse` (whole entry point) |
|
|
644
|
+
| `@johnhenry/wsh` (whole entry point) | 162.8 kB | 49.1 kB |
|
|
645
|
+
| `@johnhenry/wsh/memory` (whole entry point) | 229.5 kB | 71.6 kB |
|
|
646
|
+
| `@johnhenry/wsh/host` (whole entry point) | 124.8 kB | 41.0 kB |
|
|
647
|
+
| `@johnhenry/wsh/reverse` (whole entry point) | 218.1 kB | 67.3 kB |
|
|
648
|
+
| `@johnhenry/wsh/pipe-relay` (whole entry point) | 7.0 kB | 3.0 kB |
|
|
649
|
+
| `@johnhenry/wsh/testing` (whole entry point) | 7.9 kB | 2.6 kB |
|
|
650
|
+
| `@johnhenry/wsh/page` (whole entry point) | 277.4 kB | 87.6 kB |
|
|
651
|
+
| `@johnhenry/wsh/objects` (whole entry point) | 158.3 kB | 48.4 kB |
|
|
624
652
|
| `import { generateKeyPair } from '@johnhenry/wsh'` | 0.4 kB | 0.3 kB |
|
|
625
|
-
| `import { WshClient } from '@johnhenry/wsh'` |
|
|
626
|
-
| `import { createConnectionFactory } from '@johnhenry/wsh/host'` |
|
|
653
|
+
| `import { WshClient } from '@johnhenry/wsh'` | 134.7 kB | 40.4 kB |
|
|
654
|
+
| `import { createConnectionFactory } from '@johnhenry/wsh/host'` | 101.5 kB | 33.1 kB |
|
|
627
655
|
<!-- bundle-size:end -->
|
|
628
656
|
|
|
629
657
|
### Signing with a page-held signer
|
|
@@ -632,6 +660,191 @@ optional ML-KEM backend, is left out of the measurement. What a page ships is wh
|
|
|
632
660
|
(not both): `publicKey` is the raw 32-byte Ed25519 key or a public `CryptoKey`, `sign` returns the 64-byte signature
|
|
633
661
|
(sync or async). For keys that live in a wallet, a hardware token or another realm and are not a `CryptoKeyPair`.
|
|
634
662
|
|
|
663
|
+
### A page as a host: `@johnhenry/wsh/page` (#190)
|
|
664
|
+
|
|
665
|
+
A page cannot listen, but it can dial a [pipe relay](#a-pipe-relay-johnhenrywshpipe-relay-118) it chose and be a wsh host behind it.
|
|
666
|
+
`createPageHost` does that for **the tools the page has registered with [WebMCP](https://webmachinelearning.github.io/webmcp/)**: the
|
|
667
|
+
page author has already chosen a small surface, named it, given each tool a schema and said which ones change things, and the bridge
|
|
668
|
+
carries exactly that to an MCP client (`wsh-mcp --sealed`, or `client.openRpc('mcp')` with `mcpClientTransport`). It is key login only,
|
|
669
|
+
sealed sessions only, and there is no anonymous mode, no password login, no exec and no file access.
|
|
670
|
+
|
|
671
|
+
```js
|
|
672
|
+
import { captureWebMcp, createPageHost } from '@johnhenry/wsh/page';
|
|
673
|
+
|
|
674
|
+
captureWebMcp(window); // FIRST, before the application's code registers a tool (see "Three sources" below)
|
|
675
|
+
|
|
676
|
+
const host = await createPageHost({
|
|
677
|
+
window, // required, and the only realm this touches: nothing is reached for on the global
|
|
678
|
+
relay: 'wss://relay.example/pipe',
|
|
679
|
+
name: 'shop-tab',
|
|
680
|
+
authorizedKeys: [operatorKeyLine], // required; `authorized_keys` lines, options apply (see "Per-key narrowing")
|
|
681
|
+
mcp: {
|
|
682
|
+
allow: ['search_products', 'add_to_cart'], // by tool name; nothing is allowed by default
|
|
683
|
+
approve: 'consequential', // 'never' | 'consequential' (default) | 'always'
|
|
684
|
+
},
|
|
685
|
+
onSession(who) {}, // a key logged in; return false to refuse it (ask the person first)
|
|
686
|
+
onRefused(r) {}, // as for every host (REFUSAL_REASONS)
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
host.operatorUrl; // give this to the operator: the rendezvous id in it pairs the operator with this page
|
|
690
|
+
host.fingerprint; // this page's host key: the operator pins it (client option `expectHostKey`, `wsh-mcp --host-key`)
|
|
691
|
+
host.sessions; // who is connected now
|
|
692
|
+
await host.revoke(fingerprint); // end that key's session and refuse it until the host is closed
|
|
693
|
+
await host.close();
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
On the far side nothing new is needed: `wsh-mcp --sealed --host-key <host.fingerprint> --identity KEY <host.operatorUrl>` is a stdio MCP
|
|
697
|
+
server any MCP client can launch, and in code `client.connect(host.operatorUrl, { keyPair, sealSession: true })` then
|
|
698
|
+
`client.openRpc('mcp')`. The host serves one operator at a time and dials the relay again when a session ends.
|
|
699
|
+
|
|
700
|
+
**`window` is explicit.** `createPageHost`, `webmcpTools` and `captureWebMcp` read nothing but the object they are given: where tools are
|
|
701
|
+
registered (`window.document.modelContext`, the older `window.navigator.modelContext`), where the indicator is drawn
|
|
702
|
+
(`window.document`), which `WebSocket` dials the relay, and whose origin is reported. A test greps the entry point's source for
|
|
703
|
+
`globalThis`, `document`, `navigator`, timers and so on. So the same code serves an iframe's `contentWindow`, a popup, a worker's `self`
|
|
704
|
+
(no document: supply `indicator` callbacks and a `prompt`, or say `unattended: true`), or a fake window in a test. **Passing `window` is not
|
|
705
|
+
exposing it**: nothing of the page's object graph is reachable unless `expose` is written as well (see [Remote objects](#remote-objects-johnhenrywshobjects-190)). One window per host; serving two is two hosts with two names. The host
|
|
706
|
+
**never follows a navigation to another origin**: when `window.location.origin` changes (or cannot be read, as for a frame that went
|
|
707
|
+
cross-origin) or the window closes, it tells the operator why, ends the sessions and closes (`host.closedReason`, `onClose`). It checks on
|
|
708
|
+
`pagehide`, every second, and before every call. A host that runs in another realm than the window it serves (an opener serving a
|
|
709
|
+
popup, a parent serving an iframe) passes that realm's `timers: { setTimeout, clearTimeout, setInterval, clearInterval }`: the window's own timers die with its document.
|
|
710
|
+
|
|
711
|
+
**Three sources of tools** (the draft API has changed more than once, so none is relied on alone; they are merged by name, earlier wins):
|
|
712
|
+
|
|
713
|
+
1. an explicit list, `mcp: { tools: [...] }`: the same definitions the page passes to `registerTool`. The most robust, and the form to
|
|
714
|
+
use when the page controls its own code;
|
|
715
|
+
2. the capture shim, `captureWebMcp(window)`, called before the application's code: it wraps `registerTool` on
|
|
716
|
+
`document.modelContext` (the current draft) and `navigator.modelContext` (the older one; also `provideContext`, `unregisterTool`,
|
|
717
|
+
`clearContext`), forgets a tool when its abort signal fires or `unregister()` is called, and where the browser has **no** `modelContext`
|
|
718
|
+
provides a minimal one (registration in either generation's style, `getTools`, `executeTool`) so the application code runs everywhere;
|
|
719
|
+
3. the browser's own API, where it lets a page read its tools: `document.modelContext.getTools()` and `executeTool()` (both are in the
|
|
720
|
+
current draft; feature-detected, and listed only for the served window), plus its `toolchange` event for `tools/list_changed`. Absent in most
|
|
721
|
+
browsers today, so this path is exercised against a fake `modelContext` only.
|
|
722
|
+
|
|
723
|
+
**The mapping to MCP.** `tools/list` states `name`, `title`, `description`, `inputSchema` and `outputSchema` as registered and the
|
|
724
|
+
annotations: `readOnlyHint` stays, `consequentialHint` is `destructiveHint`, and what MCP has no field for (`untrustedContentHint`,
|
|
725
|
+
`consequentialHint`, `debugging`, and whether the bridge treated the tool as consequential) is in `_meta["webmcp/annotations"]`.
|
|
726
|
+
`tools/call` runs `execute(input, { signal })`; an MCP cancel (or the session ending, or `callTimeoutMs`) aborts the signal. An object result is
|
|
727
|
+
`structuredContent` with its JSON as the text rendering (a result already shaped `{ content: [...] }`, as the draft's examples return, is kept); a thrown
|
|
728
|
+
error or a rejected promise is a result with `isError` and **the message only, never a stack**; every result carries `_meta["wsh/untrusted"]`
|
|
729
|
+
and `initialize` says the results are untrusted. A tool registered or unregistered later is `notifications/tools/list_changed` (only for
|
|
730
|
+
tools the session may see). A tool that is not allowed, not permitted to the key, or not there answers the same way (`unknown tool`).
|
|
731
|
+
|
|
732
|
+
**Bounds, each refused by name** (`mcp.limits`): `maxTools` 64 (more are not listed), `maxSchemaBytes` 16384 per tool (a tool over it is not listed
|
|
733
|
+
or callable), `maxInputBytes` 65536, `maxResultBytes` 262144, `maxInflight` 4 per session, `maxCallsPerMinute` 30 per session (an unknown tool name counts),
|
|
734
|
+
`callTimeoutMs` 120000. The error names the bound (`refused: maxInflight: more than 2 calls in flight`); `onCall` hears of every one.
|
|
735
|
+
|
|
736
|
+
**Asking the person.** `approve: 'consequential'` (the default) asks before a tool that is **not marked `readOnlyHint`** runs (anything not
|
|
737
|
+
marked read-only is consequential; `consequentialHint` forces it), `'always'` before every call, `'never'` not at all. The question is `mcp.prompt(call, who, { signal })`
|
|
738
|
+
(true allows; anything else, a throw included, denies); the default, where the window has a document, is an accessible modal dialog that names the tool and
|
|
739
|
+
the caller's key fingerprint, shows the input **as text** (nothing is parsed as markup), puts focus on Deny, keeps Tab inside it, treats Escape as Deny,
|
|
740
|
+
returns focus afterwards and denies after 60 seconds. Questions are asked one at a time. Deny is an MCP error and the tool does not run.
|
|
741
|
+
|
|
742
|
+
**The indicator.** While a session is connected, `window.document` has a visible element (`data-wsh-page="indicator"`, `role="status"`) saying so,
|
|
743
|
+
with the key's fingerprint and a **Stop** button that calls `revoke`. Stop ends the session (the operator is told why), and that key is refused until the host
|
|
744
|
+
is closed: a Stop that lets the same key straight back in is not a Stop. If something in the page removes the element while a session is connected it is put back. `indicator: false` is
|
|
745
|
+
refused unless `unattended: true`; a window with no document refuses to start unless the embedder supplies `indicator: { connected(who, { stop }), disconnected(who) }` or
|
|
746
|
+
`unattended: true`; an unattended host denies what needs approval unless `mcp.prompt` answers.
|
|
747
|
+
|
|
748
|
+
**Per-key narrowing.** Put `capabilities="mcp:search_products"` in the key's `authorized_keys` options and that key lists and calls only that tool: the intersection
|
|
749
|
+
with `mcp.allow`. A key whose capabilities name no `mcp:` tool cannot open the channel. For this the host tells every rpc handler what the key may do: `ctx.capabilities`
|
|
750
|
+
(the list, or `null`) and `ctx.permits({ kind: 'mcp-tool', tool })` (asked afresh each time, so `expires` holds). A handler that narrows by `permits` itself declares
|
|
751
|
+
`handler.capabilityScoped = true`; only then may a key that names tools but not `mcp:*` open the `mcp` channel (every other `mcp` handler still needs `mcp:*`).
|
|
752
|
+
|
|
753
|
+
**The host key.** Unless you pass `hostKey` (a key pair or a signer), each page load generates a fresh non-extractable key: the page can sign with it but nothing can read
|
|
754
|
+
it, and it dies with the load. So an operator can pin `host.fingerprint` for that load (show it in the page, or hand it over with `operatorUrl`), but a `known_hosts` entry from an
|
|
755
|
+
earlier load will not match and trust-on-first-use gives no continuity. To keep one identity across loads, inject a store: `hostKeyStore: { load(), save(pair) }` (a non-extractable
|
|
756
|
+
`CryptoKeyPair` can be kept in IndexedDB).
|
|
757
|
+
|
|
758
|
+
**What this narrows, and what it cannot make safe.**
|
|
759
|
+
|
|
760
|
+
- It narrows *who* may call *which* tool: a key login, a sealed session (the relay sees metadata and ciphertext, not a tool name or an argument, and cannot inject a call),
|
|
761
|
+
an allow-list by name, the key's capabilities, the person's approval for consequential tools, bounds on every dimension, and a visible Stop.
|
|
762
|
+
- **A tool does whatever its `execute` does, with the user's session.** A tool that places an order, reads the account page or calls an API as the user does that for the remote
|
|
763
|
+
caller; the allow-list and the dialog decide whether it may be asked, not what it does. Register tools you would be willing to hand to the key's holder, and mark every tool
|
|
764
|
+
that only reads `readOnlyHint: true` (a mislabelled tool skips the question).
|
|
765
|
+
- **Results are the page's data and may carry text written by third parties** (a product review, a message). They are labelled untrusted and `initialize` says so, but an MCP
|
|
766
|
+
client or its model has to treat them as data, not instructions: that is the client's job, not the bridge's.
|
|
767
|
+
- **The approval dialog is the page's own.** A page script (or a tool) can remove, cover or click it; the indicator is put back, not guarded. The bridge protects the person from a remote
|
|
768
|
+
caller, not from code already running in the page.
|
|
769
|
+
- A host that is left open (`reconnect`, the default) can be reached by anyone who holds the rendezvous id **and** an authorized key; the id is a secret, not a credential.
|
|
770
|
+
- What is not offered: exec, files, gateway, more than one operator at a time, and (unless `expose` is written) any access to the page's objects. With `expose`, what that adds is stated in
|
|
771
|
+
[Remote objects](#remote-objects-johnhenrywshobjects-190); `createPageHost({ expose })` then also serves the `wsh-objects` channel, under its own capability (`rpc:wsh-objects`),
|
|
772
|
+
with the same sealing, indicator, Stop and window guard.
|
|
773
|
+
|
|
774
|
+
### Remote objects: `@johnhenry/wsh/objects` (#190)
|
|
775
|
+
|
|
776
|
+
`wsh-objects` is an rpc protocol that reaches an object graph by path: a page's `window`, a worker's `self`, any object a host names as a **root**. It is `values` mode:
|
|
777
|
+
only plain cloneable values ever cross (there are no handles, no events and no callbacks yet; `mode: 'handles'` is refused with a sentence saying it is not built).
|
|
778
|
+
Nothing is reachable but the named roots, and nothing in them is allowed until an allow-list says so.
|
|
779
|
+
|
|
780
|
+
```js
|
|
781
|
+
// the host: any host that takes `rpc` (a Node server, a memory host, a reverse host, a page host)
|
|
782
|
+
import { exposeObjects } from '@johnhenry/wsh/objects';
|
|
783
|
+
createMemoryHost({ auth, hostKey: true, dataStreams: false, sealSession: 'require', rpc: {
|
|
784
|
+
'wsh-objects': exposeObjects({
|
|
785
|
+
roots: { window }, // named roots: all that is reachable
|
|
786
|
+
mode: 'values',
|
|
787
|
+
allow: { // by operation, as paths from a root; `*` is one segment, `**` any number
|
|
788
|
+
get: ['window.document.title', 'window.location.href', 'window.app.**'],
|
|
789
|
+
call: ['window.app.**'], // covers construct
|
|
790
|
+
set: ['window.app.settings.theme'],
|
|
791
|
+
},
|
|
792
|
+
authorize(who, op) { return true; }, // asked for each operation the allow-list let through: { kind, root, path, text }
|
|
793
|
+
limits: { maxOps: 32, maxValueBytes: 262144 },
|
|
794
|
+
}) } });
|
|
795
|
+
|
|
796
|
+
// the far side (importing the entry point also adds client.openObjects())
|
|
797
|
+
import { get, set, call, construct, snapshot, describe } from '@johnhenry/wsh/objects';
|
|
798
|
+
const { window: win } = await client.openObjects(); // the roots, as lazy references
|
|
799
|
+
await win.document.title; // a reference is a lazy path: this one `await` sends ONE `resolve` request,
|
|
800
|
+
await win.app.cart.items.length; // whatever the length of the chain, calls included
|
|
801
|
+
await win.app.cart.add({ sku: 'A1', qty: 2 }); // a call with plain-data arguments; `this` is the object the method was found on
|
|
802
|
+
await set(win.document, 'title', 'Paid'); // not `=`: an assignment cannot be awaited or report a refusal, so it throws a sentence naming set()
|
|
803
|
+
await snapshot(win.app.state, { depth: 3, maxBytes: 256_000 }); // a bounded deep copy (subtrees past `depth` are null)
|
|
804
|
+
await describe(win.app); // names and types the allow-list could walk to, for a REPL or completion
|
|
805
|
+
await get(win.app, 'then'); // a remote property really named "then" (`ref.then` is the awaiting function)
|
|
806
|
+
```
|
|
807
|
+
|
|
808
|
+
`createPageHost({ ..., expose: { window: { mode: 'values', allow: { get: ['document.title', 'app.**'], call: ['app.**'] } } } })` is the same thing on a page host (paths relative to the
|
|
809
|
+
root, which is the `window` that was passed; another root needs `{ object }`), with the sealing, the indicator and Stop, the window guard and the key capability `rpc:wsh-objects`.
|
|
810
|
+
The wire is `roots`, `resolve { root, ops: [{ get } | { call, args } | { construct, args }] }`, `set { root, path, value }`, `describe`, `snapshot { root, path, depth, maxBytes }` (a notification
|
|
811
|
+
`closing { reason }` precedes a host's ending of a session); a value is `{ v }`, or `{ u: kind, type?, text? }` for what cannot be cloned. The core (`objects-core.mjs`: paths,
|
|
812
|
+
serialisation, limits, allow-lists) knows nothing of wsh and needs only a duplex seam (`createDuplexPeer({ send })` is one over a bare `send` / `receive`; an `RpcChannel` is another);
|
|
813
|
+
one test suite runs over both.
|
|
814
|
+
|
|
815
|
+
**What crosses.** A result is plain data (null, booleans, numbers, strings, bytes as `Uint8Array`, arrays, plain objects; bounded in depth and bytes) or a **named non-value**: a
|
|
816
|
+
function, a symbol, a bigint, a `Date`, a `RegExp`, an `Error`, a DOM node or any other object arrives as a `NonValue` (`{ kind, type?, text? }`, e.g. `{ kind: 'object', type: 'HTMLDivElement' }`), **never as a
|
|
817
|
+
handle**. Inside an object or array a member that cannot be cloned is left out (`null` in an array), as JSON does; the keys `__proto__`, `constructor` and `prototype` are never copied; a circular
|
|
818
|
+
reference is left out; an integer past 2^63 is named (it does not survive the integer encoding). What is sent *to* the host is plain data too, copied, and refused if an object has a prototype of its own or
|
|
819
|
+
a refused key. A function, or a remote reference (a path, not a value), cannot be passed as an argument.
|
|
820
|
+
|
|
821
|
+
**Always refused, in every list:** the path segments `__proto__`, `prototype`, `constructor`, `__defineGetter__`, `__defineSetter__`, `__lookupGetter__`, `__lookupSetter__`; `eval`, `Function`, `import`,
|
|
822
|
+
`execScript`; `call`, `apply` and `bind` of a function (they re-aim it); `setTimeout`, `setInterval` and `setImmediate` with a string. An allow-list entry that names one is a configuration error.
|
|
823
|
+
**Refused until an entry names them** (a wildcard such as `window.**` does not): `document.cookie`, `localStorage`, `sessionStorage`, `indexedDB`, `navigator.credentials`, `fetch`, `XMLHttpRequest`,
|
|
824
|
+
`postMessage`, `open` (as a path segment anywhere, so an application method called `open` needs its own entry). **Per-operation allow-lists by path glob; nothing is allowed by default**, and with no `call`
|
|
825
|
+
and no `set` entries the access is read-only for real. To walk to an allowed path a session may read the properties on the way (`window.app` toward `window.app.cart.items`) and no others; after a call the
|
|
826
|
+
chain goes on the *result*, whose path is the callee with `()` (`window.app.getCart().items`). The order of checks is: the always-refused names, the allow-list, the entries that must name a path,
|
|
827
|
+
`authorize(who, op)`, then the operation.
|
|
828
|
+
|
|
829
|
+
**Bounds, each refused by name** (`limits`): `maxOps` 32 per request, `maxArgs` 16, `maxDepth` 8, `maxValueBytes` 262144 (and always under what the transport carries in one message), `maxKeys` 200
|
|
830
|
+
for `describe`, `maxRequestsPerSecond` 50 per channel, `callTimeoutMs` 30000 for a call that returns a promise.
|
|
831
|
+
|
|
832
|
+
**Threat model of `values` mode.** An allow-list of paths means what it says **only because nothing but cloneable values crosses**: a result can never be walked somewhere else, so what a session can
|
|
833
|
+
reach is exactly the paths the lists name (and, below a `get`, the plain data inside that value). That holds up to what the named paths themselves do:
|
|
834
|
+
- **Getters with side effects are still gets.** Reading an accessor property runs its getter, and setting one runs its setter; an entry that allows the path allows the effect. The copy of a value never runs a getter or a `toJSON`
|
|
835
|
+
(an accessor member is left out).
|
|
836
|
+
- **A `call` runs the application's function with the caller's arguments**, with the page's authority: whatever it does, it does. List the functions you would hand to the caller. A wide entry means what it says:
|
|
837
|
+
`window.**` reaches `window.Object.assign`, `window.history.pushState` and every method of every object under it (it still excludes the refused names above).
|
|
838
|
+
- A Proxy used as a root runs its own traps for the paths that pass the allow-list, and for no others.
|
|
839
|
+
- The list is judged by path text. Give a root its real name: a root called `doc` that *is* the `document` is not recognised as `document.cookie` by the entries that must name it.
|
|
840
|
+
- It does not protect against the page's own code, against a function reachable by a listed path doing something unlisted, or against what a person at the keyboard can see. The remote caller sees results, which may hold text
|
|
841
|
+
written by third parties.
|
|
842
|
+
- A sealed session, a key login and a visible indicator (the page host) are what keep a relay and an unknown caller out; `authorize` is where an embedder asks the person.
|
|
843
|
+
|
|
844
|
+
Types: `@johnhenry/wsh/objects` ships `.d.ts` (`client.openObjects<T>()` types the roots; references are untyped). Size: `@johnhenry/wsh/objects` is 48.4 kB gzipped (it contains the client), and
|
|
845
|
+
the page entry point grows to 87.6 kB with it; no other entry point changed. Not built yet (later steps of #190): handles for what cannot be cloned, events and callbacks, a capability per root
|
|
846
|
+
(`objects:ROOT`), typed remotes (`Remote<T>`), an MCP face for the allow-listed paths, and a dial-out form.
|
|
847
|
+
|
|
635
848
|
### WebTransport listener
|
|
636
849
|
|
|
637
850
|
The client's ladder prefers WebTransport (`https://`) and falls back to `wss://`;
|
|
@@ -987,7 +1200,7 @@ a host that does not offer `e2e-session`, one that proved no host key, or a pass
|
|
|
987
1200
|
sent, with a sentence; `false` never seals. `client.sessionSealed` says whether it is. The exchange is bound to the host key the
|
|
988
1201
|
host PROVED on this connection: it authenticates that key, not whose it is, so pin the host as well (`expectHostKey` /
|
|
989
1202
|
`knownHosts`), or a relay that presents its own host key and terminates the exchange is the host to this client. Once sealed, a
|
|
990
|
-
plain message from the host is dropped, a frame that does not open ends the connection (`onError`, then `onClose`), `openStream()`
|
|
1203
|
+
plain message from the host is dropped (counted in `client.droppedMessages`, and reported to `client.onDrop({ reason, messageType })`; nothing is written to the console), a frame that does not open ends the connection (`onError`, then `onClose`), `openStream()`
|
|
991
1204
|
is refused and datagrams are neither sent nor heard (UDP uses the reliable path). `'auto'` is not a guarantee, for the reason above;
|
|
992
1205
|
`true` is.
|
|
993
1206
|
|
|
@@ -998,8 +1211,11 @@ signed key exchange (it verifies the login key's signature, signs its reply with
|
|
|
998
1211
|
from then on every control message but ping/pong is an `EncryptedFrame` both ways, gateway data included, and a frame that does not open
|
|
999
1212
|
closes the connection. `offer` serves a client that never asks as before. `require` serves nothing in the clear: a plain message before
|
|
1000
1213
|
the key exists is answered with an error and the connection is closed, a password login is refused, and WebTransport connections and
|
|
1001
|
-
WISP tunnels are refused (they cannot be sealed; connect over WebSocket). **
|
|
1002
|
-
|
|
1214
|
+
WISP tunnels are refused (they cannot be sealed; connect over WebSocket). **While `seal_session` is on, the typed rpc channels (`wsh-host`, and `wsh-fs` when `[rpc] fs_root` is set)
|
|
1215
|
+
are offered in virtual data mode** (#191): the server states `rpc-virtual` instead of `rpc`, and a channel rides `SessionData` (inside
|
|
1216
|
+
the seal on a sealed session, in the clear on an unsealed one under `offer`) metered by credit, with the `rpc:NAME`, `fs:read` /
|
|
1217
|
+
`fs:write` and file-transfer checks of stream-mode rpc unchanged. With `seal_session` off (the default) rpc is stream-mode, exactly as before.
|
|
1218
|
+
A client that only knows stream-mode rpc finds no `rpc` and is refused before anything is sent; see [RPC channels](#rpc-channels-object-mode). WebTransport on an
|
|
1003
1219
|
`offer` server is served as before and does not list `e2e-session`, so a client that must seal (`sealSession: true`, `--sealed`) is
|
|
1004
1220
|
refused there before a credential is sent. The same limits apply as for the JS host: the handshake before login, sizes and timing,
|
|
1005
1221
|
and a denial of service are not covered, and sealing "on its own" (`'auto'`, the CLI without `--sealed`) against an `offer` server is
|
|
@@ -1041,6 +1257,27 @@ await client.connect(pipeUrl('wss://relay.example', id), { username, keyPair, ex
|
|
|
1041
1257
|
```
|
|
1042
1258
|
|
|
1043
1259
|
The module imports nothing that can execute code or read files (a test walks its module graph); it does not parse wsh.
|
|
1260
|
+
**Browser and Node halves.** `@johnhenry/wsh/pipe-relay` itself is browser-safe -- `pipeUrl`, `newRendezvousId`, `watchPairing` and a relay's
|
|
1261
|
+
`accept()` over sockets you hold bundle for a page (the bundle test covers it, next to `./memory`). `listen()` (an HTTP server through the optional
|
|
1262
|
+
`ws` package) is a second module, `pipe-relay-node.mjs`, loaded when you call it, so a bundler never follows it. `createPipeRelay().listen()` works as it did.
|
|
1263
|
+
|
|
1264
|
+
**Knowing a host was paired.** A host that has dialled and is waiting cannot otherwise tell when its operator arrived. Dial with
|
|
1265
|
+
`pipeUrl(relay, id, 'host', { notifyPaired: true })` (`?role=host&paired=1`; with your own HTTP server, `relay.accept(socket, { id, role: 'host', notifyPaired: true })`),
|
|
1266
|
+
wrap the socket, and await the promise:
|
|
1267
|
+
|
|
1268
|
+
```js
|
|
1269
|
+
const ws = new WebSocket(pipeUrl('wss://relay.example', id, 'host', { notifyPaired: true }));
|
|
1270
|
+
await new Promise((r) => ws.addEventListener('open', r, { once: true }));
|
|
1271
|
+
const { socket, paired } = watchPairing(ws); // before anything else is attached
|
|
1272
|
+
await server.accept(socket); // the wsh host never sees the signal frame
|
|
1273
|
+
await paired; // the operator is here (rejects if the socket closes first)
|
|
1274
|
+
```
|
|
1275
|
+
|
|
1276
|
+
The relay sends the host ONE text frame, `wsh-pipe/1 paired`, when the operator arrives and before anything the operator said; everything else on a pipe is
|
|
1277
|
+
binary, so it cannot be mistaken for wsh bytes. It is opt-in per host and costs nothing otherwise: a relay older than this ignores `paired=1` and never sends it (then
|
|
1278
|
+
`paired` never settles and the connection works as before, so bound the wait with your own timer if you need to know), and a host that did not ask is sent nothing.
|
|
1279
|
+
It tells the host the operator is there, not who it is: the handshake still decides that.
|
|
1280
|
+
|
|
1044
1281
|
Bounds, all with defaults: `maxWaiting`, `rendezvousTimeoutMs`, `idleTimeoutMs`, `maxLifetimeMs`, `maxBytes`,
|
|
1045
1282
|
`maxMessageBytes`, `earlyBytes`, `highWaterBytes` (a receiver that is not draining pauses the sender; a socket that
|
|
1046
1283
|
cannot pause is closed). **Trust difference:** relay mode has the relay vouch for the operator; a pipe relay vouches
|
|
@@ -1231,6 +1468,7 @@ npx -p @johnhenry/wsh wsh-mcp [options] [user@]<url> # or install the pac
|
|
|
1231
1468
|
-l, --user NAME login name (default: the user@ in the URL, $WSH_USER, $USER, the OS user)
|
|
1232
1469
|
-i, --identity FILE Ed25519 private key (default ~/.wsh/keys/default.pem, what `wsh keygen` writes; a PKCS#8 PEM works too)
|
|
1233
1470
|
--channel NAME the rpc channel to open (default mcp)
|
|
1471
|
+
--sealed seal the whole session end to end; refuse a host that cannot (key login only)
|
|
1234
1472
|
--host-key KEY pin the host (hex fingerprint or ssh-ed25519 line); unpinned, it warns on stderr
|
|
1235
1473
|
--no-reconnect, --reconnect-attempts N, --timeout MS
|
|
1236
1474
|
```
|
|
@@ -1247,8 +1485,32 @@ no such channel** (the error lists the channels it does offer and how to serve o
|
|
|
1247
1485
|
attempts from 500 ms, doubling), re-sends the client's `initialize` to the new channel without telling the client, answers a request
|
|
1248
1486
|
that was in flight with a JSON-RPC error (`-32603`, the client may retry) and delivers what the client sent meanwhile (at most 200
|
|
1249
1487
|
messages). `--target` is not offered: rpc channels are not per target on any host (#121). The same bridge is a function,
|
|
1250
|
-
`runMcpStdioBridge()` from `@johnhenry/wsh/mcp-stdio`.
|
|
1251
|
-
|
|
1488
|
+
`runMcpStdioBridge()` from `@johnhenry/wsh/mcp-stdio`.
|
|
1489
|
+
|
|
1490
|
+
**Rust: `wsh mcp`** does the same without Node (the next `rust-v` release):
|
|
1491
|
+
|
|
1492
|
+
```
|
|
1493
|
+
wsh mcp [options] [user@]host|URL # a ws://, wss:// or https:// URL works as the target, as everywhere in wsh
|
|
1494
|
+
-i, --identity NAME the key to log in with: a name in ~/.wsh/keys (what `wsh keygen NAME` makes), default "default"
|
|
1495
|
+
--channel NAME the rpc channel to open (default mcp)
|
|
1496
|
+
--host-key KEY pin the host: 64 hex digits or an ssh-ed25519 line; it must prove that key, known_hosts is neither read nor written
|
|
1497
|
+
--no-reconnect, --reconnect-attempts N, --timeout MS
|
|
1498
|
+
--via URL through a pipe relay, as for every command that dials one host
|
|
1499
|
+
```
|
|
1500
|
+
|
|
1501
|
+
```json
|
|
1502
|
+
{ "mcpServers": { "remote": { "command": "wsh", "args": ["mcp", "-i", "default", "--host-key", "<fingerprint>", "me@host.example"] } } }
|
|
1503
|
+
```
|
|
1504
|
+
|
|
1505
|
+
Behaviour, exit statuses, reconnect, the held-message bound and `stdout` carrying MCP only are as above. What differs from `wsh-mcp`:
|
|
1506
|
+
the identity is a keystore name (`-i`), not a file; without `--host-key` the host is checked against `known_hosts` like every `wsh`
|
|
1507
|
+
command (a first use is refused unless `--accept-new-host-key`, because stdin is the MCP stream and cannot answer a prompt; a key
|
|
1508
|
+
that changed is always refused); `--target` is refused with the usual message. **The Rust `wsh-server` offers no `mcp` rpc channel**
|
|
1509
|
+
(hosting an MCP server is an embedding concern), so `wsh mcp` against it exits 2 with `offers no "mcp" channel (it offers: wsh-host)`;
|
|
1510
|
+
`wsh tools` reaches the tools a `wsh-server` is configured with (`[[mcp.tools]]`). Against a released `wsh-server`, `wsh mcp --channel
|
|
1511
|
+
wsh-host` works (it is the same rpc channel, and a handy check). `wsh mcp` follows what the host states: `rpc` is a data stream, `rpc-virtual` (a sealed session, a host in a page behind a pipe relay) rides
|
|
1512
|
+
`SessionData` with credit (#191), so `wsh mcp --sealed` and `wsh --via <pipe relay> mcp` work against a JS host, as the npm `wsh-mcp --sealed` does. Not covered: WebTransport (`https://`) opens the channel's stream but the Rust client has only
|
|
1513
|
+
been run against WebSocket hosts.
|
|
1252
1514
|
|
|
1253
1515
|
### Host key (fingerprint / TOFU)
|
|
1254
1516
|
|
|
@@ -1281,6 +1543,12 @@ client.onHostKey = (hk) => confirm(`Trust ${hk.fingerprint}?`); // or per call
|
|
|
1281
1543
|
a `code` (`HOST_KEY_MISSING | _INVALID | _MISMATCH | _UNKNOWN | _REJECTED`),
|
|
1282
1544
|
thrown **before any credential -- signature or password -- is sent**.
|
|
1283
1545
|
- `WshClient.exec()` and `connectReverse()` accept the same options.
|
|
1546
|
+
- **A refused login is a `WshAuthError`, a failed connection a `WshConnectionError`** (both `Error`s, with the same message as ever). `WshAuthError` has
|
|
1547
|
+
`code` (`AUTH_UNAUTHORIZED | _BAD_SIGNATURE | _METHOD_DISABLED | _RATE_LIMITED | _KEY_EXPIRED | _BINDING_REQUIRED | _NOT_SEALED | _BAD_REQUEST`, else
|
|
1548
|
+
`AUTH_FAILED`), `reason` (what the host said) and `refusal`, the reason the host reported to its own `onRefused`. The wire carries only the host's
|
|
1549
|
+
words, so `refusal` is recognised from the wording of the Node host and the Rust `wsh-server` (a test keeps the table in step with the Node host's
|
|
1550
|
+
`onRefused` codes); a host that words it otherwise gives `AUTH_FAILED` and `refusal: null`, with the text in `reason`. `WshConnectionError` has `code`
|
|
1551
|
+
`CONNECTION_FAILED` (no transport opened; `attempts` lists each) or `HANDSHAKE_TIMEOUT`.
|
|
1284
1552
|
- `WshKnownHosts` defaults to `localStorage`, which in Node is not a persistent file store: for a real TOFU file pass `new WshKnownHosts({ storage })` with a `getItem`/`setItem`/`removeItem` object you back with a file.
|
|
1285
1553
|
- Wire shape: the spec's `ServerHello.host_fingerprint` is populated, and
|
|
1286
1554
|
because a bare fingerprint proves nothing (anyone can repeat it) the key and
|
|
@@ -1333,9 +1601,12 @@ offer or compute a binding yet, so against them a client with
|
|
|
1333
1601
|
### Password auth
|
|
1334
1602
|
|
|
1335
1603
|
```js
|
|
1604
|
+
import { createWshServer, hashPassword, passwordVerifier } from '@johnhenry/wsh/server';
|
|
1605
|
+
|
|
1606
|
+
const stored = { alice: await hashPassword(process.env.ALICE_PASSWORD) }; // once, offline: keep the strings, not the passwords
|
|
1336
1607
|
createWshServer({
|
|
1337
1608
|
auth: {
|
|
1338
|
-
password:
|
|
1609
|
+
password: passwordVerifier(stored), // or any (username, password) => boolean | Promise<boolean>
|
|
1339
1610
|
// authorizedKeys / authorize may be given too: both methods are then served.
|
|
1340
1611
|
rateLimit: { maxFailures: 5, windowMs: 60_000, lockoutMs: 60_000, failureDelayMs: 250 },
|
|
1341
1612
|
},
|
|
@@ -1348,10 +1619,20 @@ The wire already has it (`Hello.auth_method: 'password'` then `Auth{ method:
|
|
|
1348
1619
|
that is also its limit: the password travels as plain text inside the
|
|
1349
1620
|
connection, so serve password logins over `wss://` (TLS-terminating proxy)
|
|
1350
1621
|
or a link you trust, and pin the host key so it is only ever sent to the right
|
|
1351
|
-
host.
|
|
1352
|
-
never `===` on plaintext. A host with only `password` refuses key logins and
|
|
1622
|
+
host. A host with only `password` refuses key logins and
|
|
1353
1623
|
vice versa; with neither configured every connection is refused.
|
|
1354
1624
|
|
|
1625
|
+
**Storing the passwords.** `hashPassword()` / `passwordVerifier()` (Node entry point only, `node:crypto`) store a password as a PHC
|
|
1626
|
+
`$scrypt$ln=16,r=8,p=1$<salt>$<hash>` string: scrypt (memory-hard, 64 MiB by default), a random per-user salt, a constant-time
|
|
1627
|
+
comparison, and the same derivation for an unknown user as for a wrong password, so neither the answer nor the time says which
|
|
1628
|
+
users exist. An old unsalted `sha256:<hex>` entry is refused (with a warning that names the user, never the hash) unless
|
|
1629
|
+
`allowLegacySha256: true`, which keeps it working with the warning until it is replaced. The Rust `wsh-server` does the same with
|
|
1630
|
+
Argon2id (`wsh-server hash-password`, the password from standard input or a no-echo prompt, never an argument); the two formats are
|
|
1631
|
+
not interchangeable. **Not covered:** this protects the stored file, not the wire (the password still travels inside the connection,
|
|
1632
|
+
see the Security model); `scrypt` is not available to a host that lives in a page, whose `auth.password` stays a callback and whose
|
|
1633
|
+
hash is yours to choose (WebCrypto offers PBKDF2, not scrypt or Argon2; use a high iteration count and a per-user salt); and the
|
|
1634
|
+
throttle's counters are per process.
|
|
1635
|
+
|
|
1355
1636
|
Failures are throttled per peer address (override with `rateLimit.key`, e.g.
|
|
1356
1637
|
read `x-forwarded-for` from `headers` behind a proxy): each connection gets one
|
|
1357
1638
|
guess, a failed one is answered after `failureDelayMs`, and after
|
|
@@ -1468,7 +1749,21 @@ createWshServer({
|
|
|
1468
1749
|
});
|
|
1469
1750
|
```
|
|
1470
1751
|
|
|
1471
|
-
**
|
|
1752
|
+
**Virtual data mode (#191).** On a connection with no client-opened data streams -- a host behind a relay (`createReverseHost`,
|
|
1753
|
+
`ReverseAccept.features`), a page host served with `dataStreams: false`, and every **sealed session** -- the same channel rides the control
|
|
1754
|
+
plane: the same `Open { kind: 'rpc', command: <protocol> }`, the same CBOR sequence, in `SessionData` (inside `EncryptedFrame` when the
|
|
1755
|
+
session is sealed, so a relay sees neither method names nor payloads). The host states `rpc-virtual` **instead of** `rpc`, with the same
|
|
1756
|
+
`rpc-protocol:<name>` and `rpc-max-message:<bytes>`; `openRpc()` picks the form from what the host states and callers change nothing. Because
|
|
1757
|
+
the control plane has no flow control, the channel carries its own: each direction starts with `RPC_CREDIT_WINDOW` (256 KiB) of credit,
|
|
1758
|
+
returned in bytes as the receiver takes data in (`GatewayCredit` with `gateway_id` = `0x80000000 | channel_id`), so a reader that does not
|
|
1759
|
+
read bounds the sender, a message larger than the window still arrives, and a peer that overruns its credit has the channel closed. The size
|
|
1760
|
+
cap is enforced from the CBOR header, before a message is assembled. `wsh-mcp --sealed` (and `runMcpStdioBridge({ sealSession: true })`)
|
|
1761
|
+
reach an `mcp` channel on a sealed host or a host behind a pipe relay. A released client looks for `rpc`, which a virtual-mode host does not
|
|
1762
|
+
state, so it refuses with `UNSUPPORTED_PROTOCOL` before sending anything; a released host never states `rpc-virtual`, so this client uses
|
|
1763
|
+
streams there. What it does **not** change: nothing about who may open a channel (`rpc:<protocol>` capabilities, `authorize`), and over an
|
|
1764
|
+
unsealed relayed session the relay still sees the traffic (seal it).
|
|
1765
|
+
|
|
1766
|
+
**Negotiation.** The host advertises `rpc` (or `rpc-virtual`, above), one `rpc-protocol:<name>` per
|
|
1472
1767
|
protocol and `rpc-max-message:<bytes>` (default 1 MiB) in `ServerHello.features`.
|
|
1473
1768
|
`openRpc()` / `openSession({ type: 'rpc', protocol })` refuse an unadvertised
|
|
1474
1769
|
`rpc` or protocol with an `RpcError` (`code` -32000, `reason: 'UNSUPPORTED_PROTOCOL'`)
|
|
@@ -1530,7 +1825,10 @@ and the Rust `wsh-server` (see below) serve `rpc` today. Not goals: a
|
|
|
1530
1825
|
replacement for byte streams (exec/pty are unchanged), a new transport (`rpc`
|
|
1531
1826
|
rides WebSocket/QMux and WebTransport streams), or an auth change -- an `rpc`
|
|
1532
1827
|
session is opened on an authenticated connection and per-method authorization is
|
|
1533
|
-
the handler's job (`-32003`; `ctx.user` / `ctx.fingerprint` identify the caller
|
|
1828
|
+
the handler's job (`-32003`; `ctx.user` / `ctx.fingerprint` identify the caller; `ctx.capabilities` is the caller's key's capability
|
|
1829
|
+
list, or `null`, and `ctx.permits({ kind: 'mcp-tool', tool })` asks afresh whether the key's options and capabilities allow a request,
|
|
1830
|
+
on the JS hosts; a handler that narrows by `permits` declares `handler.capabilityScoped = true`, see
|
|
1831
|
+
[A page as a host](#a-page-as-a-host-johnhenrywshpage-190)).
|
|
1534
1832
|
Handlers run per channel, so register methods synchronously (or before the
|
|
1535
1833
|
returned promise settles: inbound messages are held until it does).
|
|
1536
1834
|
|
|
@@ -1676,7 +1974,7 @@ so options the platform gains later need no change here.
|
|
|
1676
1974
|
| `WshKeyStore` | Ed25519 key management via IndexedDB + OPFS encrypted backup |
|
|
1677
1975
|
| `WshFileTransfer` | File upload/download over dedicated streams |
|
|
1678
1976
|
| `WshMcpBridge` | Remote MCP tool discovery and invocation |
|
|
1679
|
-
| `RpcChannel` / `RpcError` | Typed RPC channel (JSON-RPC 2.0 over a CBOR sequence): `client.openRpc(protocol)`; `RPC_FEATURE`, `rpcProtocolFeature(name)`, `RPC_ERROR`, `CborSequenceDecoder` |
|
|
1977
|
+
| `RpcChannel` / `RpcError` | Typed RPC channel (JSON-RPC 2.0 over a CBOR sequence): `client.openRpc(protocol)`; `RPC_FEATURE`, `RPC_VIRTUAL_FEATURE`, `rpcProtocolFeature(name)`, `RPC_ERROR`, `CborSequenceDecoder` |
|
|
1680
1978
|
| `mcpClientTransport()` / `mcpServerAdapter()` (`/server`) | MCP SDK `Transport` over an `rpc` channel |
|
|
1681
1979
|
| `SessionRecorder` | Record PTY I/O with timestamps (asciicast-v2-shaped JSON; convert to play in asciinema, see the note under Session recording) |
|
|
1682
1980
|
| `SessionPlayer` | Replay recordings with original timing |
|
|
@@ -1717,7 +2015,7 @@ instead of dragging its own toolchain and CI job into an unrelated
|
|
|
1717
2015
|
browser-app repo. It was previously deleted from clawser by accident
|
|
1718
2016
|
(2026-03-14) and restored (2026-07-05) before this move.
|
|
1719
2017
|
|
|
1720
|
-
Four crates, workspace-versioned (currently `0.
|
|
2018
|
+
Four crates, workspace-versioned (currently `0.17.0`):
|
|
1721
2019
|
|
|
1722
2020
|
| Crate | Kind | Description |
|
|
1723
2021
|
|-------|------|--------------|
|
|
@@ -1739,8 +2037,23 @@ wsh --tty alice@host top # a terminal for the command: raw
|
|
|
1739
2037
|
stdout and stderr stay separate where the host offers `exec-pipes`; the exit status is the command's.
|
|
1740
2038
|
SIGINT, SIGTERM and SIGHUP sent to `wsh` are forwarded to the command, and the same signal twice
|
|
1741
2039
|
disconnects. `wsh connect` ends when the remote session does. Diagnostics go to stderr (`-v` for more),
|
|
1742
|
-
never into the command's stdout.
|
|
1743
|
-
|
|
2040
|
+
never into the command's stdout. A plain `ws://` URL is accepted only for a loopback host.
|
|
2041
|
+
|
|
2042
|
+
**The server's certificate is verified**, on both transports. `wss://` and `https://` (WebTransport) use the platform trust store; `SSL_CERT_FILE` points the
|
|
2043
|
+
`wss://` check at another certificate. A WebTransport server with a self-signed certificate (`wsh-server --generate-cert`) is reached by pinning it:
|
|
2044
|
+
|
|
2045
|
+
```sh
|
|
2046
|
+
wsh --cert-hash "$(openssl x509 -fingerprint -sha256 -noout -in ~/.wsh/cert.pem)" alice@host ls # also: 64 hex digits, colons optional
|
|
2047
|
+
```
|
|
2048
|
+
|
|
2049
|
+
`wsh-server` prints the same hash at start-up. `--cert-hash` is repeatable (the current and the next certificate across a rotation) and has the semantics of
|
|
2050
|
+
`serverCertificateHashes`: the certificate's SHA-256 must be one of the pins, with an ECDSA P-256 key and a validity of at most 14 days (the dev certificate is
|
|
2051
|
+
13), and no certificate authority is consulted. It applies to `https://` only: with a `wss://` URL it is refused rather than ignored. A single pin is also the
|
|
2052
|
+
`cert-hash` [channel binding](#security-model) kind, which `--require-channel-binding` can then be satisfied by. `ConnectConfig.cert_hash` / `cert_hashes` are the
|
|
2053
|
+
same for the library. **Development only:** `--insecure-skip-cert-verification` (`ConnectConfig.insecure_skip_cert_verification`) turns the check off
|
|
2054
|
+
for WebTransport, prints a warning on every connection, and is refused together with `--cert-hash` and with a password login (a password cannot be sealed end
|
|
2055
|
+
to end, so it would go to whoever answers the unverified connection). A login by key is still covered by the host-key check (`known_hosts`, `--host-key`)
|
|
2056
|
+
and the channel binding; a host that proves no key is simply not authenticated in this mode.
|
|
1744
2057
|
|
|
1745
2058
|
`wsh --target NAME [user@]host [command...]` runs on one of the host's execution targets and `wsh targets [user@]host` lists the ones this key may
|
|
1746
2059
|
use (see [Execution targets](#execution-targets-121)); it is sent only to a host that advertises `targets`.
|
|
@@ -1866,34 +2179,36 @@ than left to be found.
|
|
|
1866
2179
|
| Remove a remote file | `WshClient.fileRemove()` | `file_transfer::remove()`, `wsh sftp`'s `rm` | **Wire-unified**: `FileOp`/`FileResult` (`op: "remove"`) -- refused today by every `wsh-server` release ("not yet implemented"), the same refusal on both sides |
|
|
1867
2180
|
| Install an authorized key | `WshClient.addAuthorizedKey()` | `wsh_client::WshClient::add_authorized_key()`, `wsh copy-id` | **Wire-unified** (wsh #59): `AuthorizedKeyAdd`/`AuthorizedKeyResult`, replacing a Rust-CLI-only shell command with a message every implementation can send |
|
|
1868
2181
|
| Host identity / TOFU | `WshKnownHosts` (localStorage-backed) | `KnownHosts`/`HostStatus` (`~/.wsh/known_hosts`-backed); the client sends `host-key-nonce`, verifies `host-key`/`host-key-sig`, pins only a proven key, and a first use needs `--accept-new-host-key` or a yes at a terminal (`--require-host-key` refuses a host with no proof); `wsh-server` has an opt-in host key (`[server] host_key`) | **Unified** (wsh #59, #145): both pin a PROVEN `ServerHello.host_fingerprint`. A Rust server with no `host_key` configured (the default, so released clients keep working) proves nothing |
|
|
1869
|
-
| Typed RPC channels (`openRpc`, `rpc` sessions; `wsh-host`, `wsh-fs`, `mcp`) | `WshClient.openRpc()`, `RpcChannel` | Rust `wsh-server` (`rust-v0.4.0`+): `wsh-host`, and `wsh-fs` when `[rpc] fs_root` is set
|
|
1870
|
-
| MCP over stdio for MCP clients that launch a command (#127) | `wsh-mcp` (the package's `bin`) and `runMcpStdioBridge()` from `@johnhenry/wsh/mcp-stdio`: opens the host's `mcp` rpc channel, reconnects, a clear error when the host offers none |
|
|
2182
|
+
| Typed RPC channels (`openRpc`, `rpc` sessions; `wsh-host`, `wsh-fs`, `mcp`) | `WshClient.openRpc()`, `RpcChannel` | Rust `wsh-server` (`rust-v0.4.0`+): `wsh-host`, and `wsh-fs` when `[rpc] fs_root` is set. **Client:** `WshClient::open_rpc(protocol)` in `wsh-client` (the next `rust-v` release; #127) returns an `RpcChannel` that sends and receives JSON-RPC messages (`rpc_offer()` tells what the host serves); it opens the channel's data stream over WebSocket/QMux (and WebTransport, not exercised against a host) and enforces `rpc-max-message`. It does not correlate requests or interpret `$/cancel` / `$/progress` (its one user, `wsh mcp`, passes MCP through), and there are no typed `wsh-fs` helpers in Rust (the Rust file commands use `FileOp`) | **No wire change**: `Open { kind: 'rpc', command: <protocol> }` plus `rpc*` `ServerHello` features, negotiated so it fails fast elsewhere; the Rust server serves it on WebSocket/QMux only. **Virtual data mode (#191; the next `rust-v` release): both sides.** `RpcOffer` reads `rpc-virtual` and `open_rpc` chooses the form from what the host states (a host that states `rpc` is opened with a stream as before); a virtual-mode `RpcChannel` writes `SessionData` and `GatewayCredit` (`gateway_id = 0x80000000 | channel_id`, 256 KiB per direction, returned as `recv()` takes messages in, so a slow reader bounds the sender; an overrun closes the channel; the size cap is checked from the CBOR header). `wsh-server` with `seal_session` on states `rpc-virtual` instead of `rpc` (it no longer withholds rpc), with the checks stream-mode rpc applies (`rpc:NAME`, `fs:read` / `fs:write`, file-transfer). A released Rust client looks for `rpc`, finds none, and refuses before sending anything. (`rpc` is now listed in the spec's `ChannelKind`; the bytes are what they were, the Rust server already read the kind from the raw message) |
|
|
2183
|
+
| MCP over stdio for MCP clients that launch a command (#127) | `wsh-mcp` (the package's `bin`) and `runMcpStdioBridge()` from `@johnhenry/wsh/mcp-stdio`: opens the host's `mcp` rpc channel, reconnects, a clear error when the host offers none | `wsh mcp [user@]host\|URL` (the next `rust-v` release): the same bridge, behaviour for behaviour (`--channel`, `--host-key`, reconnect with `initialize` replayed, in-flight requests answered with an error, 200 held messages, exit 2 with the channels the host offers). Identity is `-i NAME` (a `wsh keygen` key), the host is pinned by `known_hosts` or `--host-key`, `--via` works, and so does `--sealed` and a host in a page behind a pipe relay (rpc in virtual data mode, #191; `test/rust/wsh-rpc-virtual.test.mjs`). **`wsh-server` serves no `mcp` rpc channel, so `wsh mcp` to it exits 2 and says it offers `wsh-host`** (use `wsh tools` there: it answers `McpDiscover` / `McpCall`) | **Unified** -- no wire change (the channel is #85's); tested against a Node host and a memory host with the MCP SDK's stdio client (`test/rust/wsh-mcp.test.mjs`) |
|
|
1871
2184
|
| Exec stdin + EOF, separate stderr | `exec({ stdin })`, `session.closeStdin()`, `session.onStderr` | `SessionOpts { stdio: Some("pipes") }`, `WshSession::read_stderr()` / `close_stdin()`; `wsh host command` uses them whenever its stdin is a pipe or a file and the host offers `exec-pipes` | **Wire-unified, negotiated** (#105): `Open.stdio = "pipes"` + `OpenOk.stderr_channel_id` + zero-length `SessionData` as EOF, offered by the `exec-pipes` `ServerHello` feature. `@johnhenry/wsh/server` needs none of it (stream-mode EOF); the Rust `wsh-server` (`rust-v0.5.0`+) runs such an exec on pipes, everything else on the PTY. Against a host without `exec-pipes` the CLI still forwards stdin, but cannot tell the command it ended |
|
|
1872
2185
|
| Signals and resize for a one-off command | `session.signal()`, `session.resize()` | `wsh host command` forwards SIGINT/SIGTERM/SIGHUP (the same signal twice disconnects); `wsh --tty host command` also forwards terminal resizes | **Wire-unified** (`Signal`, `Resize`). The Rust `wsh-server` delivers `Signal` (#145) to a pty session's foreground process group (what ^C reaches) and to an exec-on-pipes command's own process group, for `HUP INT QUIT TERM KILL USR1 USR2 WINCH CONT STOP TSTP ALRM` (with or without `SIG`); another name is ignored, and only the control attachment of the connection that owns the channel can send one. Not delivered on Windows |
|
|
1873
2186
|
| Dial target | a URL | `wsh [user@]host` (dials `https://` then `wss://` on `--port`), or a full URL: `wsh wss://host:8443/rendezvous/ab12 command`, `ws://127.0.0.1:PORT/` | **CLI-only convenience**: a URL is dialled exactly as given (no transport fallback; `--port` and `--transport` do not apply). Plain `ws://` is accepted only to a loopback host |
|
|
1874
2187
|
| Host that runs in a browser page (`createMemoryHost`, `@johnhenry/wsh/reverse`) | yes, with injected `pty` / `fs` / `hostKey` | no (a Rust host is a process) | **JS-only**. A Rust *client* can operate such a host only with `dataStreams: false` (#132): the released Rust client over WebSocket cannot open QMux data streams, and says nothing in `Hello` that a host could use to decide. `wsh scp` works against such a host with the Rust client of the next `rust-v` release (it speaks `FileChunk`, #140); a released `rust-v0.11.0` or older `wsh scp` hangs against it (`wsh ls` and exec work) |
|
|
2188
|
+
| A page's WebMCP tools served as MCP, behind a pipe relay (#190) | `createPageHost`, `webmcpTools`, `captureWebMcp` from `@johnhenry/wsh/page`; the far side is `wsh-mcp --sealed` or `openRpc('mcp')` | the far side works where the Rust client speaks virtual-mode rpc: it does not yet, so `wsh mcp` cannot reach a page host | **JS-only** host (a page); the far side is unchanged wire (`mcp` rpc in virtual mode, #191) |
|
|
2189
|
+
| Remote objects by path, `values` mode (#190): `wsh-objects`, `client.openObjects()` | `exposeObjects` / `createObjectsServer` / `createPageHost({ expose })` host side; `get`, `set`, `call`, `construct`, `snapshot`, `describe` far side (`@johnhenry/wsh/objects`) | none: the Rust client and `wsh-server` do not speak `wsh-objects`, and `wsh-server` has no handler for it | **JS-only**; an rpc protocol on the existing `rpc` channel (no new message or feature string), so a released peer simply does not offer or open it |
|
|
1875
2190
|
| Interactive shell UI | none -- this SDK is a protocol client, not a terminal emulator; pair with xterm.js/ghostty-web | `wsh connect`, `wsh sftp` (line-oriented REPL) | **Deliberately not unified** -- a browser embeds a terminal widget the host page owns; a CLI process owns its own TTY |
|
|
1876
2191
|
| Attach / resume | `attachSession()`, `resumeSession()`, `WshSession.seq` | `attach_session()`, `resume_session()` | **Wire-unified** (`Attach`/`Resume`/`Presence`); `seq` = cumulative output bytes. `@johnhenry/wsh/server` honours `last_seq` (bounded ring, gap errors) and answers Presence with `channel_id`/`seq`; the Rust `wsh-server` does the same (`rust-v0.2.0`+; fixed 256 KiB ring) |
|
|
1877
2192
|
| Reverse-connect / relay peer | `connectReverse()`, `trustRelayPeer()`; `@johnhenry/wsh/server`: `relay` option and `createReverseHost()` | `wsh reverse`, `wsh agent` (persistent, with startup-unit install) | **Wire-unified** (registration, discovery, signed peer records); **daemonization is CLI-only** -- a browser tab cannot be a background OS service. The Node relay is default-deny and bridges one operator per peer unless `maxOperatorsPerPeer` is raised (`busy:` reasons say so); E2E and bridged feature gates need `rust-v0.3.0`+ on the Rust side. **Several operators per peer (#93): both relays** (`maxOperatorsPerPeer`; `[relay] max_operators_per_peer`, default 1) **and both peers** (`createReverseHost({ maxOperators })`; `wsh --max-operators n reverse` / `agent run`, default 1), negotiated by `relay-multi-operator`; a Rust peer serving several operators does not seal bridges (see the reverse-mode notes), and the Rust relay leaves a peer connected when its operator leaves. The signed `KeyExchange` (`e2e-sign`) is carried by the Rust relay too |
|
|
1878
2193
|
| Post-quantum E2E (experimental) | `initiateE2E()` (WebCrypto ML-KEM-768 or `@noble/post-quantum` fallback) | `E2eKeyExchange` (`ml-kem` crate) | **Wire-unified** algorithm and transcript; key material backends differ by platform necessity |
|
|
1879
2194
|
| Unix-domain socket forwarding, both directions; named endpoints (#120) | `client.openUnix()`, `listenUnix()`, `forwardUnix()` (Node: `-L`/`-R` shapes with unix and TCP ends mixed), `openEndpoint()`; host: `gateway: { unix, endpoints }`, `createMemoryHost({ endpoints })` | `wsh-server` serves `OpenUnix`/`ListenUnix` (`[gateway] unix_connect`, `unix_listen`, `unix_replace_stale`, `unix_max_listeners`; same policy as the Node host); `wsh-client` has `open_tcp`/`open_unix`/`open_endpoint`/`listen_unix`/`listen_tcp`; CLI `wsh -L` / `-R` / `-N` with TCP, unix and `endpoint=NAME` ends, also through `--via` | **Wire-unified, both directions** (#145). A Rust host does not offer named endpoints (an in-page host does); the CLI reaches them. See [Forwarding with `wsh -L`](#forwarding-with-wsh--l---r---n) |
|
|
1880
2195
|
| Gateway flow control (#123) | credit per connection (`GatewayCredit`, feature `gateway-credit`); host caps for peers without it | `wsh-server` and `wsh-client`: 256 KiB per direction when both list `gateway-credit`; without it, per-connection and per-client byte caps (`max_buffered_bytes` 4 MiB, `max_client_buffered_bytes` 32 MiB) close the connection that exceeds them | **Wire-unified, negotiated**; an older peer on either side keeps working under the caps. `OpenUdp` flows are metered too (a datagram without credit is dropped) |
|
|
1881
|
-
| TCP reverse tunnels (`ListenRequest`, #98) | `@johnhenry/wsh/server` `gateway.reverse` (off by default; loopback unless the operator lists addresses; port allow-list, nothing below 1024 unless named; bounded listeners/connections/backlog/idle); client `listenTcp(port, { onConnection })` | `wsh-server` `[gateway] enable_reverse_tunnels` + `reverse_bind_addr` (off by default, loopback, client `bind_addr` ignored);
|
|
1882
|
-
| UDP (`OpenUdp`) as WebTransport datagrams (#124) | `client.openUdp()` over WebTransport when both ends list `gateway-datagram`: payloads are datagrams (4-byte flow id + payload), read from `maxDatagramSize`; oversize goes on the control stream (or drops); bounds: flows, packet and byte rates, idle; policy as TCP. Host: `gateway.udp`; Playwright test from Chromium | `wsh-server`
|
|
2196
|
+
| TCP reverse tunnels (`ListenRequest`, #98) | `@johnhenry/wsh/server` `gateway.reverse` (off by default; loopback unless the operator lists addresses; port allow-list, nothing below 1024 unless named; bounded listeners/connections/backlog/idle); client `listenTcp(port, { onConnection })` | `wsh-server` `[gateway] enable_reverse_tunnels` + `reverse_bind_addr` (off by default, loopback, client `bind_addr` ignored); **`reverse_ports`** (default `[0, "1024-65535"]`, a list replaces it), **`reverse_max_listeners`** 4, **`reverse_max_connections_per_listener`** 16, **`reverse_backlog`** 8, **`reverse_idle_secs`** 300, with the Node host's defaults and refusal sentences (the next `rust-v` release; **breaking** for a deployment that listened below 1024 or kept a quiet tunnel for more than 5 minutes, see the CHANGELOG) | **Wire-unified** (`ListenRequest`/`ListenOk`/`ListenFail`/`InboundOpen`/`InboundAccept`; the JS host sends the real `peer_addr`/`peer_port`); **same bounds on both hosts**. Accepted connections are metered by `gateway-credit`. The Rust idle limit watches only a connection the relay is reading (one parked on the client's credit is bounded by the credit window and the caps instead) |
|
|
2197
|
+
| UDP (`OpenUdp`) as WebTransport datagrams (#124) | `client.openUdp()` over WebTransport when both ends list `gateway-datagram`: payloads are datagrams (4-byte flow id + payload), read from `maxDatagramSize`; oversize goes on the control stream (or drops); bounds: flows, packet and byte rates, idle; policy as TCP. Host: `gateway.udp`; Playwright test from Chromium | `wsh-server` (the next `rust-v` release): the socket is `connect()`ed to the checked address, with **the same bounds as the JS host**: `udp_max_flows` 16, `udp_packets_per_second_per_flow` 500, `udp_packets_per_second_per_client` 2000, `udp_bytes_per_second_per_client` 4 MiB (both directions, `0` = no limit), `udp_idle_secs` 60 counted in both directions, on BOTH paths. **Over WebTransport it lists `gateway-datagram` in `ServerHello.features`** (`udp_datagrams`, default `true`) and, for a client that lists it too, carries the payloads as datagrams `[gateway_id u32 BE][payload]` (a datagram for an unknown flow or one that is malformed is dropped); the limit is read from the QUIC connection for every payload (`max_datagram_size`) and a payload over it goes on the control stream as `GatewayData`, or is dropped with `udp_oversize = "drop"`. A client that did not list the feature, and every WebSocket client, is served over the control stream (one `GatewayData` per datagram) exactly as before. No `gatewayStats()` counters yet (the Node host's `datagramsFromClient`, `rateDropped`, ...); drops are logged at `debug` | **Same on both hosts** (negotiated by `gateway-datagram`: a released peer on either side keeps the reliable path). Tested end to end: the JS client over a real QUIC session against the Rust binary (`test/rust/wsh-rust-server-udp-datagrams.test.mjs`) and unit tests of the framing, the policy and the bounds; **not tested**: a browser (Chromium) against the Rust server (the Playwright test runs against the Node host), and datagrams on a sealed session (WebTransport is never sealed on `wsh-server`, and the JS client sends none when it seals) |
|
|
1883
2198
|
| Gateway destination policy by resolved address | `@johnhenry/wsh/server` `gateway`: resolved address checked, `allowPrivate` | fixed in the Rust release after `rust-v0.6.0`: a loopback/private/link-local/ULA/CGNAT/unspecified/multicast address is refused after resolution unless a rule names it, and the server connects to the address it checked | **Same rule on both sides** (a Rust server released before that still has the name-only check) |
|
|
1884
2199
|
| Operator proof to the peer, sealed bridge, signed initiator half (#117) | `reverseConnect(.., { sealed, requirePeerProof })`; host `createReverseHost({ requireOperatorProof })`; relay lists `operator-proof` | **Operator proof: yes.** The Rust relay lists `operator-proof` and carries `ReverseChallenge`/`ReverseProof`/`ReverseConnect.features`; `wsh reverse-connect` answers a challenge (`--operator-proof` / `--no-operator-proof`; by default only for a peer that registered the `operator-proof` capability, because a released Rust host cannot decode the field); `wsh reverse` / `wsh agent run` challenge, verify BEFORE accepting, and take `--require-operator-proof` and `--allow-operator`. **Sealed bridge and both signed `KeyExchange` halves: yes** (`wsh reverse-connect --sealed`; a host with an identity states `e2e` / `e2e-sign` / `e2e-sealed` in its `ReverseAccept` once it has proven the operator). The exchange is byte-identical to JS (transcripts compared against vectors printed by the JS code), hybrid X25519+ML-KEM-768 negotiated exactly as JS does, X25519 when the peer lists no ML-KEM key. A host started with `--require-operator-proof` REQUIRES the sealed bridge (the JS rule): until the key exists it hears and sends nothing but the key exchange, and drops a bridge that has not sealed in 10 s; an operator that does not seal gets no answer to its plain messages. Every message that would cross the relay travels as an `EncryptedFrame` on channel 0; a plain message (wrapped or not) is dropped; **a frame that does not open (tampered, replayed, reordered) closes the bridge** (stricter than the JS host, which drops the frame and ignores the rest). Not covered: a direct or pipe-relayed connection, and `GatewayData` outside a reverse bridge (#155) | **Wire-unified, negotiated** (`ReverseConnect.features`, `operator-proof`, `e2e-sealed`); both implementations seal a reverse bridge |
|
|
1885
|
-
| Channel binding of the login signature (#119) | `requireChannelBinding` (client and server); kinds `host`, `cert-hash`, `tls-exporter` | Kind `host`: the client binds to the proven host key (`--require-channel-binding`, and it honours `channel-binding-required`), and `wsh-server` offers it and can require it (`[server] require_channel_binding`, needs `host_key`). `cert-hash
|
|
2200
|
+
| Channel binding of the login signature (#119) | `requireChannelBinding` (client and server); kinds `host`, `cert-hash`, `tls-exporter` | Kind `host`: the client binds to the proven host key (`--require-channel-binding`, and it honours `channel-binding-required`), and `wsh-server` offers it and can require it (`[server] require_channel_binding`, needs `host_key`). `cert-hash`: in the Rust client when the connection is pinned to exactly one certificate (`--cert-hash`, `ConnectConfig.cert_hash`); `tls-exporter`: not in Rust | **Wire-unified, negotiated** (`channel-binding:<kind>` features); verified against the spec's test vectors |
|
|
1886
2201
|
| Pipe relay (#118) | `@johnhenry/wsh/pipe-relay` | operator side only (#145): `wsh --via wss://relay/r/<id> user@host command...` (also `connect`, `scp`, `ls`, `sftp`, `copy-id`), or the URL as the target. The host side of a pipe is not implemented in Rust. As on a direct connection the Rust client verifies the host-key proof (`host-key` / `host-key-sig` over its own nonce) before sending a credential, pins only a proven key, and binds the login to it (channel binding `host`; `test/rust/wsh-cli-identity.test.mjs`); the pipe-relayed session itself is not sealed (see Security model). `wsh -N -L` exits non-zero when the host drops the session (#156), and the error lines show the relay and a shortened id, never the whole rendezvous id | **Deliberately a relay without wsh parsing** -- nothing to unify on the wire. `--via` keeps `user@host` as the identity: its key is recorded in `known_hosts` under `host:port` (what a direct connection uses), never under the relay's address; a URL target is recorded under the URL's own authority, i.e. the relay's. The URL is not saved to `last_session.json` (the id is a capability) |
|
|
1887
2202
|
| Execution targets (#121): `Open.target`, `FileOp.target`, `OpenEndpoint.target`, `ListTargets` / `TargetList` | host: `targets` on `createWshServer` / `createMemoryHost` (own backends and `authorize(who, { target, kind })` per target, `requireTarget`); client: `openSession({ target })`, `exec(.., { target })`, `fileOperation(.., { target })`, `openEndpoint(.., { target })`, `listTargets()` | CLI: `wsh --target NAME [user@]host [command...]` and `wsh connect` (exec and shells only; every other subcommand, `-L`/`-R`/`-N` and `--share` refuse `--target`), `wsh targets [user@]host [--json]`; the client's `open_session(SessionOpts { target })` and `list_targets()` (file and endpoint calls send no target). **A Rust host with targets: not built**: `wsh-server` states no `targets`, refuses a request that names one and answers `ListTargets` with an error | **Wire-unified, negotiated** (`targets` feature; every new field optional, never sent to a host that did not advertise it) |
|
|
1888
2203
|
| Operator-side shared folders (`--share`, #159) | host side: `onShare(name, fs, who)` on `createMemoryHost` / `createWshServer` / `createReverseHost` (the host *uses* the operator's directories; `fs` is an object of async file operations, also shaped like an `fs` backend; `fs.root` is the operator's advisory, unverified path for the share, #164). The JS client does not offer shares | CLI side: `wsh --share NAME=/abs/dir[:ro\|:rw]` offers them, with each directory's path unless `--share-hide-path` (`wsh_client::share`, `wsh-cli`'s `sharefs`: descriptor-relative, never follows a link, see [Sharing a directory](#sharing-a-directory-with-the-host-wsh---share-159)); unix only. **A Rust host that uses shares: not built** (`wsh-server` does not state `shares`) | **Wire-unified, negotiated**: the host states the feature `shares`; the client sends one `ShareOffer` after login (opcodes `0xa8` `ShareOffer`, `0xa9` `ShareRequest`, host to client, `0xaa` `ShareReply`). No change notification, no sharing over `reverse-connect` |
|
|
1889
|
-
| Sealed session: any authenticated connection incl. gateway/endpoint data (#155) | host `sealSession: 'offer' \| 'require'` (stage b); client `connect(url, { sealSession: false \| 'auto' \| true })` (stage c) | `wsh --sealed ...` (or automatic against `e2e-session-required`) seals a direct or pipe-relayed session; `wsh-server` offers or requires it on WebSocket (`[server] seal_session = "off" \| "offer" \| "require"`, needs `host_key`; `require` refuses WebTransport, WISP tunnels and password logins;
|
|
2204
|
+
| Sealed session: any authenticated connection incl. gateway/endpoint data (#155) | host `sealSession: 'offer' \| 'require'` (stage b); client `connect(url, { sealSession: false \| 'auto' \| true })` (stage c) | `wsh --sealed ...` (or automatic against `e2e-session-required`) seals a direct or pipe-relayed session; `wsh-server` offers or requires it on WebSocket (`[server] seal_session = "off" \| "offer" \| "require"`, needs `host_key`; `require` refuses WebTransport, WISP tunnels and password logins; with it on, the typed rpc channels (`wsh-host`, and `wsh-fs` when `[rpc] fs_root` is set) are offered in virtual data mode, #191: stated `rpc-virtual` instead of `rpc`, riding `SessionData` inside the seal, with the same credit accounting and the same per-key capability checks as stream-mode rpc) | **Wire-unified, negotiated** (`e2e-session`, `e2e-session-required`, `KeyExchange` for the connection's session id, `EncryptedFrame` channel 0) |
|
|
1890
2205
|
| Refusal event with stable reason codes (`onRefused`, #163) | `onRefused({ reason, who, detail })` on `createMemoryHost` / `createWshServer` / `createReverseHost`; `REFUSAL_REASONS` from `@johnhenry/wsh/host` | none: `wsh-server` and `wsh reverse` log a refusal, they have no callback (an embedding process has none) | **JS-only** -- a host-side callback of the embedding API, no wire change |
|
|
1891
2206
|
| `AuthOk.ttl` enforced, `token` opaque (#125) | `connectionTtlMs`; `client.authTtl` | `wsh-server` sends `ttl: 0` (no lifetime promised; `session_ttl` is the lifetime of a *detached* session) and an HMAC token that nothing accepts back | **Wire-compatible**: both fields are still sent (released peers require them). **Changed in the Rust server after `rust-v0.6.0`**: it used to send `session_ttl` (86400), which nothing enforced. The Rust client ignores `ttl` |
|
|
1892
2207
|
| `clientEnv` allow-list (#126) | default `TERM`, `COLORTERM`, `LANG`, `LANGUAGE`, `LC_*` | `wsh-server`: the same default; `[server] client_env = true` (everything, the old behaviour), `false` (nothing) or a list of names / `PREFIX*` (replaces the default) | **Both hosts**; wire unchanged. **Breaking default in the Rust server**, see the CHANGELOG |
|
|
1893
2208
|
| `authorized_keys` options (#122): `restrict`, `permit-*`, `no-pty`, `command=`, `max-sessions=` | `auth.authorizedKeys` lines with options on `createWshServer` / `createMemoryHost`; `parseAuthorizedKeyEntries()` | `wsh-server` reads `~/.wsh/authorized_keys` (then `~/.ssh/authorized_keys`) | **Same rules and the same vectors on both hosts** (`spec/key-options.vectors.json`, run by the JS suite and a Rust test); an option that is not understood keeps the key out, on both. See [Authorized-key options](#authorized-key-options-122) for the per-host column |
|
|
1894
2209
|
| Per-key capabilities and expiry (#122): `capabilities="..."`, `expires="..."`; `authorize()` may return a set | every entry the host has: `Open` kinds, `FileOp` read vs write, gateway TCP/UDP/unix/endpoint open and listen, MCP discovery and calls, targets, rpc channels, relay; refusals through `onRefused` (`not-permitted`, `key-expired`) | the same, except **no endpoints and no targets** (`endpoint:` / `target:` parse and grant nothing; such requests are refused); refusals are logged, there is no callback; no `authorize` | **Same grammar, same vectors, same refusal codes on both hosts**; default-deny only for a key whose line has `capabilities`. Neither covers sessions already open, see [Security model](#security-model) |
|
|
1895
2210
|
| Session recording/replay | `SessionRecorder`/`SessionPlayer` (asciicast-v2-shaped JSON) | none | **JS-only** -- no current Rust consumer needs playback; the vocabulary is asciicast v2's, so a Rust port could share it |
|
|
1896
|
-
| Self-signed cert pinning | `serverCertificateHashes` (WebTransport option) |
|
|
2211
|
+
| Self-signed cert pinning | `serverCertificateHashes` (WebTransport option) | `--cert-hash <sha256>` (repeatable) and `ConnectConfig.cert_hash`/`cert_hashes`, with the same rules (SHA-256, ECDSA P-256, at most 14 days); `wsh-server` prints its certificate hash at start-up. Without a pin the certificate is validated against the system trust store; `--insecure-skip-cert-verification` is the development-only opt-out | **Not a wire concept**; a default changed in the Rust client, see the CHANGELOG |
|
|
1897
2212
|
|
|
1898
2213
|
### Build and test
|
|
1899
2214
|
|
|
@@ -1948,7 +2263,7 @@ plus one `SHA256SUMS` file covering every archive in the release. These
|
|
|
1948
2263
|
names are a stable contract other repos (clawser) pin and download by --
|
|
1949
2264
|
do not change them without coordinating downstream.
|
|
1950
2265
|
|
|
1951
|
-
`wsh --version` and `wsh-server --version` print the workspace version the binary was built from (`wsh 0.
|
|
2266
|
+
`wsh --version` and `wsh-server --version` print the workspace version the binary was built from (`wsh 0.17.0`), which is the
|
|
1952
2267
|
number in the `rust-vX.Y.Z` tag. Binaries of `rust-v0.9.0` to `rust-v0.10.0` printed a fixed `0.1.0`, so against one of those the
|
|
1953
2268
|
version cannot be read from the binary (look for a flag in `wsh --help` instead).
|
|
1954
2269
|
|
|
@@ -2058,6 +2373,16 @@ out explicitly below rather than left to be discovered.
|
|
|
2058
2373
|
|
|
2059
2374
|
**What is still yours:**
|
|
2060
2375
|
|
|
2376
|
+
- **A page host (`@johnhenry/wsh/page`, #190) lets a remote key call the page's allow-listed WebMCP tools, and nothing else.** What it narrows
|
|
2377
|
+
(key login, sealed session, an allow-list by tool name, the key's `mcp:TOOL` capabilities, the person's approval for consequential tools,
|
|
2378
|
+
bounds, a visible Stop) and what it cannot make safe (a tool does whatever its `execute` does with the user's session; results may carry
|
|
2379
|
+
third-party text and are untrusted to the MCP client; the dialog and the indicator belong to the page and are not a defence against code
|
|
2380
|
+
already in it; a fresh host key per page load means no pin outlives it unless `hostKeyStore` is given) are stated in
|
|
2381
|
+
[A page as a host](#a-page-as-a-host-johnhenrywshpage-190).
|
|
2382
|
+
- **`wsh-objects` (`@johnhenry/wsh/objects`, #190) lets a key read, call and set the paths an allow-list names on the roots a host names, and nothing else.** An allow-list of paths means what it says
|
|
2383
|
+
only because nothing but cloneable values crosses (no handles in `values` mode); what it cannot make safe is stated in
|
|
2384
|
+
[Remote objects](#remote-objects-johnhenrywshobjects-190): a getter or a setter on an allowed path runs, a called function does whatever it does with the page's authority, a wide pattern means its width, and a
|
|
2385
|
+
few paths (`document.cookie`, storage, `fetch`, ...) need an entry that names them. Object access is off on every host unless `exposeObjects` or `createPageHost({ expose })` is written, and `rpc:wsh-objects` is the key capability that gates it.
|
|
2061
2386
|
- **`wsh-mcp` runs as a client with your key (#127).** It reads a private key file you point it at (no passphrase support: protect the
|
|
2062
2387
|
file, `0600`), logs in as you and hands the MCP client everything the host's `mcp` channel serves; whatever the MCP client (or the
|
|
2063
2388
|
model behind it) asks of those tools is done as you. It does not pin the host unless you pass `--host-key` (it warns once on stderr),
|
|
@@ -2070,14 +2395,18 @@ out explicitly below rather than left to be discovered.
|
|
|
2070
2395
|
peers that connect to it. `bindAddr: '0.0.0.0'` (or an `allowBindAddrs` entry that does the same) puts that on every
|
|
2071
2396
|
interface of the host, so firewall it and keep `ports` narrow. The client sees each peer's address (`InboundOpen`) and
|
|
2072
2397
|
can reject it, but behind a NAT or proxy that address is not the real source. The Rust server's defaults are the
|
|
2073
|
-
same (loopback, off
|
|
2398
|
+
same (loopback, off, ports `0` and `1024-65535`, 4 listeners per client, 16 connections per listener, a backlog of
|
|
2399
|
+
8, a 5-minute idle limit): `reverse_ports`, `reverse_max_listeners`, `reverse_max_connections_per_listener`,
|
|
2400
|
+
`reverse_backlog` and `reverse_idle_secs` under `[gateway]`; the same applies to its UDP flows (`udp_*`).
|
|
2074
2401
|
- **UDP is not authenticated or private beyond the tunnel.** `allow: ['*']` with a public resolver lets every authorized
|
|
2075
2402
|
client send UDP to the internet from the host's address (a DNS-sized query, or a spoofed-looking flood limited only by
|
|
2076
2403
|
the packet rates above); the bounds make that slow, not impossible, and an origin that answers many large datagrams
|
|
2077
2404
|
to one small one is bounded by `bytesPerSecondPerClient`, not eliminated. WebTransport datagrams can be dropped,
|
|
2078
2405
|
reordered and duplicated by the network, and are only as private as the QUIC connection that carries them (a
|
|
2079
2406
|
datagram flow is not covered by E2E sealing, which is for sessions). A payload that did not fit a datagram travels on the
|
|
2080
|
-
reliable stream by default (see the README section above).
|
|
2407
|
+
reliable stream by default (see the README section above). On the Rust server a datagram is heard only after the
|
|
2408
|
+
connection has authenticated, for a flow that connection opened (an unknown or malformed one is dropped), and goes
|
|
2409
|
+
through the same per-flow, per-client and byte limits as a payload on the control stream.
|
|
2081
2410
|
|
|
2082
2411
|
- **What the gateway does NOT protect against.** A name that resolves to a *public* address is dialled as the client
|
|
2083
2412
|
asked, so `allow: ['*']` is an open proxy to the internet for every authorized client. Through `socks` the proxy
|
|
@@ -2126,6 +2455,16 @@ out explicitly below rather than left to be discovered.
|
|
|
2126
2455
|
populates `host_fingerprint`. `serverCertificateHashes` (below) is a
|
|
2127
2456
|
different, narrower mechanism -- it pins a certificate supplied *per
|
|
2128
2457
|
connection*, not a persisted record of what a host presented last time.
|
|
2458
|
+
- **The Rust client verifies the server's WebTransport certificate, and what that does and does not protect.** By
|
|
2459
|
+
default the certificate must chain to the system trust store; with `--cert-hash` it must be the pinned one (no
|
|
2460
|
+
authority involved); only `--insecure-skip-cert-verification` skips the check, with a warning on every connection.
|
|
2461
|
+
Verification stops an on-path party from terminating the connection as the server. It does not prove WHICH host a
|
|
2462
|
+
person is talking to beyond what the certificate names (a pin proves "this certificate", and `known_hosts` /
|
|
2463
|
+
`--host-key` prove the host's own key, which is a separate and stronger check), it does not cover the `wss://`
|
|
2464
|
+
fallback's `WSH_INSECURE_LOOPBACK_TLS` development variable (which now applies to loopback destinations only: it skips
|
|
2465
|
+
verification when the socket connected to 127.0.0.0/8 or `::1`, judged on the address reached and not on the name, and
|
|
2466
|
+
for any other destination it is ignored, with one line on stderr saying so), and a pinned certificate must be re-pinned when it is
|
|
2467
|
+
rotated (at most every 14 days). With the opt-out, a host that proves no key is not authenticated at all.
|
|
2129
2468
|
- **Password auth has no confidentiality of its own -- it relies entirely
|
|
2130
2469
|
on the transport.** `AUTH_METHOD.PASSWORD` sends the password as a plain
|
|
2131
2470
|
string inside the `auth` control message (`client.mjs`'s `#performAuth()`
|
|
@@ -2153,9 +2492,10 @@ position. From the Rust release after `rust-v0.6.0` the server's defaults are:
|
|
|
2153
2492
|
lists some. `"*"` means any *public* destination: an address that is loopback,
|
|
2154
2493
|
link-local (including `169.254.169.254`), private (RFC 1918), unique-local
|
|
2155
2494
|
(`fc00::/7`), carrier-grade NAT (`100.64.0.0/10`), unspecified or multicast is
|
|
2156
|
-
refused **after the name is resolved**, whichever rule matched the name
|
|
2157
|
-
a rule names that
|
|
2158
|
-
(`"10.1.0.0/16:5432"`, `"127.0.0.1:8080"
|
|
2495
|
+
refused **after the name is resolved**, whichever rule matched the name (a host
|
|
2496
|
+
name rule included), unless a rule names that address or range
|
|
2497
|
+
(`"10.1.0.0/16:5432"`, `"127.0.0.1:8080"`; a literal address is matched when a
|
|
2498
|
+
client asks for that address, a range also when a name resolves into it). The server connects to the address it
|
|
2159
2499
|
checked, so a name cannot pass the check as one address and connect as another.
|
|
2160
2500
|
`ResolveDns` follows the same rule and does not return internal answers.
|
|
2161
2501
|
- **Reverse listeners are off** (`enable_reverse_tunnels = false`) and, when on,
|
|
@@ -2173,10 +2513,13 @@ position. From the Rust release after `rust-v0.6.0` the server's defaults are:
|
|
|
2173
2513
|
|
|
2174
2514
|
What this does **not** protect against:
|
|
2175
2515
|
|
|
2176
|
-
- **A rule you write is trusted.** A hostname rule
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2516
|
+
- **A rule you write is trusted, as far as it says.** A hostname rule
|
|
2517
|
+
(`"partner.example.com"`) allows that name at a public address only, as the wildcard
|
|
2518
|
+
does: a name whose DNS answers an internal address is refused, so a name is not
|
|
2519
|
+
how the internal network is reached. An address range or literal address rule
|
|
2520
|
+
allows exactly what it says, so write `"10.1.2.3/32:5432"` to let `db.internal`
|
|
2521
|
+
resolve to that one address. It does not protect against a public address that
|
|
2522
|
+
forwards to something internal (a proxy, or a service you allow that fetches URLs).
|
|
2180
2523
|
- **It is not per-key.** Every authorized key gets the same gateway. A key that
|
|
2181
2524
|
should not have it should not be in `authorized_keys`.
|
|
2182
2525
|
- **There is no bandwidth or request-rate limit** beyond `max_connections`
|