@johnhenry/wsh 0.35.0 → 0.37.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 +453 -21
- package/package.json +18 -1
- package/src/bridge-seal.mjs +77 -0
- package/src/channel-binding.mjs +124 -0
- package/src/client.mjs +351 -62
- package/src/e2e-exchange.mjs +51 -1
- package/src/features.mjs +28 -0
- package/src/forward-node.mjs +118 -0
- package/src/gateway-channel.mjs +250 -0
- package/src/gateway-client.mjs +252 -0
- package/src/host-backends.mjs +100 -0
- package/src/host.d.ts +146 -0
- package/src/host.mjs +30 -0
- package/src/index.d.ts +114 -0
- package/src/index.mjs +13 -0
- package/src/memory-host.d.ts +34 -3
- package/src/memory-host.mjs +57 -13
- package/src/messages.gen.mjs +59 -7
- package/src/operator-proof.mjs +135 -0
- package/src/pipe-relay.d.ts +49 -0
- package/src/pipe-relay.mjs +274 -0
- package/src/reverse-host.d.ts +25 -0
- package/src/reverse-host.mjs +339 -0
- package/src/server/address-guard.mjs +164 -0
- package/src/server/backends.mjs +10 -16
- package/src/server/client-env.mjs +60 -0
- package/src/server/connection.mjs +100 -23
- package/src/server/constants.mjs +3 -0
- package/src/server/fs.mjs +2 -3
- package/src/server/gateway-core.mjs +188 -0
- package/src/server/gateway.mjs +483 -80
- package/src/server/index.d.ts +103 -5
- package/src/server/index.mjs +25 -4
- package/src/server/pty.mjs +1 -0
- package/src/server/relay.mjs +45 -2
- package/src/server/reverse-host.mjs +7 -213
- package/src/server/socket.mjs +25 -4
- package/src/server/unix-policy.mjs +120 -0
- package/src/server/webtransport.mjs +2 -0
- package/src/transport-ws.mjs +16 -0
- package/src/transport.mjs +11 -0
package/README.md
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
> Renamed to `@johnhenry/wsh` on import into the @johnhenry family. Unlike
|
|
5
5
|
> other packages in this family, wsh did **not** restart its version at
|
|
6
6
|
> `0.0.0` on adoption — it was already a mature, actively-depended-upon
|
|
7
|
-
> release, so versioning continued forward
|
|
8
|
-
>
|
|
9
|
-
> convention, not an
|
|
7
|
+
> release, so versioning continued forward from there (see
|
|
8
|
+
> [CHANGELOG.md](CHANGELOG.md) for the current version). This is a deliberate,
|
|
9
|
+
> permanent exception to the family's usual 0.0.0-restart convention, not an
|
|
10
|
+
> oversight.
|
|
10
11
|
|
|
11
12
|
[](https://www.npmjs.com/package/@johnhenry/wsh)
|
|
12
13
|
[](https://github.com/johnhenry/wsh/actions/workflows/ci.yml)
|
|
@@ -34,6 +35,8 @@ wsh is a pure-JS client library (with an optional Node server at `@johnhenry/wsh
|
|
|
34
35
|
- [Rust implementation](#rust-implementation)
|
|
35
36
|
- [Security model](#security-model)
|
|
36
37
|
- [Browser Compatibility](#browser-compatibility)
|
|
38
|
+
- [Browser tests and bundle size](#browser-tests-and-bundle-size)
|
|
39
|
+
- [Related projects](#related-projects)
|
|
37
40
|
- [Family](#family)
|
|
38
41
|
- [License](#license)
|
|
39
42
|
|
|
@@ -63,7 +66,7 @@ Or via CDN:
|
|
|
63
66
|
- **MCP bridge** -- discover and invoke remote MCP tools through the control channel
|
|
64
67
|
- **Session recording** -- own JSON schema (asciicast-v2-shaped, not a playable asciicast file -- see note below) recording and playback with seek/pause/resume
|
|
65
68
|
- **Key management** -- IndexedDB storage with OPFS encrypted backup (PBKDF2 + AES-256-GCM)
|
|
66
|
-
- **
|
|
69
|
+
- **105 message types** -- handshake, channel, gateway, guest sharing, compression negotiation, copilot, policy, authorized-key management, and more
|
|
67
70
|
|
|
68
71
|
> **Session recording is asciicast-v2-shaped, but not an asciicast file.**
|
|
69
72
|
> The JS `SessionRecorder.toJSON()` export borrows asciicast v2's vocabulary --
|
|
@@ -112,8 +115,10 @@ server implementations can speak the same framing.
|
|
|
112
115
|
```js
|
|
113
116
|
import { WshClient, generateKeyPair } from '@johnhenry/wsh';
|
|
114
117
|
|
|
115
|
-
// Generate an Ed25519 key pair
|
|
116
|
-
|
|
118
|
+
// Generate an Ed25519 key pair. Non-extractable (the default): this page's code can sign with the private key
|
|
119
|
+
// but nothing can read it out. Authorize it on the host by exporting the PUBLIC half
|
|
120
|
+
// (`exportPublicKeySSH(keyPair.publicKey)`); keep keys across reloads with `WshKeyStore`.
|
|
121
|
+
const keyPair = await generateKeyPair();
|
|
117
122
|
|
|
118
123
|
// Connect to a wsh server
|
|
119
124
|
const client = new WshClient();
|
|
@@ -153,7 +158,7 @@ await client.disconnect();
|
|
|
153
158
|
```js
|
|
154
159
|
import { WshClient, generateKeyPair } from '@johnhenry/wsh';
|
|
155
160
|
|
|
156
|
-
const keyPair = await generateKeyPair(
|
|
161
|
+
const keyPair = await generateKeyPair(); // non-extractable; see Quick Start
|
|
157
162
|
const { stdout, exitCode } = await WshClient.exec(
|
|
158
163
|
'wss://shell.example.com',
|
|
159
164
|
'ls -la /tmp',
|
|
@@ -224,12 +229,100 @@ restricted host with no shell. `fs.root` confines every path: `..`, absolute
|
|
|
224
229
|
paths and symlinks pointing out of it are refused -- for `write` and `rename`
|
|
225
230
|
(both paths) exactly as for `read`.
|
|
226
231
|
|
|
232
|
+
**Client environment (`clientEnv`).** A client may ask for environment
|
|
233
|
+
variables with `openSession({ env })`. Since 0.36 the host accepts only
|
|
234
|
+
`TERM`, `COLORTERM`, `LANG`, `LANGUAGE` and `LC_*` by default (the shape of
|
|
235
|
+
sshd's `AcceptEnv`); `PATH`, `LD_PRELOAD`, `BASH_ENV` and the like are dropped,
|
|
236
|
+
because they change what a shell or a restricted runner executes. Set
|
|
237
|
+
`exec: { clientEnv: true }` to accept everything (the old behaviour),
|
|
238
|
+
`false` for nothing, a list (`['TERM', 'LC_*', 'MY_APP_TOKEN']`, replacing the
|
|
239
|
+
default list) or a predicate `(name, value) => boolean`; `pty: { clientEnv }`
|
|
240
|
+
takes the same. At most 64 variables of at most 4096 bytes with plain names
|
|
241
|
+
are looked at. **This is a breaking default** for a host that relied on clients
|
|
242
|
+
setting arbitrary variables.
|
|
243
|
+
|
|
244
|
+
**Connection lifetime (`connectionTtlMs`).** `AuthOk` carries a `token` and a
|
|
245
|
+
`ttl`. The token is an opaque per-connection value that nothing accepts back
|
|
246
|
+
(session resume uses its own per-session token); it stays on the wire because
|
|
247
|
+
released clients require the field. `ttl` is now true: `connectionTtlMs: n`
|
|
248
|
+
ends every authenticated connection `n` ms after login and advertises it
|
|
249
|
+
(`client.authTtl`, whole seconds, rounded up); without it the host promises no
|
|
250
|
+
limit and sends `ttl: 0`. Before 0.36 it sent an unenforced 3600. The Rust
|
|
251
|
+
`wsh-server` still sends its `session_ttl` setting unenforced.
|
|
252
|
+
|
|
227
253
|
### Gateway (TCP and DNS egress from the host)
|
|
228
254
|
|
|
229
|
-
`gateway: { allow: ['broker.lan:1883'], socks: '127.0.0.1:9050' }` makes the Node server
|
|
230
|
-
client (a browser tab via netway's `GatewayBackend`) can open TCP
|
|
231
|
-
deny; `allow` takes `"*"`, `"host"` or `"host:port"`. `socks` routes
|
|
232
|
-
unresolved.
|
|
255
|
+
`gateway: { allow: ['broker.lan:1883'], allowPrivate: ['10.0.0.0/8'], socks: '127.0.0.1:9050' }` makes the Node server
|
|
256
|
+
answer the gateway opcodes, so a client (a browser tab via netway's `GatewayBackend`, or `client.openTcp()`) can open TCP
|
|
257
|
+
connections and resolve names from the host. Default deny; `allow` takes `"*"`, `"host"` or `"host:port"`. `socks` routes
|
|
258
|
+
every dial through a SOCKS5 proxy (Tor) with the name unresolved. TCP reverse tunnels are refused. `OpenUdp` is served
|
|
259
|
+
(`client.openUdp(host, port)`: one chunk is one datagram, same destination policy, idle flows closed after `udpIdleMs`,
|
|
260
|
+
default 60 s, not available through `socks`), but over the reliable control stream: it is ordered and retransmitted, and a
|
|
261
|
+
datagram the client cannot take fast enough is dropped by the host. **WebTransport datagrams (the real UDP semantics) are
|
|
262
|
+
not implemented yet (#124).**
|
|
263
|
+
|
|
264
|
+
**The address is checked, not just the name.** The host resolves a name once, refuses every resolved address that is not
|
|
265
|
+
globally routable (loopback, private, link-local, CGNAT, ULA, multicast, reserved, and IPv4 addresses wrapped as
|
|
266
|
+
IPv4-mapped, NAT64 or 6to4 IPv6), and connects to the address it checked, so a name that resolves to something else a
|
|
267
|
+
moment later cannot redirect the connection. Reaching private space is an explicit rule: `allowPrivate` (CIDR blocks or
|
|
268
|
+
addresses) for names and `"*"`, or an `allow` entry that is itself an IP literal (`"127.0.0.1:1883"`), which permits
|
|
269
|
+
exactly that address. `ResolveDns` answers are filtered with the same rule. Through `socks` the proxy resolves the name,
|
|
270
|
+
so only IP literals can be checked there. See the Security model below and the CHANGELOG (this is a behaviour change).
|
|
271
|
+
|
|
272
|
+
**Flow control.** Gateway data is metered in both directions when both ends offer the `gateway-credit` feature: each
|
|
273
|
+
direction of each connection starts with 256 KiB of credit that the receiver tops up (`GatewayCredit`) as its
|
|
274
|
+
application consumes data, so a slow reader stops its peer (the origin socket is paused, `write()` results and `drain`
|
|
275
|
+
are honoured) instead of making the host buffer. Against a peer without the feature the host still holds the origin back
|
|
276
|
+
by the transport's own backpressure and bounds what a client can make it hold with `maxBufferedBytes` (default 4 MiB per
|
|
277
|
+
connection) and `maxClientBufferedBytes` (default 32 MiB per client), closing a connection that exceeds them.
|
|
278
|
+
|
|
279
|
+
#### Unix-domain sockets (streamlocal) and named endpoints
|
|
280
|
+
|
|
281
|
+
Modelled on OpenSSH's streamlocal forwarding. Off unless configured:
|
|
282
|
+
|
|
283
|
+
```js
|
|
284
|
+
createWshServer({ auth, gateway: {
|
|
285
|
+
allow: [],
|
|
286
|
+
unix: {
|
|
287
|
+
connect: ['/var/run/docker.sock'], // OpenUnix: a client may connect to these (exact path, or "/dir/" prefix, or "@abstract")
|
|
288
|
+
listen: ['/run/user/1000/wsh/'], // ListenUnix: a client may ask the host to create sockets under here
|
|
289
|
+
replaceStale: false, // a client may replace a STALE socket file only if it asks AND this is true
|
|
290
|
+
},
|
|
291
|
+
endpoints: { ping: async (duplex, who) => { /* ... */ } }, // named virtual endpoints, below
|
|
292
|
+
} });
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Paths are checked after `realpath` of the parent directory (so `/var/run` and `/private/var/run` agree and a symlinked
|
|
296
|
+
directory cannot lead out of an allowed one), a `..` segment is refused, and the file must be a socket and not a symlink.
|
|
297
|
+
The abstract namespace (`@name`) is refused unless listed. Sockets the host creates are mode `0600` (the umask is
|
|
298
|
+
tightened while binding) and are unlinked when the listener closes or the connection ends; an existing socket file is
|
|
299
|
+
replaced only when the request says `replace` AND `replaceStale` is on AND nothing accepts connections on it, and a file
|
|
300
|
+
that is not a socket is never touched. Allow only directories no other local user can write to: the check cannot close
|
|
301
|
+
the instant between it and the connect.
|
|
302
|
+
|
|
303
|
+
```js
|
|
304
|
+
const duplex = await client.openUnix('/var/run/docker.sock'); // web streams with backpressure
|
|
305
|
+
await duplex.writable.getWriter().write(new TextEncoder().encode('GET /containers/json HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n'));
|
|
306
|
+
// Node: ssh -L / -R shapes, unix and TCP ends mixed
|
|
307
|
+
await client.forwardUnix({ local: '127.0.0.1:2375', remote: '/var/run/docker.sock' }); // -L 127.0.0.1:2375:/var/run/docker.sock
|
|
308
|
+
await client.forwardUnix({ local: '/tmp/docker.sock', remote: '/var/run/docker.sock' });
|
|
309
|
+
await client.forwardUnix({ reverse: true, remote: '/run/user/1000/wsh/app.sock', local: '127.0.0.1:8080' }); // -R
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
**Named virtual endpoints** are for a host with no file system (the memory host, a browser tab):
|
|
313
|
+
`endpoints: { docker: (duplex, who) => ... }` registers handlers and a client reaches one with `client.openEndpoint('docker')`.
|
|
314
|
+
It is its own message (`OpenEndpoint { name }`) rather than a reserved `OpenUnix` path so that a name can never be
|
|
315
|
+
mistaken for (or smuggled as) a file-system path or an abstract-namespace name, and so a host's file-system policy is not
|
|
316
|
+
consulted for it; the registered names are an allow-list by construction. `who` is the authenticated
|
|
317
|
+
`{ username, fingerprint }`, so the embedder can authorise per call (throw to refuse, or `{ open, authorize(who) }`).
|
|
318
|
+
|
|
319
|
+
**Rust side: JS only for now.** `wsh-server` does not advertise `gateway-unix`, `gateway-endpoints` or `gateway-credit`,
|
|
320
|
+
and `wsh` has no `-L` / `-R` with unix sockets yet. What it must implement: `OpenUnix { gateway_id, path }` and
|
|
321
|
+
`ListenUnix { listener_id, path, replace? }` (answer with the existing `GatewayOk`/`GatewayFail` and `ListenOk` with
|
|
322
|
+
`actual_port: 0`/`ListenFail`; accepted connections announced with `InboundOpen` and answered by `InboundAccept`'s
|
|
323
|
+
`gateway_id`), the same path policy and `0600`/unlink rules, `GatewayCredit` (256 KiB initial credit per direction when
|
|
324
|
+
the client's `Hello.features` lists `gateway-credit`), and in the CLI `-L [bind:]port:/remote.sock`,
|
|
325
|
+
`-L /local.sock:/remote.sock`, `-R /remote.sock:host:port` and `-R /remote.sock:/local.sock`.
|
|
233
326
|
|
|
234
327
|
### TLS (`wss://`) and host extensions
|
|
235
328
|
|
|
@@ -274,9 +367,35 @@ session.onData = (d) => console.log(new TextDecoder().decode(d)); // "ran hi"
|
|
|
274
367
|
|
|
275
368
|
It is the real connection handler speaking QMux over an in-memory socket pair, so the client code you test is the code
|
|
276
369
|
you ship. `host.createClient()` / `host.WebSocket` / `host.accept(socket)` / `createSocketPair()` are the lower-level pieces.
|
|
277
|
-
Supported: `auth`, `exec` (a function; there is no shell), `
|
|
278
|
-
|
|
279
|
-
|
|
370
|
+
Supported: `auth`, `exec` (a function; there is no shell), `pty`, `fs` and `hostKey` (injected, below), `mcp`,
|
|
371
|
+
`extensions`, `rpc`, `sessions` (below) and `endpoints` ([named virtual endpoints](#unix-domain-sockets-streamlocal-and-named-endpoints):
|
|
372
|
+
`endpoints: { api: (duplex, who) => ... }`, reached with `client.openEndpoint('api')`, with flow control). Not available
|
|
373
|
+
in memory: the TCP, DNS, UDP and unix-socket parts of `gateway`, `relay`, WebTransport, `exec: true` and
|
|
374
|
+
`fs: { root }` (they need Node) and the `wsh-host` / `wsh-fs` rpc built-ins (use `@johnhenry/wsh/server`).
|
|
375
|
+
|
|
376
|
+
**Injected backends**, shaped like the Node host's, so a page can be a real host (#114):
|
|
377
|
+
|
|
378
|
+
- `pty: { spawn, shell?, cwd?, env?, term? }` -- `spawn` is `node-pty`'s `spawn(file, args, { name, cols, rows, cwd, env })`
|
|
379
|
+
or anything shaped like it, returning `{ onData(cb), onExit(cb), write(data), resize(cols, rows), kill(signal?) }`.
|
|
380
|
+
`write` receives a `Uint8Array` (there is no `Buffer` in a browser, and none is needed anywhere in the host). `shell` is
|
|
381
|
+
the `file` your `spawn` is called with (default `/bin/sh`).
|
|
382
|
+
- `fs: { operate, readWhole, writeWhole, writeAt, openRange?, maxFileBytes? }` -- an object of operations, **not** a root path
|
|
383
|
+
(`fs: { root }` needs Node and is refused here). The types are `WshFileBackend` in `@johnhenry/wsh/host`; the file
|
|
384
|
+
operations (`list`, `stat`, `read`, `write`, `rename`, `mkdir`, `remove`) reach `operate` with the path exactly as the
|
|
385
|
+
client sent it, so **confining paths is the backend's job** -- see [Security model](#security-model).
|
|
386
|
+
- `hostKey` -- a `CryptoKeyPair` (generate it with `generateKeyPair()` and the private key stays non-extractable), a signer
|
|
387
|
+
`{ publicKey, sign(data) }` for a key held elsewhere, or `true` for a fresh non-extractable key. Clients pin it as for
|
|
388
|
+
any host ([Host key](#host-key-fingerprint--tofu)); the proof is signed through `sign`, so the key never has to be readable.
|
|
389
|
+
- `dataStreams` (default `true`) -- whether to offer client-opened QMux data streams. **Set it to `false` for a peer that
|
|
390
|
+
cannot open them: the released Rust client over WebSocket** (`wsh`, `rust-v0.6.0`: "WebSocket transport does not support
|
|
391
|
+
real data streams for this server", #132). Exec output then rides `SessionData` (`data_mode: "virtual"`, as over a relay
|
|
392
|
+
bridge) and `stream-announce` and `rpc` are not offered. It is an option rather than a negotiation because no released
|
|
393
|
+
client says whether it can open streams: the Rust client's `Hello` carries only `mcp` and `file-transfer`. The JS client works
|
|
394
|
+
either way. `host.accept(socket, { dataStreams })` overrides it per connection.
|
|
395
|
+
|
|
396
|
+
**Serving a socket you opened yourself:** `host.accept(new WebSocket(url))` works on a socket that is still connecting (the
|
|
397
|
+
host's first bytes are held until it opens). `accept()` of an in-page host through a relay or a byte pipe is what the
|
|
398
|
+
[browser suite](#browser-tests-and-bundle-size) runs against the released Rust CLI.
|
|
280
399
|
|
|
281
400
|
**`rpc`** takes handler functions only, `rpc: { calc: (channel, ctx) => channel.onRequest('add', ({ a, b }) => a + b) }`
|
|
282
401
|
(the `RpcChannel` is the one `@johnhenry/wsh/server` hands its handlers), with `rpcMaxMessageBytes` (default 1 MiB) and
|
|
@@ -288,10 +407,39 @@ messages, `seq` counted in output bytes, and the same errors (unknown or expired
|
|
|
288
407
|
of the session, an output gap). The limits and defaults are the server's: 300000 ms detached before a session is
|
|
289
408
|
dropped, at most 16 detached sessions (the longest-detached is dropped first), 1 MiB of replayable output per session
|
|
290
409
|
(a resume older than the ring is refused as a gap; `attachSession` gets the retained tail). The session list lives in
|
|
291
|
-
the page's memory, so it ends with the page or `host.close()`. Differences from the server: no `
|
|
292
|
-
`sessionSecret` (tokens are random per session instead of HMAC-signed, so they cannot be checked across restarts), and
|
|
410
|
+
the page's memory, so it ends with the page or `host.close()`. Differences from the server: no `sessionSecret` (tokens are random per session instead of HMAC-signed, so they cannot be checked across restarts), and
|
|
293
411
|
the host still runs no command by itself: sessions only wrap whatever `exec` function you pass.
|
|
294
412
|
|
|
413
|
+
### Browser entry points, the connection factory and bundle size
|
|
414
|
+
|
|
415
|
+
Every `exports` entry except `./server` is browser-safe: no `node:*` import and no `Buffer` is reachable from it (a test
|
|
416
|
+
bundles each one for the browser and fails if one is, `test/browser-bundle.test.mjs`), and `"sideEffects": false` lets a
|
|
417
|
+
bundler drop what you do not use.
|
|
418
|
+
|
|
419
|
+
| Entry | What it is |
|
|
420
|
+
|---|---|
|
|
421
|
+
| `@johnhenry/wsh` | the client (`WshClient`, `WshKeyStore`, ...) |
|
|
422
|
+
| `@johnhenry/wsh/memory` | `createMemoryHost()`, a host in this realm (above) |
|
|
423
|
+
| `@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 |
|
|
424
|
+
| `@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 }` |
|
|
425
|
+
| `@johnhenry/wsh/server` | Node only |
|
|
426
|
+
|
|
427
|
+
```js
|
|
428
|
+
import { createConnectionFactory, bindSocket, resolveBackends, buildAuthorizer, authMethods } from '@johnhenry/wsh/host';
|
|
429
|
+
|
|
430
|
+
const auth = { authorizedKeys: [rawPublicKey] };
|
|
431
|
+
const attach = createConnectionFactory({ // authorize is required: there is no open default
|
|
432
|
+
authorize: await buildAuthorizer(auth), methods: authMethods(auth),
|
|
433
|
+
...resolveBackends({ exec: async (command, io) => { await io.write('hi\n'); return 0; } }),
|
|
434
|
+
});
|
|
435
|
+
await bindSocket(upgradedSocket, Promise.resolve(attach), { dataStreams: false }); // or attach({ send, ... }) on a byte pipe
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
`npm run size` prints raw and gzip bytes per entry point (and a few single-import probes, which show tree-shaking at
|
|
439
|
+
work) against `scripts/bundle-budget.json`; CI runs it and `npm test` fails a bundle more than 10% over its budget.
|
|
440
|
+
`npm run size -- --update` rewrites the budget after a deliberate change. Sizes are of this package's own code:
|
|
441
|
+
`@noble/post-quantum`, the optional ML-KEM backend, is left out of the measurement.
|
|
442
|
+
|
|
295
443
|
### Signing with a page-held signer
|
|
296
444
|
|
|
297
445
|
`connect()`, `WshClient.exec()` and `connectReverse()` take `signer: { publicKey, sign(data) }` instead of `keyPair`
|
|
@@ -549,6 +697,101 @@ const s = await client.openSession({ type: 'exec', command: 'echo hello' });
|
|
|
549
697
|
there): against such a relay or operator, set `reportFeatures: false` on the
|
|
550
698
|
host (and use `ReverseAccept` without the field in your own peers).
|
|
551
699
|
|
|
700
|
+
#### Operator proof and sealed bridges (#117)
|
|
701
|
+
|
|
702
|
+
Out of the box the relay tells the host who the operator is (`from_fingerprint`,
|
|
703
|
+
set from the operator's login at the relay) and the host's `accept` trusts it:
|
|
704
|
+
fine for a relay you run, not for a shared one. Two opt-ins close that, and both
|
|
705
|
+
are negotiated by feature strings so every released peer keeps working
|
|
706
|
+
(the Rust relay never lists `operator-proof`, so the operator simply does not
|
|
707
|
+
offer it there):
|
|
708
|
+
|
|
709
|
+
```js
|
|
710
|
+
// host: do not take the operator's identity from the relay.
|
|
711
|
+
createReverseHost({ url, username, keyPair, exec: true,
|
|
712
|
+
requireOperatorProof: true,
|
|
713
|
+
accept: ({ fingerprint, username, proven, publicKey }) => fingerprint === aliceFingerprint });
|
|
714
|
+
// operator: prove yourself, and seal the bridge (nothing naming a command is sent before the key exists).
|
|
715
|
+
await client.reverseConnect(hostFingerprint, 10_000, { sealed: true, requirePeerProof: true });
|
|
716
|
+
```
|
|
717
|
+
|
|
718
|
+
1. **Operator proof.** After `ReverseConnect` the host sends a signed
|
|
719
|
+
`ReverseChallenge` (its key, the operator fingerprint it saw, a nonce it chose and a
|
|
720
|
+
session id); the operator checks the host's signature, that the key is the host it asked for and that
|
|
721
|
+
the host saw the operator's *own* fingerprint (so a relay that rewrote `from_fingerprint` shows
|
|
722
|
+
up here), and answers with a `ReverseProof`: an Ed25519 signature over the host's key, its own key, the
|
|
723
|
+
username it claims, and the host's nonce and session id. The host verifies it **before `accept` runs**, takes
|
|
724
|
+
the identity from the proof and refuses when it differs from what the relay asserted. `accept` receives
|
|
725
|
+
`{ fingerprint, username, proven, publicKey }`; by default the proof is requested whenever the relay
|
|
726
|
+
and operator can do it and merely *reported* (`proven`).
|
|
727
|
+
2. **Sealed bridge.** A proof is a point in time, and a relay can stamp any
|
|
728
|
+
`from_fingerprint` on a plain message afterwards (an injected `Open`), so a host with
|
|
729
|
+
`requireOperatorProof` also requires the bridge to be sealed: the operator opens it with a
|
|
730
|
+
`KeyExchange` that **both** sides sign (the operator's half covers the session id, algorithm, its
|
|
731
|
+
ephemeral key and the host's identity; the host's reply covers both ephemeral keys), hybrid
|
|
732
|
+
X25519+ML-KEM-768 by default, and from then on every message that would cross the relay (`Open`, `OpenOk`,
|
|
733
|
+
`SessionData`, `FileOp`, `McpCall` ...) travels as an `EncryptedFrame` on channel 0 with a strict counter.
|
|
734
|
+
The host acts on nothing else. The only plaintext before the key exists is the key exchange itself (ephemeral
|
|
735
|
+
public keys, signatures); before this change `Open` -- the command, the environment, the working size --
|
|
736
|
+
and `OpenOk` with its resume token crossed the relay in the clear until a per-session `initiateE2E`.
|
|
737
|
+
|
|
738
|
+
What a relay can and cannot do, with and without these (a relay always sees who connects to whom, when, and how
|
|
739
|
+
many bytes):
|
|
740
|
+
|
|
741
|
+
| The relay can ... | Plain bridge (default) | + operator proof | + `requireOperatorProof` (sealed) |
|
|
742
|
+
|---|---|---|---|
|
|
743
|
+
| read commands, output, files, MCP calls | yes, until a per-session `initiateE2E` | yes | **no** (ciphertext; metadata and sizes only) |
|
|
744
|
+
| make the host think an operator it chose is connecting | yes (it stamps `from_fingerprint`) | **no**: the host verifies the operator's own signature before `accept` | no |
|
|
745
|
+
| replay an old operator's login to the host | n/a | **no**: the nonce is the host's, single use, signed over the host's key and the session | no |
|
|
746
|
+
| swap the operator's key or the host's ephemeral key | n/a | no (signature does not verify) | no (both halves are signed) |
|
|
747
|
+
| inject an `Open` / `SessionData` stamped as the operator | **yes** | **yes** (a proof is a point in time) | **no** (plain messages are dropped) |
|
|
748
|
+
| replay or reorder a sealed frame | n/a | n/a | **no** (strict counter and role tag) |
|
|
749
|
+
| drop, delay or truncate traffic, or end the bridge | yes | yes | yes (a denial of service is always open to a relay) |
|
|
750
|
+
| tell the host the operator is *absent* when it is present (`ReverseClose`) | yes | yes | yes |
|
|
751
|
+
| learn the operator's and host's keys, usernames, and the sizes and timing of traffic | yes | yes | yes |
|
|
752
|
+
|
|
753
|
+
Not covered: an operator or host that skips the checks (the options are opt-in on both
|
|
754
|
+
sides; a host that does not require proof is exactly as exposed as before), the Rust `wsh-server` relay and
|
|
755
|
+
`wsh` client (they neither carry nor send these messages), and a compromised *operator* key (it proves the key, not the
|
|
756
|
+
person). A relay can still refuse service by dropping the challenge.
|
|
757
|
+
|
|
758
|
+
#### A pipe relay (`@johnhenry/wsh/pipe-relay`, #118)
|
|
759
|
+
|
|
760
|
+
When you do not want the relay to be a party at all, use a pipe: the host dials the relay, the operator dials the
|
|
761
|
+
relay, the relay matches them by an unguessable rendezvous id and copies bytes. **There is no relay-asserted identity**:
|
|
762
|
+
the host runs the ordinary handshake and verifies the operator's own signature (`authorize`, `authorizedKeys`,
|
|
763
|
+
channel binding, ...) exactly as on a direct connection, and the operator can pin the host key.
|
|
764
|
+
|
|
765
|
+
```js
|
|
766
|
+
import { createPipeRelay, newRendezvousId, pipeUrl } from '@johnhenry/wsh/pipe-relay';
|
|
767
|
+
const relay = createPipeRelay({ idleTimeoutMs: 300_000, maxWaiting: 1024 });
|
|
768
|
+
const { port } = await relay.listen({ port: 8443 }); // or relay.accept(socket, { id, role }) from your own HTTP server
|
|
769
|
+
|
|
770
|
+
const id = newRendezvousId(); // 128 bits; hand it to both sides out of band
|
|
771
|
+
// host (behind NAT): dial out, wait for the socket to open, serve it like any accepted connection
|
|
772
|
+
const ws = new WebSocket(pipeUrl('wss://relay.example', id, 'host'));
|
|
773
|
+
await new Promise((r) => ws.addEventListener('open', r, { once: true }));
|
|
774
|
+
await server.accept(ws); // createWshServer / createMemoryHost
|
|
775
|
+
// operator: the stock client, any URL form
|
|
776
|
+
await client.connect(pipeUrl('wss://relay.example', id), { username, keyPair, expectHostKey });
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
The module imports nothing that can execute code or read files (a test walks its module graph); it does not parse wsh.
|
|
780
|
+
Bounds, all with defaults: `maxWaiting`, `rendezvousTimeoutMs`, `idleTimeoutMs`, `maxLifetimeMs`, `maxBytes`,
|
|
781
|
+
`maxMessageBytes`, `earlyBytes`, `highWaterBytes` (a receiver that is not draining pauses the sender; a socket that
|
|
782
|
+
cannot pause is closed). **Trust difference:** relay mode has the relay vouch for the operator; a pipe relay vouches
|
|
783
|
+
for nothing, and the rendezvous id is the only thing standing between the host's socket and whoever dials first --
|
|
784
|
+
an impostor that reaches the id first is still a stranger to the operator, who must pin the host key
|
|
785
|
+
(`expectHostKey`) to notice; and the host still authenticates every operator. A pipe relay terminates the TLS of each leg, so what it copies -- the wsh
|
|
786
|
+
handshake and the session traffic -- is readable by it unless the two ends seal it themselves
|
|
787
|
+
(per-session `initiateE2E`); it cannot forge the operator's signature or the host's. It can drop, delay or
|
|
788
|
+
cut a connection, and it sees who dials which id and how much they send.
|
|
789
|
+
|
|
790
|
+
*CLI side (not built here).* The Rust `wsh` client always dials `wss://<host>/` (#136), so it cannot dial
|
|
791
|
+
`/r/<id>` yet. It needs either `wsh --via wss://relay/r/<id> user@host`, or to keep the URL path and query it is
|
|
792
|
+
given; the JS client already does. The host side is any process that can open a WebSocket to `pipeUrl(..., 'host')`
|
|
793
|
+
and hand it to `accept`.
|
|
794
|
+
|
|
552
795
|
### Sessions: attach / resume / detach
|
|
553
796
|
|
|
554
797
|
By default a pty/exec session dies with the connection that opened it. Pass
|
|
@@ -742,6 +985,41 @@ client.onHostKey = (hk) => confirm(`Trust ${hk.fingerprint}?`); // or per call
|
|
|
742
985
|
ServerHello and then read or alter the rest. Pinning keeps you from talking
|
|
743
986
|
to the wrong host; confidentiality still needs `wss://` or a link you trust.
|
|
744
987
|
|
|
988
|
+
### Channel binding (tie the login to the connection)
|
|
989
|
+
|
|
990
|
+
A host key proves who the host is; it does not stop an intermediary from
|
|
991
|
+
passing a genuine challenge through to the host and getting your login
|
|
992
|
+
signature back. With binding, the signature also covers what the two ends of
|
|
993
|
+
*this* connection share, so a relayed signature is worthless to the host:
|
|
994
|
+
|
|
995
|
+
```js
|
|
996
|
+
// host: accept a key login only when it is bound (requires hostKey for `host`; wss served by this process for `tls-exporter`)
|
|
997
|
+
createWshServer({ auth, hostKey: { file }, requireChannelBinding: true }); // or ['host', 'tls-exporter']
|
|
998
|
+
// client: refuse to sign a login that cannot be bound
|
|
999
|
+
await client.connect(url, { username, keyPair, requireChannelBinding: true });
|
|
1000
|
+
client.channelBinding; // ['host'] -- which kinds this login's signature covered
|
|
1001
|
+
```
|
|
1002
|
+
|
|
1003
|
+
| Kind | Bound to | Who can supply it |
|
|
1004
|
+
|---|---|---|
|
|
1005
|
+
| `host` | the Ed25519 host key that proved possession in `ServerHello` | a host with `hostKey`; any client that checked the proof (so a relay presenting its own key binds to *its* key) |
|
|
1006
|
+
| `cert-hash` | the SHA-256 of the pinned WebTransport certificate | a `selfSigned` WebTransport host; a client with exactly one `serverCertificateHashes` entry |
|
|
1007
|
+
| `tls-exporter` | 32 bytes of TLS keying material (RFC 5705/8446, label `EXPORTER-wsh-channel-binding`) | Node on both ends over `wss://` served by the process itself (the client must use the `ws` package, e.g. `new WebSocketTransport({ WebSocket })`; Node's global `WebSocket` and every browser expose no exporter) |
|
|
1008
|
+
|
|
1009
|
+
It is negotiated with feature strings (`channel-binding:<kind>`,
|
|
1010
|
+
`channel-binding-required`), so released clients and hosts keep working: a
|
|
1011
|
+
host that does not require binding still accepts an unbound login, and a
|
|
1012
|
+
client binds whatever the host offers. A host that requires it refuses an
|
|
1013
|
+
unbound signature with a reason. **What it does not do:** it protects only
|
|
1014
|
+
what you require. An intermediary that strips the host's offer gets an unbound
|
|
1015
|
+
signature from a client that did not set `requireChannelBinding`, and a host
|
|
1016
|
+
that does not require binding accepts it -- set the option on whichever side
|
|
1017
|
+
you control (a host protects every client; a client protects itself).
|
|
1018
|
+
`tls-exporter` fails behind a TLS-terminating proxy by design. Password logins
|
|
1019
|
+
are not bound (nothing is signed). The Rust `wsh-server` and `wsh` CLI do not
|
|
1020
|
+
offer or compute a binding yet, so against them a client with
|
|
1021
|
+
`requireChannelBinding` refuses to log in.
|
|
1022
|
+
|
|
745
1023
|
### Password auth
|
|
746
1024
|
|
|
747
1025
|
```js
|
|
@@ -1064,7 +1342,7 @@ so options the platform gains later need no change here.
|
|
|
1064
1342
|
|
|
1065
1343
|
| Export | Description |
|
|
1066
1344
|
|--------|-------------|
|
|
1067
|
-
| `MSG` |
|
|
1345
|
+
| `MSG` | 105 message type constants (hex opcodes) |
|
|
1068
1346
|
| `CHANNEL_KIND` | Channel types: `pty`, `exec`, `meta`, `file`, `tcp`, `udp`, `job` |
|
|
1069
1347
|
| `AUTH_METHOD` | Auth methods: `pubkey`, `password` |
|
|
1070
1348
|
| `cborEncode` / `cborDecode` | CBOR codec (maps, arrays, strings, ints, bytes, bools, null, floats) |
|
|
@@ -1088,7 +1366,7 @@ instead of dragging its own toolchain and CI job into an unrelated
|
|
|
1088
1366
|
browser-app repo. It was previously deleted from clawser by accident
|
|
1089
1367
|
(2026-03-14) and restored (2026-07-05) before this move.
|
|
1090
1368
|
|
|
1091
|
-
Four crates, workspace-versioned (currently `0.
|
|
1369
|
+
Four crates, workspace-versioned (currently `0.7.0`):
|
|
1092
1370
|
|
|
1093
1371
|
| Crate | Kind | Description |
|
|
1094
1372
|
|-------|------|--------------|
|
|
@@ -1097,6 +1375,22 @@ Four crates, workspace-versioned (currently `0.5.0`):
|
|
|
1097
1375
|
| `wsh-cli` | binary (`wsh`) | SSH-like CLI: connect, exec, scp-style copy, reverse tunnels, key management |
|
|
1098
1376
|
| `wsh-server` | binary (`wsh-server`) | Server: WebTransport/WebSocket listener, real PTY sessions (`portable-pty`), relay/reverse-connect, WISP bridging |
|
|
1099
1377
|
|
|
1378
|
+
### Running a command with `wsh`
|
|
1379
|
+
|
|
1380
|
+
```sh
|
|
1381
|
+
wsh alice@host ls -l # dials https://host:4422, then wss://host:4422
|
|
1382
|
+
wsh -t ws -p 8443 alice@host ls -l # wss:// only, on port 8443
|
|
1383
|
+
wsh wss://host:8443/rendezvous/ab12 ls -l # a full URL, dialled exactly as written (path and query kept)
|
|
1384
|
+
printf 'a\nb\n' | wsh alice@host sort # stdin is forwarded; its end reaches the command as EOF
|
|
1385
|
+
wsh --tty alice@host top # a terminal for the command: raw keys, resizes forwarded
|
|
1386
|
+
```
|
|
1387
|
+
|
|
1388
|
+
stdout and stderr stay separate where the host offers `exec-pipes`; the exit status is the command's.
|
|
1389
|
+
SIGINT, SIGTERM and SIGHUP sent to `wsh` are forwarded to the command, and the same signal twice
|
|
1390
|
+
disconnects. `wsh connect` ends when the remote session does. Diagnostics go to stderr (`-v` for more),
|
|
1391
|
+
never into the command's stdout. TLS uses the platform trust store, and `SSL_CERT_FILE` points it at another certificate (how a self-signed host is trusted); a plain
|
|
1392
|
+
`ws://` URL is accepted only for a loopback host.
|
|
1393
|
+
|
|
1100
1394
|
### Capability matrix: JS SDK vs Rust CLI/client
|
|
1101
1395
|
|
|
1102
1396
|
Two implementations of one protocol will always have *some* asymmetry --
|
|
@@ -1112,11 +1406,22 @@ than left to be found.
|
|
|
1112
1406
|
| 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 |
|
|
1113
1407
|
| Host identity / TOFU | `WshKnownHosts` (localStorage-backed) | `KnownHosts`/`HostStatus` (`~/.wsh/known_hosts`-backed) | **Record unified, policy is not** (wsh #59): both pin `ServerHello.host_fingerprint`, which `@johnhenry/wsh/server` populates (with a proof of possession, [Host key](#host-key-fingerprint--tofu)) but no Rust `wsh-server` release does yet (see [Security](#security-model)). *When* to trust, prompt, or persist is deliberately left per-implementation -- a browser and a CLI have different UX for "first time seeing this host" |
|
|
1114
1408
|
| 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; no client yet in `wsh-client` | **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 |
|
|
1115
|
-
| Exec stdin + EOF, separate stderr | `exec({ stdin })`, `session.closeStdin()`, `session.onStderr` |
|
|
1409
|
+
| 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 |
|
|
1410
|
+
| 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`). **Not everywhere honoured**: the Rust `wsh-server` currently only logs `Signal`, so a forwarded signal does not stop the command there |
|
|
1411
|
+
| 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 |
|
|
1412
|
+
| 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. Its `scp` download also reads a raw stream, not the `FileChunk` messages this host sends, so `wsh scp` from such a host does not work (`wsh ls` and exec do) |
|
|
1116
1413
|
| 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 |
|
|
1117
1414
|
| 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) |
|
|
1118
1415
|
| 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 and the signed `KeyExchange` are JS-relay only for now |
|
|
1119
1416
|
| 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 |
|
|
1417
|
+
| 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 })` | none yet (`wsh -L` / `-R` with sockets are not implemented) | **JS only for now.** Wire: `OpenUnix`, `OpenEndpoint`, `ListenUnix` behind the `gateway-unix` / `gateway-endpoints` host features; the Rust server and CLI must implement them (message handling, the path policy, `-L`/`-R` flags) as described under [Gateway](#unix-domain-sockets-streamlocal-and-named-endpoints) |
|
|
1418
|
+
| Gateway flow control (#123) | credit per connection (`GatewayCredit`, feature `gateway-credit`); host caps for peers without it | none: the Rust forwarder has bounded in-process queues but no per-connection credit and no per-client byte cap | **JS only for now** (negotiated, so a Rust peer on either side keeps today's unmetered behaviour) |
|
|
1419
|
+
| 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) |
|
|
1420
|
+
| Operator proof to the peer, sealed bridge, signed initiator half (#117) | `reverseConnect(.., { sealed, requirePeerProof })`; host `createReverseHost({ requireOperatorProof })`; relay lists `operator-proof` | none: the Rust relay neither carries `ReverseChallenge`/`ReverseProof` nor lists the feature, and the Rust agent/client send and answer neither | **Wire-unified, negotiated** (`ReverseConnect.features`, `operator-proof`, `e2e-sealed`); the Rust types are regenerated (and `ReverseConnect.features` is `None` there) but no Rust peer implements it yet |
|
|
1421
|
+
| Channel binding of the login signature (#119) | `requireChannelBinding` (client and server); kinds `host`, `cert-hash`, `tls-exporter` | none: no Rust host offers one and the Rust client signs with an empty binding | **Wire-unified, negotiated** (`channel-binding:<kind>` features); a Rust client logging in to a JS host that requires it is refused |
|
|
1422
|
+
| Pipe relay (#118) | `@johnhenry/wsh/pipe-relay` | none; the `wsh` CLI always dials `wss://<host>/` (#136), so it cannot reach `/r/<id>` -- it needs `--via` or to keep the URL path | **Deliberately a relay without wsh parsing** -- nothing to unify on the wire |
|
|
1423
|
+
| `AuthOk.ttl` enforced, `token` opaque (#125) | `connectionTtlMs`; `client.authTtl` | `wsh-server` sends `session_ttl` (default 86400) and an HMAC token, neither enforced or checked | **Wire-compatible**: both fields are still sent (released peers require them); the JS host sends `ttl: 0` unless a limit is set |
|
|
1424
|
+
| `clientEnv` allow-list (#126) | default `TERM`, `COLORTERM`, `LANG`, `LANGUAGE`, `LC_*` | the Rust server applies whatever environment the client sends | **JS host only**; wire unchanged |
|
|
1120
1425
|
| 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 |
|
|
1121
1426
|
| Self-signed cert pinning | `serverCertificateHashes` (WebTransport option) | N/A -- Rust dials a cert its own TLS stack already trusts, or `--generate-cert`'s self-signed cert out of band | **Deliberately not unified** -- this is a browser-specific WebTransport API shape, not a wire-protocol concept |
|
|
1122
1427
|
|
|
@@ -1186,7 +1491,28 @@ out explicitly below rather than left to be discovered.
|
|
|
1186
1491
|
- **Auth transcript binding.** Challenge signatures cover
|
|
1187
1492
|
`SHA-256("wsh-v1\0" || lp(username) || lp(session_id) || nonce || channel_binding)`,
|
|
1188
1493
|
so a signature can't be replayed against a different session or relabeled
|
|
1189
|
-
to a different username.
|
|
1494
|
+
to a different username. `channel_binding` is empty unless both ends agree
|
|
1495
|
+
on one (wsh #119): then it also names the connection (host key, pinned
|
|
1496
|
+
certificate, TLS exporter), so a relaying intermediary cannot reuse a
|
|
1497
|
+
signature -- but only against a host that requires it or a client that
|
|
1498
|
+
does; see [Channel binding](#channel-binding-tie-the-login-to-the-connection).
|
|
1499
|
+
- **A relay need not be believed about who the operator is (opt-in).** With
|
|
1500
|
+
`requireOperatorProof` on the host and `sealed` on the operator, the host
|
|
1501
|
+
verifies the operator's own signature before `accept`, and acts only on
|
|
1502
|
+
sealed traffic, so a relay cannot stamp an identity, replay a login or inject
|
|
1503
|
+
an `Open`; see the table under
|
|
1504
|
+
[Operator proof and sealed bridges](#operator-proof-and-sealed-bridges-117).
|
|
1505
|
+
Not default, not available through the Rust relay, and no defence against a
|
|
1506
|
+
relay that drops traffic.
|
|
1507
|
+
- **A pipe relay vouches for nothing.** With `createPipeRelay` the host
|
|
1508
|
+
authenticates the operator itself (see [A pipe relay](#a-pipe-relay-johnhenrywshpipe-relay-118)).
|
|
1509
|
+
- **`AuthOk.ttl` and `token`.** The token is an opaque per-connection value
|
|
1510
|
+
with no authority; `ttl` is enforced when `connectionTtlMs` is set (else 0:
|
|
1511
|
+
no limit) -- do not read either as a session credential.
|
|
1512
|
+
- **Client environment is an allow-list** (`clientEnv`, default `TERM`,
|
|
1513
|
+
`COLORTERM`, `LANG`, `LANGUAGE`, `LC_*`): a client cannot set `PATH`,
|
|
1514
|
+
`LD_PRELOAD` or `BASH_ENV` for a command your host runs through a shell
|
|
1515
|
+
unless you say so.
|
|
1190
1516
|
- **E2E through a relay is opt-in.** The relay carries `KeyExchange` /
|
|
1191
1517
|
`EncryptedFrame` between a bridged operator and peer without being able to
|
|
1192
1518
|
read the sealed frames. `KeyExchange` is unauthenticated unless the peer signs
|
|
@@ -1199,8 +1525,25 @@ out explicitly below rather than left to be discovered.
|
|
|
1199
1525
|
entry client-side and reports a `verified` boolean, independent of
|
|
1200
1526
|
trusting the relay.
|
|
1201
1527
|
|
|
1528
|
+
- **The Node gateway checks where a connection goes, not only what it was called.** `gateway.allow` matches the name a
|
|
1529
|
+
client sent, and then the address it resolves to must be globally routable (or permitted by `allowPrivate` or an
|
|
1530
|
+
IP-literal rule); the connection is made to that checked address, and `ResolveDns` answers are filtered the same way.
|
|
1531
|
+
Unix-domain sockets (`gateway.unix`) and named endpoints (`gateway.endpoints`) are off unless configured, are listed
|
|
1532
|
+
paths or names only, and sockets the host creates are `0600`.
|
|
1533
|
+
|
|
1202
1534
|
**What is still yours:**
|
|
1203
1535
|
|
|
1536
|
+
- **What the gateway does NOT protect against.** A name that resolves to a *public* address is dialled as the client
|
|
1537
|
+
asked, so `allow: ['*']` is an open proxy to the internet for every authorized client. Through `socks` the proxy
|
|
1538
|
+
resolves the name, so the host cannot check the address (only IP literals are checked) and the proxy's own network
|
|
1539
|
+
is the egress. The path check for unix sockets is made just before the connect: a local user who can write to an
|
|
1540
|
+
allowed directory can still swap a path between the two, so list only directories that are not writable by others.
|
|
1541
|
+
A client may open any listed socket as the host's user; a socket that speaks a powerful API (the Docker socket is
|
|
1542
|
+
root on the host) is exactly as powerful for every authorized client, so list it only for clients you would give that
|
|
1543
|
+
access. Named endpoints run embedder code with the caller's identity (`who`) but the handler decides what that
|
|
1544
|
+
identity may do. A `wsh-server` built before the Rust release that followed `rust-v0.6.0` only matches the name, not the
|
|
1545
|
+
resolved address (see the Rust defaults above): do not expose such a binary with a `"*"` allow list.
|
|
1546
|
+
|
|
1204
1547
|
- **Hybrid post-quantum E2E is experimental and not fully wired (in
|
|
1205
1548
|
progress).** `initiateE2E(sessionId, 'X25519+ML-KEM-768')` combines
|
|
1206
1549
|
X25519 ECDH with ML-KEM-768 via HKDF-SHA256, preferring native WebCrypto
|
|
@@ -1246,7 +1589,68 @@ out explicitly below rather than left to be discovered.
|
|
|
1246
1589
|
above), but nothing in this protocol or client stops a non-browser
|
|
1247
1590
|
caller (Node, the Rust CLI) from dialing `ws://` directly. Prefer pubkey
|
|
1248
1591
|
auth, or make sure the transport is actually encrypted, before sending a
|
|
1249
|
-
password.
|
|
1592
|
+
password. (The Rust `wsh` CLI refuses a plain `ws://` URL unless the host is
|
|
1593
|
+
loopback.)
|
|
1594
|
+
|
|
1595
|
+
### Rust `wsh-server`: what is off until you turn it on
|
|
1596
|
+
|
|
1597
|
+
An authorized key is a login, not a licence to use the machine as a network
|
|
1598
|
+
position. From the Rust release after `rust-v0.6.0` the server's defaults are:
|
|
1599
|
+
|
|
1600
|
+
- **The gateway is off** (`[gateway] enabled = false`), and `gateway` is not
|
|
1601
|
+
advertised. Turning it on allows **no destination** until `allowed_destinations`
|
|
1602
|
+
lists some. `"*"` means any *public* destination: an address that is loopback,
|
|
1603
|
+
link-local (including `169.254.169.254`), private (RFC 1918), unique-local
|
|
1604
|
+
(`fc00::/7`), carrier-grade NAT (`100.64.0.0/10`), unspecified or multicast is
|
|
1605
|
+
refused **after the name is resolved**, whichever rule matched the name, unless
|
|
1606
|
+
a rule names that host (`"db.internal:5432"`) or address/range
|
|
1607
|
+
(`"10.1.0.0/16:5432"`, `"127.0.0.1:8080"`). The server connects to the address it
|
|
1608
|
+
checked, so a name cannot pass the check as one address and connect as another.
|
|
1609
|
+
`ResolveDns` follows the same rule and does not return internal answers.
|
|
1610
|
+
- **Reverse listeners are off** (`enable_reverse_tunnels = false`) and, when on,
|
|
1611
|
+
bind to `reverse_bind_addr` (default `127.0.0.1`). The client's own `bind_addr`
|
|
1612
|
+
in `ListenRequest` (its wire default is `0.0.0.0`) is ignored.
|
|
1613
|
+
- **Password login is off** (`[auth] allow_password = false`). Stored hashes are
|
|
1614
|
+
Argon2id PHC strings with a per-user salt (`printf '%s' "$PW" | wsh-server
|
|
1615
|
+
--hash-password`), compared in constant time; an unknown user and a wrong password
|
|
1616
|
+
cost the same and fail with the same message. Old unsalted `sha256:` entries are
|
|
1617
|
+
**refused** (logged at start-up, naming the user) unless `allow_legacy_sha256 = true`,
|
|
1618
|
+
which accepts them with a warning at every start-up. Refusing, not warning, is the
|
|
1619
|
+
default because a warning nobody reads leaves the weak hash live on every
|
|
1620
|
+
deployment that is not watched; the edit that turns password login back on is the
|
|
1621
|
+
natural moment to rehash.
|
|
1622
|
+
|
|
1623
|
+
What this does **not** protect against:
|
|
1624
|
+
|
|
1625
|
+
- **A rule you write is trusted.** A hostname rule (`"db.internal"`) allows that name
|
|
1626
|
+
to resolve to anything, including a restricted address; only the wildcard is
|
|
1627
|
+
held to public addresses. An address range or literal address rule allows
|
|
1628
|
+
exactly what it says.
|
|
1629
|
+
- **It is not per-key.** Every authorized key gets the same gateway. A key that
|
|
1630
|
+
should not have it should not be in `authorized_keys`.
|
|
1631
|
+
- **There is no bandwidth or request-rate limit** beyond `max_connections`
|
|
1632
|
+
(default 100 concurrent connections and listeners together), and a listener's
|
|
1633
|
+
port is chosen by the client within what the server's user may bind.
|
|
1634
|
+
- **Hashing protects the stored file, not the wire.** The password still travels
|
|
1635
|
+
inside the auth message (see above); only use password login over `wss://` or
|
|
1636
|
+
WebTransport. The per-address auth rate limit bounds how fast one address can
|
|
1637
|
+
make the server run Argon2id (19 MiB each); it is not a defence against many
|
|
1638
|
+
addresses.
|
|
1639
|
+
- **The dev certificate from `--generate-cert` is not a certificate a TLS client
|
|
1640
|
+
can verify** (it is flagged as a CA); clients dial it with
|
|
1641
|
+
`WSH_INSECURE_LOOPBACK_TLS=1`, which disables verification and is for loopback
|
|
1642
|
+
testing only.
|
|
1643
|
+
|
|
1644
|
+
- **A host that lives in a page (`createMemoryHost`, `@johnhenry/wsh/reverse`) is only as trustworthy as the page.** A
|
|
1645
|
+
non-extractable host key or client key keeps the private key from being *read*, not from being *used*: any script that
|
|
1646
|
+
runs in the page (an XSS, a malicious dependency, an extension with page access) can still have it sign, which means
|
|
1647
|
+
impersonate the host or log in as the user for as long as it runs. The injected `pty`, `fs` and `exec` backends are
|
|
1648
|
+
code you wrote and run with the page's authority -- wsh authenticates who may call them, and confines nothing about what
|
|
1649
|
+
they do: a file backend that resolves `..`, a `pty.spawn` that starts a real process, an `exec` that evals its
|
|
1650
|
+
command are yours to make safe (the Node server's `fs: { root }` is the one with confinement built in, and the
|
|
1651
|
+
browser-safe `fs` option takes no root). Pinning a page-held host key protects a client from the wrong host, not from
|
|
1652
|
+
a byte pipe or relay between them reading and altering the bytes: confidentiality needs `wss://` or the end-to-end layer.
|
|
1653
|
+
`dataStreams: false` changes how output is framed (as `SessionData`), not who is let in.
|
|
1250
1654
|
|
|
1251
1655
|
## Browser Compatibility
|
|
1252
1656
|
|
|
@@ -1325,6 +1729,34 @@ browser the optional `@noble/post-quantum` dependency is what actually
|
|
|
1325
1729
|
runs, loaded dynamically by `src/mlkem.mjs`. Treat it as required, not
|
|
1326
1730
|
optional, if you want the hybrid handshake on the web today.
|
|
1327
1731
|
|
|
1732
|
+
## Browser tests and bundle size
|
|
1733
|
+
|
|
1734
|
+
`npm test` is JS-only and needs no browser. `npm run test:browser` runs the real-Chromium suite (Playwright; install it
|
|
1735
|
+
once with `npx playwright install chromium`) and has its own CI job:
|
|
1736
|
+
|
|
1737
|
+
- a browser client against a Node `createWshServer` over a real WebSocket: auth with a non-extractable key, exec, a pty with
|
|
1738
|
+
resize, file transfer, and resuming a session after the socket drops;
|
|
1739
|
+
- a host that lives in the page, `createMemoryHost().accept(new WebSocket(url))`, joined to its operator by a tiny byte pipe
|
|
1740
|
+
the test owns, driven by the JS client (exec, stdin, pty, files, a pinned non-extractable host key) **and by the released
|
|
1741
|
+
Rust `wsh` CLI**: that test downloads the latest `rust-v*` release's archive for the platform from this repository's
|
|
1742
|
+
GitHub releases, verifies it against the release's `SHA256SUMS`, and runs it with `HOME` pointed at a temp directory (so
|
|
1743
|
+
it never touches `~/.wsh`). It is skipped, with the reason printed, on a platform with no release asset or when the
|
|
1744
|
+
download fails, and fails (rather than skips) in CI. The released CLI only dials `wss://`, so the pipe terminates TLS with
|
|
1745
|
+
a self-signed certificate and the CLI runs with its loopback-only `WSH_INSECURE_LOOPBACK_TLS=1`;
|
|
1746
|
+
- `WshKeyStore` with a non-extractable key surviving a reload and still authenticating.
|
|
1747
|
+
|
|
1748
|
+
The bundle-size report is described under [Browser entry points](#browser-entry-points-the-connection-factory-and-bundle-size).
|
|
1749
|
+
|
|
1750
|
+
## Related projects
|
|
1751
|
+
|
|
1752
|
+
- **[`@johnhenry/browsermesh-netway`](https://github.com/johnhenry/browsermesh)** takes a `WshClient` as its gateway backend
|
|
1753
|
+
(see [Family](#family) below).
|
|
1754
|
+
- **The Rust crates** in [`crates/`](crates) (`wsh-core`, `wsh-client`, `wsh-cli`, `wsh-server`) are a native
|
|
1755
|
+
implementation of the same wire protocol, versioned separately (`rust-v*` tags) and generated from the same
|
|
1756
|
+
`spec/wsh-v1.yaml`; see [Rust implementation](#rust-implementation) for what each side can do.
|
|
1757
|
+
- **[clawser](https://github.com/erisera-code/clawser)** downloads the Rust release binaries by their archive names and is
|
|
1758
|
+
where the Rust workspace came from.
|
|
1759
|
+
|
|
1328
1760
|
## Family
|
|
1329
1761
|
|
|
1330
1762
|
wsh isn't just a standalone remote-shell client -- its `WshClient` is the
|