@johnhenry/wsh 0.38.0 → 0.38.1
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 +97 -29
- package/package.json +2 -2
- package/src/client.mjs +35 -3
- package/src/index.d.ts +5 -1
- package/src/server/relay.mjs +6 -1
package/README.md
CHANGED
|
@@ -375,13 +375,30 @@ mistaken for (or smuggled as) a file-system path or an abstract-namespace name,
|
|
|
375
375
|
consulted for it; the registered names are an allow-list by construction. `who` is the authenticated
|
|
376
376
|
`{ username, fingerprint }`, so the embedder can authorise per call (throw to refuse, or `{ open, authorize(who) }`).
|
|
377
377
|
|
|
378
|
-
**Rust side
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
378
|
+
**Rust side.** The Rust `wsh-server` serves the same messages with the same policy (`[gateway]`, off unless
|
|
379
|
+
`enabled = true`; `gateway-unix` is advertised only when a socket is listed):
|
|
380
|
+
|
|
381
|
+
```toml
|
|
382
|
+
[gateway]
|
|
383
|
+
enabled = true
|
|
384
|
+
unix_connect = ["/var/run/docker.sock", "/run/user/1000/wsh/"] # OpenUnix: exact path, "/dir/" prefix, or "@abstract" (Linux)
|
|
385
|
+
unix_listen = ["/run/user/1000/wsh/"] # ListenUnix: sockets a client may ask the host to create
|
|
386
|
+
unix_replace_stale = false # replace a stale socket file only if the request asks AND this is true
|
|
387
|
+
unix_max_listeners = 4 # per client connection
|
|
388
|
+
max_buffered_bytes = 4194304 # per connection, for a peer without gateway-credit (at least 262144)
|
|
389
|
+
max_client_buffered_bytes = 33554432
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
The checks are the Node host's: paths judged after `realpath` of the parent, a `..` segment refused, the target must be a
|
|
393
|
+
socket and not a symlink, created sockets are `0600` and unlinked on close, a socket that something still accepts on is
|
|
394
|
+
never replaced, a file that is not a socket is never touched; a bad pattern (`/`, a relative path, `..`) stops the server
|
|
395
|
+
at start-up. `GatewayCredit` is served with 256 KiB per direction when the client lists `gateway-credit`; without it the
|
|
396
|
+
host closes a connection that has more than `max_buffered_bytes` of unconsumed client data (or the client more than
|
|
397
|
+
`max_client_buffered_bytes`). The `gateway_id` and `listener_id` tables are per client connection (before, one table was
|
|
398
|
+
shared by every client). A Rust host does not offer named endpoints.
|
|
399
|
+
|
|
400
|
+
The CLI forwards like OpenSSH (see [Rust implementation](#running-a-command-with-wsh)): `wsh -L /tmp/docker.sock:/var/run/docker.sock user@host`,
|
|
401
|
+
`wsh -N -L 2375:/var/run/docker.sock user@host`, `wsh -N -L /tmp/d.sock:endpoint=docker --via wss://relay/r/<id> user@host`.
|
|
385
402
|
|
|
386
403
|
### TLS (`wss://`) and host extensions
|
|
387
404
|
|
|
@@ -763,7 +780,16 @@ set from the operator's login at the relay) and the host's `accept` trusts it:
|
|
|
763
780
|
fine for a relay you run, not for a shared one. Two opt-ins close that, and both
|
|
764
781
|
are negotiated by feature strings so every released peer keeps working
|
|
765
782
|
(the Rust relay never lists `operator-proof`, so the operator simply does not
|
|
766
|
-
offer it there)
|
|
783
|
+
offer it there).
|
|
784
|
+
|
|
785
|
+
**Who is offered proof.** `ReverseConnect.features` is a field a released Rust host (`rust-v0.6` to `v0.8`) cannot decode
|
|
786
|
+
(`deny_unknown_fields`: it drops the connection, which looks like a timeout). So a peer lists `operator-proof` in its
|
|
787
|
+
registered capabilities when it can answer a challenge (JS hosts and, since `rust-v0.9`, Rust hosts with an identity),
|
|
788
|
+
`reverseConnect()` offers proof only to a peer whose record lists it (`proof: 'auto'`, looked up with `listPeers()`;
|
|
789
|
+
`peerCapabilities` skips the lookup, `proof: true` offers regardless, `proof: false` never), and the JS relay strips the
|
|
790
|
+
field for a peer that did not advertise it. `requirePeerProof` and `sealed` against such a peer fail at once with a
|
|
791
|
+
sentence and send nothing. A JS host from npm 0.36-0.38 does not list the capability yet, so proof to it needs an upgrade
|
|
792
|
+
of the host.
|
|
767
793
|
|
|
768
794
|
```js
|
|
769
795
|
// host: do not take the operator's identity from the relay.
|
|
@@ -1272,7 +1298,7 @@ fs_max_file_bytes = 67108864
|
|
|
1272
1298
|
Key options apply as they do to other channels: a key restricted to a forced
|
|
1273
1299
|
command opens no rpc channel, and `wsh-fs` needs the `file-transfer` scope
|
|
1274
1300
|
(`permit-file-transfer` under `restrict`). `host.info` reports the crate version
|
|
1275
|
-
and `hostFingerprint: null`
|
|
1301
|
+
and `hostFingerprint: null` unless `[server] host_key` is configured. The JS client
|
|
1276
1302
|
needs nothing new: it reads `rpc` from `ServerHello`, and its file helpers prefer
|
|
1277
1303
|
`wsh-fs` automatically once the server offers it.
|
|
1278
1304
|
|
|
@@ -1432,7 +1458,7 @@ instead of dragging its own toolchain and CI job into an unrelated
|
|
|
1432
1458
|
browser-app repo. It was previously deleted from clawser by accident
|
|
1433
1459
|
(2026-03-14) and restored (2026-07-05) before this move.
|
|
1434
1460
|
|
|
1435
|
-
Four crates, workspace-versioned (currently `0.
|
|
1461
|
+
Four crates, workspace-versioned (currently `0.9.0`):
|
|
1436
1462
|
|
|
1437
1463
|
| Crate | Kind | Description |
|
|
1438
1464
|
|-------|------|--------------|
|
|
@@ -1457,6 +1483,36 @@ disconnects. `wsh connect` ends when the remote session does. Diagnostics go to
|
|
|
1457
1483
|
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
|
|
1458
1484
|
`ws://` URL is accepted only for a loopback host.
|
|
1459
1485
|
|
|
1486
|
+
### Forwarding with `wsh -L` / `-R` / `-N`
|
|
1487
|
+
|
|
1488
|
+
Modelled on OpenSSH. The forwards live as long as the connection does (`wsh -L ... user@host` also runs the command or
|
|
1489
|
+
shell; `-N` only forwards, until Ctrl-C), work with `--via` (the pipe relay carries them like anything else), and may be
|
|
1490
|
+
repeated:
|
|
1491
|
+
|
|
1492
|
+
```sh
|
|
1493
|
+
wsh -L 8080:db.internal:5432 alice@host # [bind_addr:]port:host:hostport (the HOST connects to db.internal)
|
|
1494
|
+
wsh -N -L /tmp/docker.sock:/var/run/docker.sock alice@host # local unix socket -> a unix socket on the host
|
|
1495
|
+
wsh -N -L 127.0.0.1:2375:/var/run/docker.sock alice@host # local TCP port -> a unix socket on the host
|
|
1496
|
+
wsh -N -L /tmp/db.sock:db.internal:5432 alice@host # local unix socket -> TCP the host reaches
|
|
1497
|
+
wsh -N -L /tmp/docker.sock:endpoint=docker --via wss://relay/r/<id> alice@tab.example # a NAMED ENDPOINT of an in-page host
|
|
1498
|
+
wsh -N -R /run/user/1000/wsh/app.sock:127.0.0.1:3000 alice@host # the HOST listens on a unix socket; connections come here
|
|
1499
|
+
wsh -N -R 9000:localhost:3000 alice@host # the host listens on a TCP port (loopback by default)
|
|
1500
|
+
```
|
|
1501
|
+
|
|
1502
|
+
A named endpoint is written `endpoint=NAME` as the remote end of `-L` (`NAME`: letters, digits, `.`, `_`, `-`; at most 64).
|
|
1503
|
+
The `=` cannot occur in a host name, a port or a path, so it can never be mistaken for a host called "endpoint" (that is
|
|
1504
|
+
`endpoint:80`), and `@NAME` is already the Linux abstract-namespace socket (`-L 8080:@name`). A host with no file system
|
|
1505
|
+
(an in-page host) offers endpoints instead of unix sockets; `wsh -L ...:endpoint=docker` plus `DOCKER_HOST=unix:///tmp/docker.sock`
|
|
1506
|
+
is the shape of reaching a daemon behind one. `-R` cannot name an endpoint (a host offers those, it does not listen on them).
|
|
1507
|
+
|
|
1508
|
+
Local TCP listeners bind `127.0.0.1` unless `bind_addr` says otherwise (`*` or `0.0.0.0` listens on every interface, and `wsh`
|
|
1509
|
+
warns). Local unix sockets are created `0600`, removed on exit (a killed `wsh` leaves its file), and an existing file at the
|
|
1510
|
+
path is **refused** unless `--replace-socket` is given, which replaces only a stale socket: never a live one, never a file that
|
|
1511
|
+
is not a socket. With `-R`, `--replace-socket` asks the host to replace its own stale socket (its policy decides). A host that
|
|
1512
|
+
cannot do what a forward needs says so (`this host does not offer unix-socket forwarding`, `no such endpoint`, `not allowed by
|
|
1513
|
+
the gateway policy`); a malformed spec exits with status 2 before anything is dialled. Up to 128 forwarded connections are
|
|
1514
|
+
open at once. `-L`/`-R`/`-N` apply to `wsh [user@]host [command...]` and `wsh connect` only.
|
|
1515
|
+
|
|
1460
1516
|
### Capability matrix: JS SDK vs Rust CLI/client
|
|
1461
1517
|
|
|
1462
1518
|
Two implementations of one protocol will always have *some* asymmetry --
|
|
@@ -1470,7 +1526,7 @@ than left to be found.
|
|
|
1470
1526
|
| Upload/download | `WshClient.upload()`/`.download()` | `file_transfer::upload()`/`download()`, `wsh scp` | **Wire-unified**: `FileChunk` over a `'file'`-kind channel (wsh #13) |
|
|
1471
1527
|
| 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 |
|
|
1472
1528
|
| 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 |
|
|
1473
|
-
| Host identity / TOFU | `WshKnownHosts` (localStorage-backed) | `KnownHosts`/`HostStatus` (`~/.wsh/known_hosts`-backed)
|
|
1529
|
+
| 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 |
|
|
1474
1530
|
| 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 |
|
|
1475
1531
|
| 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 |
|
|
1476
1532
|
| 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 |
|
|
@@ -1480,13 +1536,13 @@ than left to be found.
|
|
|
1480
1536
|
| 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) |
|
|
1481
1537
|
| 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 |
|
|
1482
1538
|
| 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 |
|
|
1483
|
-
| 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 })` |
|
|
1484
|
-
| Gateway flow control (#123) | credit per connection (`GatewayCredit`, feature `gateway-credit`); host caps for peers without it |
|
|
1485
|
-
| 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); no port allow-list; no per-listener connection, backlog or idle bounds beyond `max_connections` | **Wire-unified** (`ListenRequest`/`ListenOk`/`ListenFail`/`InboundOpen`/`InboundAccept`; the JS host sends the real `peer_addr`/`peer_port`). **Rust still needs**: a port allow-list and per-client listener / per-listener connection / idle bounds to match the JS host
|
|
1539
|
+
| 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) |
|
|
1540
|
+
| 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) |
|
|
1541
|
+
| 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); no port allow-list; no per-listener connection, backlog or idle bounds beyond `max_connections` | **Wire-unified** (`ListenRequest`/`ListenOk`/`ListenFail`/`InboundOpen`/`InboundAccept`; the JS host sends the real `peer_addr`/`peer_port`). **Rust still needs**: a port allow-list and per-client listener / per-listener connection / idle bounds to match the JS host. Accepted connections are metered by `gateway-credit` now |
|
|
1486
1542
|
| 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` serves `OpenUdp` over the reliable control stream only (one `GatewayData` per datagram); no datagrams, no rate bounds | **JS only for now** (negotiated by `gateway-datagram`, so a Rust peer keeps the reliable path). **Rust must implement**: list `gateway-datagram` in `ServerHello.features` on a WebTransport connection, accept/send datagrams `[gateway_id u32 BE][payload]` for `OpenUdp` flows when the client listed it (ignore the id of an unknown flow), read `maxDatagramSize` and send a bigger payload as `GatewayData` (or drop, by config), `connect()` the UDP socket to the checked address, and the same rate/flow bounds |
|
|
1487
1543
|
| 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) |
|
|
1488
|
-
| Operator proof to the peer, sealed bridge, signed initiator half (#117) | `reverseConnect(.., { sealed, requirePeerProof })`; host `createReverseHost({ requireOperatorProof })`; relay lists `operator-proof` |
|
|
1489
|
-
| Channel binding of the login signature (#119) | `requireChannelBinding` (client and server); kinds `host`, `cert-hash`, `tls-exporter` |
|
|
1544
|
+
| 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 signed `KeyExchange` halves: not yet** (no Rust E2E responder), so `--require-operator-proof` proves who connected but does not stop a relay stamping an identity on later plain messages | **Wire-unified, negotiated** (`ReverseConnect.features`, `operator-proof`, `e2e-sealed`); sealing is JS-only |
|
|
1545
|
+
| 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` and `tls-exporter`: not in Rust (the Rust WebTransport client has no certificate-hash pinning; `ConnectConfig.cert_hash` binds it if a caller supplies one) | **Wire-unified, negotiated** (`channel-binding:<kind>` features); verified against the spec's test vectors |
|
|
1490
1546
|
| 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, and the Rust client does not yet verify the host-key proof or bind the login to the host (see Security model) | **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) |
|
|
1491
1547
|
| `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` |
|
|
1492
1548
|
| `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 |
|
|
@@ -1649,6 +1705,11 @@ out explicitly below rather than left to be discovered.
|
|
|
1649
1705
|
treat `initiateE2E` as key agreement, not confidentiality, unless you've
|
|
1650
1706
|
separately confirmed the session has sealing enabled.
|
|
1651
1707
|
- **Host identity (TOFU) has a known, named gap (wsh #59).**
|
|
1708
|
+
**Update (#145): the Rust `wsh-server` now has an opt-in host key
|
|
1709
|
+
(`[server] host_key = "<path>"`, created 0600 on first start; see the
|
|
1710
|
+
capability matrix) and the Rust client verifies the proof; the paragraph
|
|
1711
|
+
below describes the state before that and still applies to a Rust server
|
|
1712
|
+
with no `host_key` configured, which proves nothing.**
|
|
1652
1713
|
`ServerHello.host_fingerprint` is the spec's formal host-identity slot:
|
|
1653
1714
|
the SHA-256 fingerprint of a server's persistent Ed25519 host key, meant
|
|
1654
1715
|
to be pinned across connections the way SSH pins a host key. **As of 0.19
|
|
@@ -1746,23 +1807,30 @@ What this does **not** protect against:
|
|
|
1746
1807
|
`Signal` goes only to the process group of a channel the sending connection
|
|
1747
1808
|
controls. This does not make a command safe to run: an authorized key still
|
|
1748
1809
|
runs commands as the server's user.
|
|
1810
|
+
- **Forwarding (`wsh -L`/`-R`, `OpenUnix`, `ListenUnix`) lends the host's reach, not a sandbox.** Listing a socket in
|
|
1811
|
+
`unix_connect` gives every authorized key everything that socket's service can do: Docker's socket is root on the
|
|
1812
|
+
machine. The policy checks the path, not the peer, and cannot close the instant between the check and the connect
|
|
1813
|
+
(allow only directories no other local user can write to). It is not per key and has no rate limit beyond
|
|
1814
|
+
`max_connections`. `wsh -L` publishes a local port or socket to whoever can reach it: loopback by default, but an explicit
|
|
1815
|
+
`bind_addr` of `0.0.0.0` (the CLI warns) hands the forward to the network, and a local unix socket is `0600` only against
|
|
1816
|
+
other users, not against your own processes. A forwarded connection is as private as the wsh connection under it (a pipe
|
|
1817
|
+
relay sees it unless the legs are TLS). The Rust host binds a created socket inside a private `0700` directory and links it into place, so it is never visible with a looser mode and the process umask is not touched.
|
|
1749
1818
|
- **Rust `wsh-server`'s `AuthOk.ttl` is 0 and its `token` is opaque** (as the
|
|
1750
1819
|
JS host's, above): nothing is promised or enforced at connection level; do not
|
|
1751
1820
|
treat the token as a credential.
|
|
1752
1821
|
- **`wsh --via` (pipe relay from the Rust CLI) is the operator side only, and
|
|
1753
|
-
|
|
1754
|
-
`
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
are the next part of #145.
|
|
1822
|
+
still not sealed.** The Rust client now verifies the host-key proof
|
|
1823
|
+
(`host-key` / `host-key-sig` over its own `host-key-nonce`) before sending
|
|
1824
|
+
any credential, records only a PROVEN key in `known_hosts`, binds the login
|
|
1825
|
+
signature to that key (channel binding `host`), and refuses a changed key
|
|
1826
|
+
always. A replayed `ServerHello` or an impostor's key is refused as the JS
|
|
1827
|
+
client refuses it. What is still unprotected: the bridge is not sealed
|
|
1828
|
+
end to end (the Rust side has no sealed bridge yet), so the relay sees
|
|
1829
|
+
session traffic in the clear unless the legs are TLS and it is trusted not
|
|
1830
|
+
to read them (it terminates each leg's TLS), and it can stamp an identity on
|
|
1831
|
+
a plain message after the handshake. A host with no host key proves nothing:
|
|
1832
|
+
the CLI connects to it (as every release did) unless `--require-host-key`
|
|
1833
|
+
says otherwise.
|
|
1766
1834
|
|
|
1767
1835
|
- **A host that lives in a page (`createMemoryHost`, `@johnhenry/wsh/reverse`) is only as trustworthy as the page.** A
|
|
1768
1836
|
non-extractable host key or client key keeps the private key from being *read*, not from being *used*: any script that
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnhenry/wsh",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.1",
|
|
4
4
|
"description": "Web Shell \u2014 browser-native remote command execution over WebTransport and WebSocket with Ed25519 authentication",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.mjs",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"test": "node --test test/*.test.mjs",
|
|
75
|
-
"test:rust": "node --test test/rust/*.test.mjs",
|
|
75
|
+
"test:rust": "node --test --test-timeout=180000 test/rust/*.test.mjs",
|
|
76
76
|
"test:browser": "playwright test --config test/browser/playwright.config.mjs",
|
|
77
77
|
"size": "node scripts/bundle-size.mjs",
|
|
78
78
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
package/src/client.mjs
CHANGED
|
@@ -1234,6 +1234,8 @@ export class WshClient {
|
|
|
1234
1234
|
* @param {object} [opts.expose] - Capabilities to expose { shell, exec, fs, tools }
|
|
1235
1235
|
* @param {string} [opts.peerType]
|
|
1236
1236
|
* @param {string} [opts.shellBackend]
|
|
1237
|
+
* @param {boolean} [opts.operatorProof=true] list `operator-proof` in the registered capabilities (a key login only): this
|
|
1238
|
+
* peer can answer an operator's challenge. A hand-written handler that never challenges passes `false`.
|
|
1237
1239
|
* @param {boolean} [opts.supportsAttach]
|
|
1238
1240
|
* @param {boolean} [opts.supportsReplay]
|
|
1239
1241
|
* @param {boolean} [opts.supportsEcho]
|
|
@@ -1253,6 +1255,7 @@ export class WshClient {
|
|
|
1253
1255
|
supportsReplay,
|
|
1254
1256
|
supportsEcho,
|
|
1255
1257
|
supportsTermSync,
|
|
1258
|
+
operatorProof = true,
|
|
1256
1259
|
...hostKeyOpts
|
|
1257
1260
|
} = {}) {
|
|
1258
1261
|
// Authenticate normally first.
|
|
@@ -1267,6 +1270,9 @@ export class WshClient {
|
|
|
1267
1270
|
|
|
1268
1271
|
// Export public key for peer identification.
|
|
1269
1272
|
const cred = await resolveSigner({ keyPair, signer });
|
|
1273
|
+
// A peer that can answer an operator's challenge says so in its signed record: a released peer cannot decode
|
|
1274
|
+
// `ReverseConnect.features`, so an operator (and the relay) states the field only to a peer that lists this.
|
|
1275
|
+
if (cred && operatorProof) capabilities.push(OPERATOR_PROOF_FEATURE);
|
|
1270
1276
|
this.#signer = cred;
|
|
1271
1277
|
this.#loginUsername = username;
|
|
1272
1278
|
let publicKey = null;
|
|
@@ -1359,12 +1365,21 @@ export class WshClient {
|
|
|
1359
1365
|
/**
|
|
1360
1366
|
* Initiate a reverse connection and wait for accept/reject.
|
|
1361
1367
|
*
|
|
1368
|
+
* Offering proof (`ReverseConnect.features: ['operator-proof']`) needs a key login, a relay that carries it, and a peer
|
|
1369
|
+
* whose registered record lists `operator-proof`: a released Rust host (v0.6 to v0.8) rejects the field outright. Options:
|
|
1370
|
+
* - `proof`: `'auto'` (default; offer to a peer that advertises it, looked up with `listPeers()`), `true` (offer anyway;
|
|
1371
|
+
* the relay still strips it for a peer that did not advertise), `false` (never offer).
|
|
1372
|
+
* - `requirePeerProof` / `sealed`: fail at once, with a sentence, when the peer does not advertise it.
|
|
1373
|
+
* - `peerCapabilities`: the peer's capability list, when the caller already has it (skips the lookup).
|
|
1374
|
+
*
|
|
1362
1375
|
* @param {string} targetFingerprint
|
|
1363
1376
|
* @param {number} [timeout=10000]
|
|
1377
|
+
* @param {{ proof?: 'auto'|boolean, requirePeerProof?: boolean, sealed?: boolean|object, peerCapabilities?: string[] }} [opts]
|
|
1364
1378
|
* @returns {Promise<object>}
|
|
1365
1379
|
*/
|
|
1366
|
-
async reverseConnect(targetFingerprint, timeout = DEFAULT_OPEN_TIMEOUT, { proof = 'auto', requirePeerProof = false, sealed = false } = {}) {
|
|
1380
|
+
async reverseConnect(targetFingerprint, timeout = DEFAULT_OPEN_TIMEOUT, { proof = 'auto', requirePeerProof = false, sealed = false, peerCapabilities } = {}) {
|
|
1367
1381
|
this.#assertAuthenticated('reverseConnect');
|
|
1382
|
+
if (proof !== 'auto' && typeof proof !== 'boolean') throw new TypeError("reverseConnect: proof must be 'auto', true or false");
|
|
1368
1383
|
|
|
1369
1384
|
// Proving this operator's identity to the PEER (wsh #117) needs a relay that carries the challenge and a key to sign with.
|
|
1370
1385
|
const relayCarriesProof = this.#serverFeatures.includes(OPERATOR_PROOF_FEATURE);
|
|
@@ -1373,7 +1388,6 @@ export class WshClient {
|
|
|
1373
1388
|
throw new Error(`reverseConnect: this relay does not carry operator proof (no "${OPERATOR_PROOF_FEATURE}" in its features), so ${sealOpts ? 'a sealed bridge' : 'proof'} is not available -- nothing was sent`);
|
|
1374
1389
|
}
|
|
1375
1390
|
if ((sealOpts || requirePeerProof || proof === true) && !this.#signer) throw new Error('reverseConnect: proof needs a key login (a password login has nothing to sign with)');
|
|
1376
|
-
const offerProof = proof !== false && relayCarriesProof && !!this.#signer;
|
|
1377
1391
|
|
|
1378
1392
|
// A sealed bridge sends nothing that names a command, a path or a session before the key exists: from here on a
|
|
1379
1393
|
// message the relay may forward is refused locally until the bridge key is in place.
|
|
@@ -1395,6 +1409,24 @@ export class WshClient {
|
|
|
1395
1409
|
let response = null;
|
|
1396
1410
|
let challenge = null;
|
|
1397
1411
|
try {
|
|
1412
|
+
// A released peer (rust-v0.6 to v0.8) drops the connection on a ReverseConnect with a field it does not know, so the
|
|
1413
|
+
// offer is made only to a peer whose registered record lists `operator-proof` ('auto'), or when the caller insists
|
|
1414
|
+
// (`proof: true`). The relay checks the same on its side and strips the field for a peer that did not advertise it.
|
|
1415
|
+
let peerCanProve = proof === true;
|
|
1416
|
+
if (!peerCanProve && proof === 'auto' && relayCarriesProof && this.#signer) {
|
|
1417
|
+
let caps = peerCapabilities;
|
|
1418
|
+
if (!Array.isArray(caps)) {
|
|
1419
|
+
const peers = await this.listPeers(timeout).catch(() => []);
|
|
1420
|
+
const hits = peers.filter((p) => p.fingerprint === targetFingerprint || (targetFingerprint.length >= 8 && String(p.fingerprint ?? '').startsWith(targetFingerprint)));
|
|
1421
|
+
caps = hits.length === 1 ? hits[0].capabilities : [];
|
|
1422
|
+
}
|
|
1423
|
+
peerCanProve = caps.includes(OPERATOR_PROOF_FEATURE);
|
|
1424
|
+
if ((sealOpts || requirePeerProof) && !peerCanProve) {
|
|
1425
|
+
throw new Error(`reverseConnect: the peer does not advertise "${OPERATOR_PROOF_FEATURE}" in its registered record (a host older than operator proof, or one that cannot answer a challenge), so ${sealOpts ? 'a sealed bridge' : 'proof'} is not available -- nothing was sent`);
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
const offerProof = proof !== false && relayCarriesProof && !!this.#signer && peerCanProve;
|
|
1429
|
+
|
|
1398
1430
|
const ownFingerprint = this.#signer ? await computeFingerprint(this.#signer.publicKeyRaw) : null;
|
|
1399
1431
|
// Register before sending: the answer can follow the request closely.
|
|
1400
1432
|
const first = this.#waitForMessage(
|
|
@@ -1425,7 +1457,7 @@ export class WshClient {
|
|
|
1425
1457
|
}
|
|
1426
1458
|
|
|
1427
1459
|
if (response.type === MSG.REVERSE_ACCEPT) {
|
|
1428
|
-
if (requirePeerProof && !challenge) throw new Error(
|
|
1460
|
+
if (requirePeerProof && !challenge) throw new Error(`reverseConnect: the peer did not prove its identity (requirePeerProof)${proof === true ? `; the relay does not pass the offer to a peer that does not advertise "${OPERATOR_PROOF_FEATURE}"` : ''} -- nothing was sent over the bridge`);
|
|
1429
1461
|
if (challenge && response.target_fingerprint !== challenge.peerFingerprint) throw new Error('reverseConnect: the relay named a different peer than the one that signed the challenge');
|
|
1430
1462
|
if (sealOpts) {
|
|
1431
1463
|
if (!challenge) throw new Error('reverseConnect: a sealed bridge needs the peer to answer with a challenge (does it require operator proof support?)');
|
package/src/index.d.ts
CHANGED
|
@@ -1946,6 +1946,8 @@ export interface WshConnectReverseOptions {
|
|
|
1946
1946
|
fs?: boolean;
|
|
1947
1947
|
tools?: boolean;
|
|
1948
1948
|
};
|
|
1949
|
+
/** List `operator-proof` in the registered capabilities (key logins only; default true): this peer can answer an operator's challenge. */
|
|
1950
|
+
operatorProof?: boolean;
|
|
1949
1951
|
peerType?: string;
|
|
1950
1952
|
shellBackend?: string;
|
|
1951
1953
|
supportsAttach?: boolean;
|
|
@@ -2416,8 +2418,10 @@ export class WshClient {
|
|
|
2416
2418
|
targetFingerprint: string,
|
|
2417
2419
|
timeout?: number,
|
|
2418
2420
|
opts?: {
|
|
2419
|
-
/** `'auto'` (default):
|
|
2421
|
+
/** `'auto'` (default): offer proof when the relay carries it and the peer's registered record lists `operator-proof`; `false`: never; `true`: offer regardless of the record (the relay still strips it for a peer that did not advertise it) and refuse if the relay cannot carry it. */
|
|
2420
2422
|
proof?: 'auto' | boolean;
|
|
2423
|
+
/** The peer's capability list, when the caller already holds it (skips the `listPeers()` lookup `'auto'` makes). */
|
|
2424
|
+
peerCapabilities?: string[];
|
|
2421
2425
|
/** Refuse the bridge unless the peer signed its challenge (so it proved its key to this operator). */
|
|
2422
2426
|
requirePeerProof?: boolean;
|
|
2423
2427
|
/**
|
package/src/server/relay.mjs
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
import { cborEncode, cborDecode } from '../cbor.mjs';
|
|
29
29
|
import { fingerprint as fingerprintOf, importPublicKeyRaw, verifyPeerRecord } from '../auth.mjs';
|
|
30
30
|
import { MSG, isRelayForwardable, relayForward, reversePeers, reverseReject, reverseClose } from '../messages.gen.mjs';
|
|
31
|
+
import { OPERATOR_PROOF_FEATURE } from '../operator-proof.mjs';
|
|
31
32
|
|
|
32
33
|
export const DEFAULT_MAX_PEERS = 1024;
|
|
33
34
|
export const DEFAULT_CONNECT_TIMEOUT_MS = 8000;
|
|
@@ -253,7 +254,11 @@ export class RelayHub {
|
|
|
253
254
|
from_fingerprint: operator.fingerprint,
|
|
254
255
|
};
|
|
255
256
|
// What the operator says it can do (#117), bounded; it is the operator's own claim and decides nothing here.
|
|
256
|
-
|
|
257
|
+
// Only to a peer that advertised `operator-proof` in its registered record: a released peer (rust-v0.6 to v0.8) rejects
|
|
258
|
+
// the field outright (its generated types deny unknown fields), which the operator would see as a timeout. Stripped,
|
|
259
|
+
// that peer answers as it always did, without a challenge; an operator that insists on proof then fails at once.
|
|
260
|
+
const peerCanProve = (target.meta.capabilities ?? []).includes(OPERATOR_PROOF_FEATURE);
|
|
261
|
+
if (peerCanProve && Array.isArray(msg.features) && msg.features.length <= MAX_OPERATOR_FEATURES && msg.features.every((f) => isStr(f, MAX_FEATURE_LENGTH))) forwarded.features = [...msg.features];
|
|
257
262
|
target.handle.send(forwarded);
|
|
258
263
|
this.log(`relay: ${operator.fingerprint.slice(0, 12)} -> ${target.meta.fingerprint.slice(0, 12)} requested`);
|
|
259
264
|
}
|