@johnhenry/wsh 0.47.0 → 0.49.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 CHANGED
@@ -37,7 +37,7 @@ wsh is a pure-JS client library (with an optional Node server at `@johnhenry/wsh
37
37
  - [Browser Compatibility](#browser-compatibility)
38
38
  - [Browser tests and bundle size](#browser-tests-and-bundle-size)
39
39
  - [Related projects](#related-projects)
40
- - [Family](#family)
40
+ - [wsh and browsermesh](#wsh-and-browsermesh)
41
41
  - [License](#license)
42
42
 
43
43
  ## Install
@@ -309,7 +309,8 @@ the host has turned on; scope them with `capabilities` below. `no-port-forwardin
309
309
 
310
310
  #### Capabilities and expiry (#122, step two)
311
311
 
312
- Two more options give a key a finer, **default-deny** licence. Nothing changes for a key line that has neither.
312
+ Two more options give a key a finer, **default-deny** licence. Nothing changes for a key line that has neither. The notation is written
313
+ as a specification in [`spec/capabilities.md`](spec/capabilities.md) (see [Identity and capabilities for other implementations](#identity-and-capabilities-for-other-implementations-220)).
313
314
 
314
315
  ```
315
316
  capabilities="exec,fs:read,gateway:tcp:db.internal:5432,mcp:search" ssh-ed25519 AAAA... ci@build
@@ -360,6 +361,46 @@ the client already gets (`OpenFail`, a failed `FileResult`, `GatewayFail`, `List
360
361
  `not-permitted` (`detail`: `capability-missing: missing capability exec (open exec)`), or `key-expired`. The Rust server logs them.
361
362
  `capabilities` and `expires` apply to **key logins**: a password login has no key and is not narrowed by them.
362
363
 
364
+ #### Identity and capabilities for other implementations (#220)
365
+
366
+ The notation above is written down once, as a specification, with vectors that another implementation can run:
367
+
368
+ - **`spec/capabilities.md`** is the grammar of one capability, what each wildcard matches (and what it does not: `*.example.com`
369
+ is not `example.com` and not `evilexample.com`; `/srv/*` is not `/srv`), what each request kind needs, the order of the checks
370
+ (expiry, the options, the list), and what an implementation does with an entry it does not understand: **fail closed**, the whole
371
+ list permits nothing and a key line that holds it is refused.
372
+ - **`spec/capabilities.vectors.json`** (with a `version`, and `spec/key-options.vectors.json` for the option syntax) is "does a
373
+ holder of list L permit request R" as data. The JS evaluation and the Rust `wsh-server` both run it. A case names the host classes
374
+ it applies to: the Rust server has no named endpoints, no targets and no `wsh-objects`, and **states that subset by refusing**:
375
+ a key line with an `objects:` capability is refused at load there (`unknown-capability`), rather than accepted and ignored, so a
376
+ key meant for a page cannot sit unnoticed on a machine that cannot honour it. Both files ship in the npm package:
377
+ `import vectors from '@johnhenry/wsh/spec/capabilities.vectors.json' with { type: 'json' }`.
378
+ - **`@johnhenry/wsh/capabilities`** exports the evaluation: `permits(capabilities, request, { expires, now })` is a boolean,
379
+ `checkCapabilities(...)` the refusal (`{ code, capability }`) when not. It is pure, browser-safe and fails closed (no list, an
380
+ entry it does not know, or a request kind it does not know permits nothing).
381
+ - **`@johnhenry/wsh/identity`** is one stable module for a key's names: the raw 32-byte key, the OpenSSH `ssh-ed25519` line
382
+ (`rawKeyToOpenSsh`, `openSshToRawKey`, `publicKeyToOpenSsh`), the hex **fingerprint** (SHA-256 of the raw key) and the base64url
383
+ **pod id** (the same 32 bytes: `fingerprintToPodId`, `podIdToFingerprint`), `identityOf(key)` for all four, and
384
+ `authorizedKeyLine(key, { capabilities, expires, comment })`, which builds a line for an `authorized_keys` file and **refuses
385
+ unsafe input**: no `capabilities` unless you say `allowFullAccess: true` out loud (a line with none may do everything), only
386
+ capabilities the notation knows, a timestamp it can read, no control character or line break in the comment, a plain Ed25519
387
+ key, and it reads its own line back through a host's parser before returning it.
388
+ - **The gateway error table** is data too: `GATEWAY_FAIL`, `GATEWAY_FAIL_TABLE` and `gatewayFailName(code)` are exported from the
389
+ package root (`@johnhenry/browsermesh-netway` decodes the same numbers). The table notes that the Rust server sends `5` for a
390
+ disabled gateway where the Node gateway sends it for a timeout.
391
+ - **For the object and MCP layers**: the identity handed to `authorize(who, op)` is `{ username, fingerprint, podId? }`.
392
+ `fingerprint` is always the hex hash of the caller's key; `podId` is there when the transport knows the caller by one. A
393
+ transport that is not wsh gives an identity object (`createDuplexPeer({ send, who: { podId } })`, or `attach(peer, { who })`)
394
+ instead of putting a pod id in a field named `fingerprint`; whichever of the two it gives, the other is derived, and an identity
395
+ that names two different keys is refused. A wsh caller keeps the `{ username, fingerprint }` it always had. The transport's own
396
+ grants are `createDuplexPeer({ permit })`, asked per operation (`get`, `call`, `set`, `on`, and `walk`); `permit` answering anything
397
+ but `true`, or throwing, refuses.
398
+
399
+ What none of this is: `permits()` decides what a list says; it does not authenticate the holder, and a list is only as portable as
400
+ the oldest implementation that reads it (a newer notation's entries fail closed on an older reader). `authorizedKeyLine` writes a
401
+ grant; whoever may install it into a file a host reads is who decides, and a browser-stored key that is valid on real machines is
402
+ a decision to make deliberately (see [wsh and browsermesh](#wsh-and-browsermesh)).
403
+
363
404
  ### Gateway (TCP and DNS egress from the host)
364
405
 
365
406
  `gateway: { allow: ['broker.lan:1883'], allowPrivate: ['10.0.0.0/8'], socks: '127.0.0.1:9050' }` makes the Node server
@@ -623,7 +664,10 @@ bundler drop what you do not use.
623
664
  | `@johnhenry/wsh/memory` | `createMemoryHost()`, a host in this realm (above) |
624
665
  | `@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 |
625
666
  | `@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 }` |
626
- | `@johnhenry/wsh/testing` | the QMux record and frame codec (`encodeStream`, `encodeRecord`, `RecordDecoder`, `decodeFrames`, the varint and the other frame encoders), for a test that reads, alters and re-wraps what travels on a connection. **Experimental: not part of the stable API**; it may change or disappear in any release |
667
+ | `@johnhenry/wsh/testing` | the QMux record and frame codec (`encodeStream`, `encodeRecord`, `RecordDecoder`, `decodeFrames`, the varint and the other frame encoders), for a test that reads, alters and re-wraps what travels on a connection; and two test doubles for code that embeds wsh: `createInProcessPipeRelay({ tap })` (the real pipe relay in this process, with a `WebSocket` that dials it, a record of every message it copied, and a `tap` that may change, drop, repeat or add to what it writes, like a hostile relay) and `createMemoryPair({ host, username })` (a memory host and a client already logged in to it). **Experimental: not part of the stable API**; it may change or disappear in any release. Importing only the codec costs under 1 kB: the doubles are separate exports a bundler drops |
668
+ | `@johnhenry/wsh/identity` | a key in its four spellings, and `authorized_keys` lines: `fingerprint` and `podId` of a raw key, `fingerprintToPodId` / `podIdToFingerprint`, `rawKeyToOpenSsh` / `openSshToRawKey` / `parseOpenSshKey` / `publicKeyToOpenSsh`, `identityOf`, `normalizeIdentity`, `authorizedKeyLine`. Stable; see [Identity and capabilities for other implementations](#identity-and-capabilities-for-other-implementations-220) |
669
+ | `@johnhenry/wsh/capabilities` | `permits(capabilities, request)`: the notation of key capabilities as a pure function, the one `@johnhenry/wsh/server` and the memory host evaluate. Stable; same section |
670
+ | `@johnhenry/wsh/spec/*.json`, `*.md`, `wsh-v1.yaml` | the data files of the specification: `capabilities.md`, `capabilities.vectors.json`, `key-options.vectors.json`, the wire spec |
627
671
  | `@johnhenry/wsh/server` | Node only |
628
672
 
629
673
  ```js
@@ -647,17 +691,20 @@ optional ML-KEM backend, is left out of the measurement. What a page ships is wh
647
691
  <!-- bundle-size:start (generated by `npm run size -- --update`; do not edit) -->
648
692
  | browser bundle | minified | gzip |
649
693
  | --- | ---: | ---: |
650
- | `@johnhenry/wsh` (whole entry point) | 164.0 kB | 49.5 kB |
651
- | `@johnhenry/wsh/memory` (whole entry point) | 231.5 kB | 72.3 kB |
652
- | `@johnhenry/wsh/host` (whole entry point) | 126.1 kB | 41.5 kB |
653
- | `@johnhenry/wsh/reverse` (whole entry point) | 220.0 kB | 68.0 kB |
694
+ | `@johnhenry/wsh` (whole entry point) | 165.8 kB | 50.3 kB |
695
+ | `@johnhenry/wsh/memory` (whole entry point) | 232.6 kB | 72.7 kB |
696
+ | `@johnhenry/wsh/host` (whole entry point) | 127.3 kB | 41.9 kB |
697
+ | `@johnhenry/wsh/reverse` (whole entry point) | 221.1 kB | 68.4 kB |
654
698
  | `@johnhenry/wsh/pipe-relay` (whole entry point) | 7.0 kB | 3.0 kB |
655
- | `@johnhenry/wsh/testing` (whole entry point) | 7.9 kB | 2.6 kB |
656
- | `@johnhenry/wsh/page` (whole entry point) | 285.3 kB | 90.2 kB |
657
- | `@johnhenry/wsh/objects` (whole entry point) | 165.7 kB | 50.8 kB |
699
+ | `@johnhenry/wsh/testing` (whole entry point) | 240.4 kB | 75.7 kB |
700
+ | `@johnhenry/wsh/page` (whole entry point) | 301.5 kB | 95.8 kB |
701
+ | `@johnhenry/wsh/objects` (whole entry point) | 177.4 kB | 54.4 kB |
702
+ | `@johnhenry/wsh/capabilities` (whole entry point) | 10.5 kB | 3.8 kB |
703
+ | `@johnhenry/wsh/identity` (whole entry point) | 15.7 kB | 5.7 kB |
704
+ | `import { encodeRecord } from '@johnhenry/wsh/testing'` | 1.8 kB | 0.9 kB |
658
705
  | `import { generateKeyPair } from '@johnhenry/wsh'` | 0.4 kB | 0.3 kB |
659
706
  | `import { WshClient } from '@johnhenry/wsh'` | 135.9 kB | 40.8 kB |
660
- | `import { createConnectionFactory } from '@johnhenry/wsh/host'` | 102.9 kB | 33.6 kB |
707
+ | `import { createConnectionFactory } from '@johnhenry/wsh/host'` | 104.0 kB | 34.0 kB |
661
708
  <!-- bundle-size:end -->
662
709
 
663
710
  ### Signing with a page-held signer
@@ -745,6 +792,17 @@ marked read-only is consequential; `consequentialHint` forces it), `'always'` be
745
792
  the caller's key fingerprint, shows the input **as text** (nothing is parsed as markup), puts focus on Deny, keeps Tab inside it, treats Escape as Deny,
746
793
  returns focus afterwards and denies after 60 seconds. Questions are asked one at a time. Deny is an MCP error and the tool does not run.
747
794
 
795
+ **Over any duplex, not only a wsh channel (#220).** `webmcpTools(...)` is a handler written for a channel; `serveMcpOverDuplex(handler,
796
+ { send, who, permits })` (also from `@johnhenry/wsh/page`) gives it one made of two functions you already have, so a transport that is not
797
+ wsh at all (a mesh channel, a `MessagePort`) can carry the same tools: feed what arrives to `session.receive(message)`, `send` what goes out,
798
+ `session.close(reason)` when the link ends. **The far side speaks plain MCP**: JSON-RPC 2.0 messages as objects (`{ jsonrpc: '2.0', id, method, params }`
799
+ and the matching result or error, notifications with no `id`; no batches), so an MCP SDK `Client` connects through any `Transport` that moves them.
800
+ The handler's bounds, `approve` and `prompt`, `onCall` and the untrusted labelling are unchanged. The seam adds `maxMessageBytes` (default 1 MiB,
801
+ either direction), `maxInflight` (default 64 requests of any kind), one answer per id, and refuses a message that is not JSON-RPC 2.0. `who` is
802
+ `{ username, fingerprint, podId }` (what the prompt and `onCall` see), and `permits` is asked per tool, so `(req) => permits(caps,
803
+ req)` of `@johnhenry/wsh/capabilities` narrows it by `mcp:TOOL`. **It authenticates and seals nothing**: who is on the other end, and what they
804
+ were granted, are the transport's to establish; they are not in the messages.
805
+
748
806
  **The indicator.** While a session is connected, `window.document` has a visible element (`data-wsh-page="indicator"`, `role="status"`) saying so,
749
807
  with the key's fingerprint and a **Stop** button that calls `revoke`. Stop ends the session (the operator is told why), and that key is refused until the host
750
808
  is closed: a Stop that lets the same key straight back in is not a Stop. If something in the page removes the element while a session is connected it is put back. `indicator: false` is
@@ -780,7 +838,7 @@ earlier load will not match and trust-on-first-use gives no continuity. To keep
780
838
  ### Remote objects: `@johnhenry/wsh/objects` (#190)
781
839
 
782
840
  `wsh-objects` is an rpc protocol that reaches an object graph by path: a page's `window`, a worker's `self`, any object a host names as a **root**. It is `values` mode:
783
- only plain cloneable values ever cross (there are no handles and no callbacks yet; `mode: 'handles'` is refused with a sentence saying it is not built; events are delivered as copies, see below).
841
+ only plain cloneable values ever cross (on a root that has not opted in to [handles](#handles) there are no handles and no callbacks; events are delivered as copies, see below).
784
842
  Nothing is reachable but the named roots, and nothing in them is allowed until an allow-list says so.
785
843
 
786
844
  ```js
@@ -844,8 +902,61 @@ an **emitter's** arguments become `{ type, args }` (what cannot be cloned is `nu
844
902
  does the same). Bounds, by name: `maxSubscriptions` 16 per channel (refused), `maxEventsPerSecond` 20 per subscription, `maxEventBytes` 16384 and `maxQueuedEvents` 100 per channel: an event over any of the last three
845
903
  is **dropped and counted** (the rate and the queue are checked before anything of the event is read or copied, so a dropped event costs a counter), and the next one delivered says how many were lost before it (`dropped`). Events leave as notifications whose write waits for the channel's credit, so a slow reader fills the bounded
846
904
  queue and then loses events, counted, instead of growing the page's memory. Every listener is taken out of the page's sources when the channel ends: the operator leaves, Stop, a navigation, a revoke. An error in the far
847
- side's listener goes to its `onError` and stays there; the host's listener only copies and queues and cannot throw into the page's dispatch. Callbacks as arguments of a call are **not offered** (a function cannot be
848
- sent: it is refused where it is written); the design in #190 describes them as handles, which is the next step.
905
+ side's listener goes to its `onError` and stays there; the host's listener only copies and queues and cannot throw into the page's dispatch. Callbacks as arguments of a call are a separate facility (see [Callbacks](#callbacks)).
906
+
907
+ #### Handles
908
+
909
+ A root can opt in to **handles**: `exposeObjects({ roots, handles: { window: {} }, ... })`, or `createPageHost({ expose: { window: { mode: 'handles', allow } } })`. Values stays the default, and the opt-in is per root.
910
+ On such a root a function or an object that is not plain data (a class instance with state, a `Map`) comes back as an opaque `RemoteHandle` instead of a named non-value, and `use(handle)` makes a reference that stands on it:
911
+
912
+ ```js
913
+ const cart = await win.app.cart; // a RemoteHandle { type: 'Cart' } (what a plain value or a named non-value would have been)
914
+ await use(cart).add({ sku: 'A1' }); // the same object across calls; one request per chain, as ever
915
+ await use(cart).items.length;
916
+ await release(cart); // gives its place back; everything is released when the channel ends
917
+ ```
918
+
919
+ - **The path-bound model.** A handle stands at the **path that produced it**: one got by `get window.app.cart` behaves as `window.app.cart`; one returned by calling `window.app.makeCounter` behaves as `window.app.makeCounter()`
920
+ (the notation values mode uses for results), and its members as `window.app.makeCounter().inc`. Every operation through it is judged by the allow-lists for that path extended by the member, exactly as if the path were written out.
921
+ **A handle never widens what a path grants**: if only `window.app.cart.add` may be called, `use(cart).items` is refused. Allow-list entries can name such paths (`call: ['window.app.makeCounter', 'window.app.makeCounter().inc']`).
922
+ The always-refused names stay refused through a handle, and so do the entries that must name their path (`fetch`, cookies, storage, ...).
923
+ - **A handle is opaque and local.** Its id is 128 random bits (from `crypto.getRandomValues`; the page host uses the served window's). It is meaningful only on the channel that produced it, for the key that holds that channel: another
924
+ channel, another key, a reconnect, or a guess finds nothing (`no such handle`). Nothing of it is enumerable on the far side; it is not thenable, and it cannot be sent as an argument.
925
+ - **Nodes and the window graph.** A DOM node, a window or a document is **not** handed out as a handle (it stays a named non-value) unless the root sets its own opt-in, `nodes: true`, which is control of the page. Even then the members that
926
+ lead back up to the graph (`ownerDocument`, `defaultView`, `parentNode`, `parentElement`, `getRootNode`, `contentWindow`, `contentDocument`, `self`, `window`, `top`, `parent`, `frames`, `opener`, `globalThis`) stay refused
927
+ until an allow-list entry names them; a wildcard does not.
928
+ - **A bounded table.** `maxHandles` (64) per channel, **refused by name on overflow, never evicted**; `release(handle)` is explicit; all of them go when the channel ends (the operator leaving, Stop, a navigation, a revoke). A far side's
929
+ garbage-collection hints would be advisory only; none is used.
930
+ - **Previews.** `handle.preview` (a bounded list of up to 8 member names) is present only if a `get` entry names the handle's path, and lists only the names `describe(use(handle))` would list: those the allow-lists could walk to from there. Otherwise a handle says its type and nothing more.
931
+ - **Wide entries need an acknowledgement.** A wildcard (`*` or `**`) in `allow.call` or `allow.set` on a handles root lets a caller hold and reuse every object under it, so the host refuses to start with one unless the root says
932
+ so, `handles: { window: { wideEntries: true } }` (in `createPageHost`, `wideEntries: true` beside `mode: 'handles'`), or lists the paths. A wildcard in `get` alone needs no acknowledgement. A values root is not affected.
933
+ - **Capabilities.** `objects:ROOT[:OP]` apply unchanged: an operation through a handle is the same `get`, `call`, `set` of the producing path (a key with `objects:window:get` can read through a handle and cannot call through it).
934
+ - **What a handle is not.** The host's real object stays in the page: calling a method runs the page's code with the caller's plain-data arguments, as for any `call`; a handle to an object with a powerful method is as powerful as that method's entry in `call`. A handle is
935
+ a reference to something already reachable by a path, so it cannot reach more than the path's own entries; but a wide entry (`window.app.**`) covers every member of every object under it. Events are not offered through a handle, and callbacks are not built.
936
+
937
+ A host says what it supports with its roots (`features`: `events`, `callbacks`, and `handles` when a root opted in). A client does not send a function to a host that has not said it supports callbacks, nor use events on one that has not said so (a named `unsupported` error);
938
+ a handle-shaped answer from a host that never said it supports handles is the same error. A 0.47.0 host says nothing, so it counts as supporting none of them.
939
+
940
+ #### Callbacks
941
+
942
+ A far-side **function passed as an argument** of a call is a callback, but only where the call's allow-list entry says so by ending in `(callback)`: `allow.call: ['window.app.subscribe(callback)']`. A call entry without it refuses a function
943
+ argument (`does not accept callbacks`), and a function nested inside an argument, a remote reference and a handle are refused where they are written. The page then receives a **stub**, a plain function it may keep and call:
944
+
945
+ ```js
946
+ await win.app.subscribe((event) => console.log(event.n)); // the page's subscribe(fn) gets a stub; fn runs here, on the far side
947
+ await release(fn); // kills the stub (also: the channel ending)
948
+ ```
949
+
950
+ - **One-way.** The stub copies its arguments, queues a notification and **returns `undefined` at once**: the page cannot be made to wait for the far side, and the far side's return value is not delivered back (a notation to ask for it is not built).
951
+ - **Plain values only.** The arguments are copied under the same rules as a result: plain data and bytes; what cannot be cloned (a function, a node, a class instance, a date) is `null`; never a handle.
952
+ - **Bounds.** `maxCallbacks` (16 per channel, refused by name), `maxCallbacksPerSecond` (20 per callback), `maxCallbackBytes` (16384 per call); a call over the rate, the size or the shared queue (`maxQueuedEvents`) is dropped and counted, and the next delivered call is preceded by
953
+ `onCallbackDropped({ dropped })` on the client. The notifications go through the channel's credit like events. The same function sent again is the same callback.
954
+ - **Dead after the session.** A stub is dead after the channel ends (the operator leaving, Stop, a navigation, a revoke) and after `release(fn)`: calling it does nothing and is counted. A listener that throws on the far side goes to `onCallbackError` and never reaches the page.
955
+ - The call with callbacks is a `call` for `authorize` (`op.callbacks` is how many) and for the key's `objects:ROOT:call` capability. A callback is a channel for the page's own code to push plain values to the caller: it can send whatever the page's code puts in it, within the bounds, so list `(callback)` only on calls whose
956
+ stub the page will use for what the caller should see.
957
+
958
+ **The indicator is best effort.** The page host shows a visible element while a session is connected, puts it back if the page removes it, and has a Stop button. Page code can always remove or cover a DOM element, and a tool or a
959
+ function the caller may call runs with the page's authority. What holds is **Stop and revoke** (they close the channel from the page's own code, whatever is on screen) and **the key's capabilities and the host's allow-lists**.
849
960
 
850
961
  **Threat model of `values` mode.** An allow-list of paths means what it says **only because nothing but cloneable values crosses**: a result can never be walked somewhere else, so what a session can
851
962
  reach is exactly the paths the lists name (and, below a `get`, the plain data inside that value). That holds up to what the named paths themselves do:
@@ -862,9 +973,9 @@ reach is exactly the paths the lists name (and, below a `get`, the plain data in
862
973
  written by third parties.
863
974
  - A sealed session, a key login and a visible indicator (the page host) are what keep a relay and an unknown caller out; `authorize` is where an embedder asks the person.
864
975
 
865
- Types: `@johnhenry/wsh/objects` ships `.d.ts` (`client.openObjects<T>()` types the roots; references are untyped). Size: `@johnhenry/wsh/objects` is 50.8 kB gzipped (it contains the client), and
866
- the page entry point is 90.2 kB with it; no other entry point changed. A capability per root and operation (`objects:ROOT[:OP]`) is described under [per-key capabilities](#authorized-key-options-122).
867
- Not built yet (later steps of #190): handles for what cannot be cloned, callbacks as arguments, typed remotes (`Remote<T>`), an MCP face for the allow-listed paths, and a dial-out form.
976
+ Types: `@johnhenry/wsh/objects` ships `.d.ts` (`client.openObjects<T>()` types the roots; references are untyped). Size: `@johnhenry/wsh/objects` is 53.4 kB gzipped (it contains the client), and
977
+ the page entry point is 93.1 kB with it; no other entry point changed. A capability per root and operation (`objects:ROOT[:OP]`) is described under [per-key capabilities](#authorized-key-options-122).
978
+ Not built yet (later steps of #190): typed remotes (`Remote<T>`), an MCP face for the allow-listed paths, and a dial-out form.
868
979
 
869
980
  ### WebTransport listener
870
981
 
@@ -1500,6 +1611,8 @@ An MCP client configuration:
1500
1611
  { "mcpServers": { "remote": { "command": "wsh-mcp", "args": ["--identity", "/home/me/.wsh/keys/default.pem", "--host-key", "<fingerprint>", "wss://host.example:4422"] } } }
1501
1612
  ```
1502
1613
 
1614
+ **Dialling a host behind a pipe relay (a pod's services host, a page host).** Both CLIs dial the operator side of a [pipe relay](#a-pipe-relay-johnhenrywshpipe-relay-118) directly. `wsh-mcp` takes the relay URL as its URL, since that is a `ws://` / `wss://` URL: `wsh-mcp --sealed --host-key <host fingerprint> --identity KEY wss://relay.example/r/<rendezvous id>` (the URL must end in `/r/<22-128 base64url characters>` and must not be the `?role=host` one). The Rust `wsh` has a flag for it: `wsh --sealed --via wss://relay.example/r/<id> mcp user@host` (and `wsh --via wss://relay.example/r/<id> user@host [command...]`), where `user@host` stays the identity the host key is recorded under. A host behind a relay that is a page or a mesh peer serves sealed sessions only, so pass `--sealed` and pin `--host-key`.
1615
+
1503
1616
  stdout carries MCP messages only (one JSON-RPC message per line); every diagnostic goes to stderr. Exit status: `0` the client closed
1504
1617
  its side, `1` the host was lost for good, `2` it could not start -- no connection, a refused login or host key, or **a host that offers
1505
1618
  no such channel** (the error lists the channels it does offer and how to serve one). After a dropped connection it reconnects (5
@@ -2227,7 +2340,8 @@ than left to be found.
2227
2340
  | `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` |
2228
2341
  | `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 |
2229
2342
  | `authorized_keys` options (#122): `restrict`, `permit-*`, `no-pty`, `command=`, `max-sessions=` | `auth.authorizedKeys` lines with options on `createWshServer` / `createMemoryHost`; `parseAuthorizedKeyEntries()` | `wsh-server` reads `~/.wsh/authorized_keys` (then `~/.ssh/authorized_keys`) | **Same rules and the same vectors on both hosts** (`spec/key-options.vectors.json`, run by the JS suite and a Rust test); an option that is not understood keeps the key out, on both. See [Authorized-key options](#authorized-key-options-122) for the per-host column |
2230
- | Per-key capabilities and expiry (#122): `capabilities="..."`, `expires="..."`; `authorize()` may return a set | every entry the host has: `Open` kinds, `FileOp` read vs write, gateway TCP/UDP/unix/endpoint open and listen, MCP discovery and calls, targets, rpc channels, relay; refusals through `onRefused` (`not-permitted`, `key-expired`) | the same, except **no endpoints and no targets** (`endpoint:` / `target:` parse and grant nothing; such requests are refused); refusals are logged, there is no callback; no `authorize` | **Same grammar, same vectors, same refusal codes on both hosts**; default-deny only for a key whose line has `capabilities`. Neither covers sessions already open, see [Security model](#security-model) |
2343
+ | Per-key capabilities and expiry (#122): `capabilities="..."`, `expires="..."`; `authorize()` may return a set | every entry the host has: `Open` kinds, `FileOp` read vs write, gateway TCP/UDP/unix/endpoint open and listen, MCP discovery and calls, targets, rpc channels, relay; refusals through `onRefused` (`not-permitted`, `key-expired`) | the same, except **no endpoints and no targets** (`endpoint:` / `target:` parse and grant nothing; such requests are refused); refusals are logged, there is no callback; no `authorize` | **Same grammar, same vectors, same refusal codes on both hosts**; default-deny only for a key whose line has `capabilities`. Neither covers sessions already open, see [Security model](#security-model). The notation is written in `spec/capabilities.md` and its vectors (`spec/capabilities.vectors.json`, `version` 1) ship in the npm package and are run by both; the Rust server's subset is stated by refusal: a key line with an `objects:` capability is refused at load (`unknown-capability`) |
2344
+ | `permits(capabilities, request)`, `@johnhenry/wsh/identity` (fingerprint, pod id, OpenSSH line, `authorized_keys` line builder), the `GATEWAY_FAIL` table, `serveMcpOverDuplex`, `createDuplexPeer({ who, permit })` (#220) | exported pure functions and seams of the JS package, browser-safe | none: the Rust server and CLI export no library function of these; the Rust server sends the same `GatewayFail` numbers, with `5` meaning "gateway disabled" where the Node gateway sends it for a timeout | **Notation unified by vectors**; the functions are the JS implementation's and are not a wire feature |
2231
2345
  | 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 |
2232
2346
  | Self-signed cert pinning | `serverCertificateHashes` (WebTransport option) | `--cert-hash <sha256>` (repeatable) and `ConnectConfig.cert_hash`/`cert_hashes`, with the same rules (SHA-256, ECDSA P-256, at most 14 days); `wsh-server` prints its certificate hash at start-up. Without a pin the certificate is validated against the system trust store; `--insecure-skip-cert-verification` is the development-only opt-out | **Not a wire concept**; a default changed in the Rust client, see the CHANGELOG |
2233
2347
 
@@ -2400,8 +2514,14 @@ out explicitly below rather than left to be discovered.
2400
2514
  third-party text and are untrusted to the MCP client; the dialog and the indicator belong to the page and are not a defence against code
2401
2515
  already in it; a fresh host key per page load means no pin outlives it unless `hostKeyStore` is given) are stated in
2402
2516
  [A page as a host](#a-page-as-a-host-johnhenrywshpage-190).
2517
+ - **Objects and MCP over a transport that is not wsh (`createDuplexPeer`, `serveMcpOverDuplex`, #220) are only as authenticated as that transport.** The
2518
+ identity they hand to `authorize(who, op)`, a prompt and `onCall` is whatever the adapter gave (`who`, `permit`, `permits`): `fingerprint` and `podId`
2519
+ are checked to agree, nothing else is verified, and the messages carry no proof of either. They bound what they receive (message size, requests in
2520
+ flight, one answer per id), refuse what is not the protocol, and fail closed when a `permit` throws or answers anything but `true`; they do not seal, and
2521
+ a hop that can read the duplex reads every tool result and every value. The capability notation (`spec/capabilities.md`) is a **reading** of a list, not a
2522
+ credential: an implementation that reads it more loosely than the vectors say grants more than the list does, which is why the vectors are shipped.
2403
2523
  - **`wsh-objects` (`@johnhenry/wsh/objects`, #190) lets a key read, call and set the paths an allow-list names on the roots a host names, and nothing else.** An allow-list of paths means what it says
2404
- only because nothing but cloneable values crosses (no handles in `values` mode); what it cannot make safe is stated in
2524
+ only because nothing but cloneable values crosses (no handles in `values` mode; on a root that opted in to [handles](#handles), a handle is judged by the path that produced it and never widens it, and nodes need their own opt-in); what it cannot make safe is stated in
2405
2525
  [Remote objects](#remote-objects-johnhenrywshobjects-190): a getter or a setter on an allowed path runs, a called function does whatever it does with the page's authority, a wide pattern means its width, and a
2406
2526
  few paths (`document.cookie`, storage, `fetch`, ...) need an entry that names them. Object access is off on every host unless `exposeObjects` or `createPageHost({ expose })` is written, and `rpc:wsh-objects` is the key capability that gates it.
2407
2527
  - **`wsh-mcp` runs as a client with your key (#127).** It reads a private key file you point it at (no passphrase support: protect the
@@ -2722,30 +2842,55 @@ The bundle-size report is described under [Browser entry points](#browser-entry-
2722
2842
  ## Related projects
2723
2843
 
2724
2844
  - **[`@johnhenry/browsermesh-netway`](https://github.com/johnhenry/browsermesh)** takes a `WshClient` as its gateway backend
2725
- (see [Family](#family) below).
2845
+ and the rest of browsermesh meets wsh in several places (see [wsh and browsermesh](#wsh-and-browsermesh)).
2726
2846
  - **The Rust crates** in [`crates/`](crates) (`wsh-core`, `wsh-client`, `wsh-cli`, `wsh-server`) are a native
2727
2847
  implementation of the same wire protocol, versioned separately (`rust-v*` tags) and generated from the same
2728
2848
  `spec/wsh-v1.yaml`; see [Rust implementation](#rust-implementation) for what each side can do.
2729
2849
  - **[clawser](https://github.com/erisera-code/clawser)** downloads the Rust release binaries by their archive names and is
2730
2850
  where the Rust workspace came from.
2731
2851
 
2732
- ## Family
2733
-
2734
- wsh isn't just a standalone remote-shell client -- its `WshClient` is the
2735
- designed transport backing one sibling package's network gateway, and
2736
- `WshClient`'s connected/authenticated shape is a drop-in for that sibling's
2737
- injected-client extension point.
2738
-
2739
- - **[`@johnhenry/browsermesh-netway`](https://github.com/johnhenry/browsermesh)**
2740
- -- browsermesh-netway's `GatewayBackend` takes a `wshClient` in its
2741
- constructor and proxies every network operation (socket open/send/close)
2742
- through it via `sendControl()`, once the client reaches the
2743
- `'authenticated'` state (`isReady()` checks exactly that). This is a real,
2744
- verified dependency on wsh's client shape -- `GatewayBackend` is
2745
- duck-typed against a `WshClient` instance, not declared as an npm
2746
- dependency -- not a thematic pairing; see
2747
- `packages/browsermesh-netway/src/gateway-backend.mjs` in the browsermesh
2748
- repo. wsh itself has no dependency in the other direction.
2852
+ ## wsh and browsermesh
2853
+
2854
+ **wsh** is the authenticated, capability-scoped door into **one machine or one page**: a key login in both directions, a host key a dialler
2855
+ can pin, a session sealed end to end, and what a key may do written down as capabilities. **[browsermesh](https://github.com/johnhenry/browsermesh)**
2856
+ is the **peer fabric**: pods that find each other, link, route messages and share state, with no machine at the centre. One is a way
2857
+ into a place; the other is the place between places. They are separate packages with separate versions, and **wsh has no dependency on
2858
+ browsermesh** (a test of the pod id derivation uses `@johnhenry/browsermesh-primitives` as a dev dependency only).
2859
+
2860
+ **Where they meet**
2861
+
2862
+ - **The mesh's wsh peer link** (`@johnhenry/browsermesh-transport`, off by default): a link between two pods is one wsh session, sealed and
2863
+ authenticated in both directions, carrying one named endpoint (`mesh`) on which the mesh's frames travel. A pod's Ed25519 key is its wsh
2864
+ login; the pod id it claims must equal the hash of the key wsh authenticated. wsh supplies the session (login, host key, seal, endpoints);
2865
+ the mesh supplies the frames. `@johnhenry/wsh/identity` is where the pod id and the fingerprint convert.
2866
+ - **The relay's pipe route**: browsermesh's relay server serves wsh's [pipe relay](#a-pipe-relay-johnhenrywshpipe-relay-118) (rendezvous and
2867
+ byte copying, no keys), so two pods that cannot reach each other directly still run the ordinary wsh handshake end to end. `@johnhenry/wsh/testing`
2868
+ has the same relay in process, with a tap for a hostile one, as a test double.
2869
+ - **netway's gateway backend** (`@johnhenry/browsermesh-netway`): its `GatewayBackend` takes a `WshClient` and proxies every network
2870
+ operation through the host's [gateway](#gateway-tcp-and-dns-egress-from-the-host); it decodes the `GatewayFail` codes of
2871
+ `GATEWAY_FAIL` / `GATEWAY_FAIL_TABLE`, exported here as data so there is one table.
2872
+ - **Objects and MCP over a mesh channel**, through the browsermesh adapter package (a separate, small package that peer-depends on
2873
+ `@johnhenry/wsh`): a page's [remote objects](#remote-objects-johnhenrywshobjects-190) and WebMCP tools reachable over a protocol channel
2874
+ with no wsh relay. wsh exports the seams it needs: `createDuplexPeer({ send, who, permit })` and `createObjectsServer(...).attach` for objects,
2875
+ `serveMcpOverDuplex` for MCP, the identity object `{ username, fingerprint, podId }`, and `permits()` of the
2876
+ [capability notation](#identity-and-capabilities-for-other-implementations-220), which the mesh's own grants run the same vectors against.
2877
+
2878
+ **What is deliberately not shared**
2879
+
2880
+ - **Sealing.** A wsh session is sealed once, after a signed key exchange, and everything after login travels in authenticated frames; the
2881
+ mesh seals one-shot routed messages in its own way. They are two schemes for two shapes of traffic, and neither is built on the other.
2882
+ - **Wire codecs and addressing.** wsh speaks CBOR messages over QMux (WebSocket or WebTransport streams) and is reached by a URL or a rendezvous
2883
+ id; the mesh has its own encodings and names pods by id. Neither adopts the other's.
2884
+ - **Exec and hosted pods.** Shells, commands, files and the gateway are wsh's; running things for other pods and hosting them is the mesh's.
2885
+ Discovery and state sync stay in the mesh.
2886
+ - **Machine rights from mesh trust.** Being a peer of a pod, or holding a mesh grant, never gives a key exec, files or the gateway on a
2887
+ machine. What a mesh grant can reach in a page is objects and MCP tools only, and only what that page's host opted in to.
2888
+
2889
+ **One key in both worlds is possible, never automatic.** A pod's key can be exported as an OpenSSH line and a key from `authorized_keys`
2890
+ can be imported as a pod identity (`rawKeyToOpenSsh`, `openSshToRawKey`), explicitly. Do not do it for a key that is stored in a browser
2891
+ and valid on real machines: a key that can open a shell somewhere should not also be the identity a page presents to every peer it meets.
2892
+ Capabilities from the mesh are written as an `authorized_keys` line only by `authorizedKeyLine`, which refuses a line that grants
2893
+ more than it was asked for.
2749
2894
 
2750
2895
  ## License
2751
2896
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnhenry/wsh",
3
- "version": "0.47.0",
3
+ "version": "0.49.0",
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",
@@ -44,7 +44,18 @@
44
44
  "./mcp-stdio": {
45
45
  "types": "./src/mcp-stdio.d.ts",
46
46
  "import": "./src/mcp-stdio.mjs"
47
- }
47
+ },
48
+ "./capabilities": {
49
+ "types": "./src/capabilities.d.ts",
50
+ "import": "./src/capabilities.mjs"
51
+ },
52
+ "./identity": {
53
+ "types": "./src/identity.d.ts",
54
+ "import": "./src/identity.mjs"
55
+ },
56
+ "./spec/*.json": "./spec/*.json",
57
+ "./spec/*.md": "./spec/*.md",
58
+ "./spec/wsh-v1.yaml": "./spec/wsh-v1.yaml"
48
59
  },
49
60
  "bin": {
50
61
  "wsh-mcp": "./bin/wsh-mcp.mjs"
@@ -54,6 +65,9 @@
54
65
  "files": [
55
66
  "src",
56
67
  "bin",
68
+ "spec/*.json",
69
+ "spec/*.md",
70
+ "spec/wsh-v1.yaml",
57
71
  "LICENSE",
58
72
  "README.md"
59
73
  ],
@@ -83,7 +97,7 @@
83
97
  "devDependencies": {
84
98
  "@fails-components/webtransport": "^1.6.4",
85
99
  "@fails-components/webtransport-transport-http3-quiche": "^1.6.4",
86
- "@johnhenry/browsermesh-primitives": "^0.2.0",
100
+ "@johnhenry/browsermesh-primitives": "^0.5.0",
87
101
  "@playwright/test": "^1.65.1",
88
102
  "esbuild": "^0.28.2",
89
103
  "typescript": "^7.0.0",
@@ -0,0 +1,174 @@
1
+ # wsh key capabilities: notation and evaluation
2
+
3
+ Version 1 of the notation (the `version` field of `capabilities.vectors.json`).
4
+
5
+ This document states, in one place, what a capability list means: the grammar of one capability, what the wildcards
6
+ match, how a request is checked against a list, and what an implementation does with something it does not understand.
7
+ It is written so that an implementation other than `@johnhenry/wsh` (the Rust `wsh-server`, a mesh registry in another
8
+ package) can be tested against the same vectors and agree. The words MUST and MUST NOT are meant as in RFC 2119.
9
+
10
+ Two files go with it and are published in the npm package:
11
+
12
+ - `spec/capabilities.vectors.json` (`@johnhenry/wsh/spec/capabilities.vectors.json`): "does a holder of list L permit
13
+ request R" as data. The JS evaluation (`permits` in `@johnhenry/wsh/capabilities`) and the Rust `wsh-server` run
14
+ these vectors in their own test suites. An implementation claims conformance by passing the cases that name its host
15
+ class (see "Host classes").
16
+ - `spec/key-options.vectors.json`: the `authorized_keys` option syntax (`restrict`, `permit-*`, `command=`,
17
+ `capabilities=`, `expires=`) and the checks of the options themselves. Capabilities are one option of that line.
18
+
19
+ ## Where a list comes from
20
+
21
+ A capability list is an ordered collection of strings. It reaches an implementation from:
22
+
23
+ - the `capabilities="a,b,c"` option of an `authorized_keys` line (a comma-separated string);
24
+ - the value an `authorize()` callback of a host returns instead of `true` (`{ capabilities: 'a,b' | ['a', 'b'], expires }`);
25
+ - a registry of grants in another system that uses the same notation.
26
+
27
+ The list is **default-deny**: a holder may do exactly what an entry names and nothing else. An empty list (`capabilities=""`)
28
+ permits nothing. A key line that has no `capabilities` option has no list and is limited by its other options only
29
+ (`restrict`, `permit-*`, `command=`, `max-sessions=`); `permits()` of the JS package treats "no list" as "no grant"
30
+ (it returns `false`), because the meaning "this key carries no list" belongs to the options layer.
31
+
32
+ ## Grammar
33
+
34
+ ```
35
+ capability = simple / gateway / unix / named / objects
36
+ simple = "exec" / "pty" / "relay" / "fs:read" / "fs:write"
37
+ gateway = "gateway:tcp:" hostport / "gateway:udp:" hostport / "gateway:listen:tcp:" port
38
+ unix = "unix:" path / "unix:listen:" path
39
+ named = ("endpoint:" / "target:" / "mcp:") name-or-star / "rpc:" name
40
+ objects = "objects:" root [ ":" op ]
41
+ hostport = host ":" port
42
+ host = "*" / "*." domain / domain / "[" ipv6 "]"
43
+ port = "*" / 1..65535 ; decimal, no leading zero
44
+ path = "/*" / dir "/*" / dir ; absolute, see below
45
+ op = "get" / "call" / "set" / "on"
46
+ ```
47
+
48
+ - **Whitespace** anywhere in an entry, an empty entry, or an entry that is not a string makes the whole list invalid
49
+ (`bad-capability`).
50
+ - `domain`: letters, digits, `.`, `_` and `-`, starting and ending with a letter or digit. A host is compared case
51
+ insensitively (the pattern is lower-cased when parsed, the request's host when checked).
52
+ - IP literals: an IPv4 address is a `domain`; an IPv6 address is written in brackets (`[::1]`) in the capability, and a
53
+ request's `host` may be given with or without the brackets.
54
+ - `name` (of `endpoint:`, `target:`): 1 to 64 characters, letters, digits, `.`, `_`, `-`, starting with a letter or digit.
55
+ `tool` (of `mcp:`): 1 to 128 characters of letters, digits, `_`, `.`, `:`, `-`, not starting with `.`, `:` or `-`.
56
+ `rpc:NAME` follows the `name` rule and has **no** `*` form.
57
+ - `root` (of `objects:`): `*`, or 1 to 64 characters of letters, digits, `_`, `$`, `-`, starting with a letter, `_` or `$`.
58
+ - `path`: absolute (`/` first), no empty, `.` or `..` segment, none of space or control characters, `,`, `"`, `'`, `\`.
59
+
60
+ ## What a wildcard matches
61
+
62
+ There is no general glob. A `*` is only meaningful in the positions below; anywhere else the entry is `bad-capability`.
63
+
64
+ | Where | Pattern | Matches | Does not match |
65
+ | --- | --- | --- | --- |
66
+ | host | `*` | every host | |
67
+ | host | `*.example.com` | `a.example.com`, `a.b.example.com` | `example.com` (the apex), `evilexample.com`, `example.com.evil.net` |
68
+ | host | `db.internal` | `db.internal`, `DB.Internal` | any other name |
69
+ | port | `*` | every port | |
70
+ | port | `443` | `443` | any other port |
71
+ | path | `/srv/*` | any path below `/srv` (`/srv/a`, `/srv/a/b.sock`) | `/srv` itself, `/srvx/a`, a path with `.` or `..` |
72
+ | path | `/*` | any absolute path with at least one segment | `/` |
73
+ | path | `/run/app.sock` | exactly that path | any other path |
74
+ | `endpoint:` `target:` `mcp:` | `*` | every name | |
75
+ | `endpoint:` `target:` `mcp:` | `logs` | exactly `logs` (case sensitive) | `Logs`, `logs2` |
76
+ | `objects:` root | `*` | every root | |
77
+ | `objects:` root | `window` | exactly `window` | `windows` |
78
+ | `objects:` operation | absent | all four operations (`get`, `call`, `set`, `on`) and walking | |
79
+ | `objects:` operation | `get` | `get`, and walking toward something (`walk`) | `call`, `set`, `on` |
80
+
81
+ A request path with a `.` or `..` segment, an empty segment, or one that is not absolute matches no path capability.
82
+ A wildcard never matches across a different capability kind: `gateway:tcp:*:*` does not allow UDP, `gateway:*` is not a
83
+ capability, `unix:` does not grant `unix:listen:`.
84
+
85
+ ## Requests, and what each needs
86
+
87
+ A request is an object with a `kind`. The capability needed (the name a refusal reports in `capability`) is:
88
+
89
+ | Request | Needs |
90
+ | --- | --- |
91
+ | `{ kind: 'open', channel: 'pty' }` | `pty` |
92
+ | `{ kind: 'open', channel: 'exec' }` | `exec` |
93
+ | `{ kind: 'open', channel: 'file', direction: 'download' }` | `fs:read` |
94
+ | `{ kind: 'open', channel: 'file', direction: 'upload' }` | `fs:write` |
95
+ | `{ kind: 'open', channel: 'rpc', protocol: 'wsh-fs' }` | `fs:read` and `fs:write` |
96
+ | `{ kind: 'open', channel: 'rpc', protocol: 'mcp' }` | `mcp:*` (an `mcp:TOOL` key opens it only through a handler that narrows by tool itself, `scoped: true`) |
97
+ | `{ kind: 'open', channel: 'rpc', protocol: 'wsh-objects', scoped: true }` | `rpc:wsh-objects` or any `objects:` entry |
98
+ | `{ kind: 'open', channel: 'rpc', protocol: P }` | `rpc:P` |
99
+ | `{ kind: 'file-op', op }` | `fs:read` for `stat`, `list`, `read`; `fs:write` for every other `op` |
100
+ | `{ kind: 'mcp' }` (discovery) | any `mcp:` entry |
101
+ | `{ kind: 'mcp-call' | 'mcp-tool', tool }` | `mcp:TOOL` or `mcp:*` |
102
+ | `{ kind: 'objects', root, op }` | `objects:ROOT[:OP]` that names `root` and `op` (see below) |
103
+ | `{ kind: 'relay' }` | `relay` |
104
+ | `{ kind: 'key-admin' }` | nothing can: a key with a list may never install another key |
105
+ | `{ kind: 'tcp' \| 'udp', host, port }` | `gateway:tcp:` / `gateway:udp:` with a matching host and port |
106
+ | `{ kind: 'dns', name }` | a `gateway:tcp:` entry whose host matches `name` (any port) |
107
+ | `{ kind: 'listen-tcp', port }` | `gateway:listen:tcp:` with a matching port |
108
+ | `{ kind: 'unix' \| 'listen-unix', path }` | `unix:` / `unix:listen:` with a matching path |
109
+ | `{ kind: 'endpoint', name }` | `endpoint:NAME` or `endpoint:*` |
110
+ | `{ kind: 'target', name }` | `target:NAME` or `target:*` |
111
+
112
+ A request of `kind` `open`, `file-op` or `endpoint` MAY carry `target`: the execution target it names. Then the list
113
+ needs `target:NAME` (or `target:*`) in addition to the capability above. A request with no `target` (the host's own
114
+ backends) needs no `target:` entry. A request of a `kind` not in this table is refused, whatever the list holds.
115
+
116
+ ### Objects
117
+
118
+ `objects:ROOT[:OP]` scopes the remote-object protocol `wsh-objects`:
119
+
120
+ - a request is `{ kind: 'objects', root, op }` with `op` one of `get`, `call`, `set`, `on`, or `walk` (reading on the way to
121
+ something else). `describe` and `snapshot` are `get`; a `construct` is a `call`;
122
+ - `objects:ROOT` (no operation) covers every operation on `ROOT`; `objects:ROOT:get` covers `get` and `walk` on `ROOT`;
123
+ - a list that has **no** `objects:` entry is limited by `rpc:wsh-objects` alone: all roots, every operation (the behaviour
124
+ before `objects:` existed). A list that names any `objects:` entry is limited to what its `objects:` entries name,
125
+ whatever `rpc:wsh-objects` says;
126
+ - the capability decides what a key MAY do on a root; the host's own allow-lists and `authorize()` decide what exists.
127
+ Both must allow.
128
+
129
+ ## Order of the checks
130
+
131
+ 1. **Expiry.** A key with an `expires` timestamp (RFC 3339, `2030-01-01T00:00:00Z`; an offset is honoured; fractional seconds
132
+ are dropped; lower-case `t`/`z`, a date without a time and leap seconds are refused as `bad-value`) is refused
133
+ with `key-expired` at the instant it is reached (`now >= expires`), for every request including the login.
134
+ 2. **The options**: `restrict` and the `permit-*` flags, `command=`, `max-sessions=` (see `key-options.vectors.json`).
135
+ `restrict` alone grants nothing; each `permit-*` flag grants one family back; `command="..."` ties the key to one
136
+ command. The options are checked before the capabilities, so an option that refuses wins over a capability that would grant.
137
+ 3. **The capability list**, when the key has one. A request that no entry covers is refused with `capability-missing`,
138
+ and the refusal names the capability that was needed (`refusal.capability`, e.g. `gateway:tcp:db.internal:22`).
139
+
140
+ `expires` and the options are properties of the key, not entries of the list; `permits()` of the JS package takes `expires`
141
+ and `now` as options and evaluates the list only.
142
+
143
+ ## Unknown and malformed entries: fail closed
144
+
145
+ An implementation MUST NOT skip an entry it does not understand and grant the rest:
146
+
147
+ - an entry that matches no known form is `unknown-capability` (`capabilities="exec,teleport"`);
148
+ - an entry of a known form with a bad argument is `bad-capability` (`gateway:tcp:host` with no port, `objects:window:fly`);
149
+ - either one invalidates the whole list: the key is refused outright (the host does not load it), and `permits()` returns
150
+ `false` for every request.
151
+
152
+ A newer revision of the notation will add forms; an implementation of this revision therefore refuses a list that uses
153
+ them, and a list is only as portable as the oldest implementation that will read it.
154
+
155
+ ## Host classes
156
+
157
+ Not every implementation serves every capability. A vector case names the host classes it applies to in `hosts`
158
+ (default: all of them):
159
+
160
+ - `node`: the JS implementation (`@johnhenry/wsh/server`, the memory host, the page host) and anything that adopts the JS
161
+ evaluation.
162
+ - `rust`: the Rust `wsh-server`. It has no named endpoints, no execution targets and no `wsh-objects`.
163
+
164
+ The Rust server states its subset by refusing, not by ignoring: a key line with an `objects:` entry is refused at load with
165
+ `unknown-capability`. That is the conservative choice: a capability that is silently ignored would look like a grant that
166
+ was withheld, and a key that is meant for a page would sit unnoticed on a machine whose server cannot honour it. The
167
+ vectors record this as `rust` outcomes of the `lists` cases. `endpoint:` and `target:` entries parse on both; the Rust
168
+ server serves neither, so its request vectors for them carry `hosts: ["node"]`.
169
+
170
+ ## What the vectors do not pin
171
+
172
+ - Which request kinds an implementation can issue. A vector marked `node` is not a promise that every Node host issues it.
173
+ - The wording of a refusal `reason`; only `code` and `capability` are stable.
174
+ - Anything about how a list is transported (the `capabilities=` quoting is the options syntax of `key-options.vectors.json`).