@nac3/runtime 2.9.0 → 2.9.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/CHANGELOG.md +87 -0
- package/README.md +9 -0
- package/SPEC.md +1 -1
- package/contract-head.json +4 -4
- package/dist/cli-levels.json +1 -1
- package/dist/cli.js +5 -2
- package/dist/nac-chat-client.browser.js +19 -6
- package/dist/nac-chat-client.cjs +19 -6
- package/dist/nac-chat-client.mjs +19 -6
- package/dist/nac-mcp-interop.browser.js +83 -3
- package/dist/nac-mcp-interop.cjs +83 -3
- package/dist/nac-mcp-interop.mjs +83 -3
- package/dist/nac-v2-extensions.d.ts +1 -1
- package/dist/nac.browser.js +273 -66
- package/dist/nac.cjs +273 -66
- package/dist/nac.d.ts +1 -1
- package/dist/nac.mjs +273 -66
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,92 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.9.1 -- 2026-11-28
|
|
4
|
+
|
|
5
|
+
A PATCH release, and every line of it came from an adversarial review
|
|
6
|
+
of the published 2.9.0 run on 2026-11-28. Nine findings, nine fixes,
|
|
7
|
+
no new capability and no change to the contract's vocabulary. Two were
|
|
8
|
+
security defects with a proof-of-concept that ran before the fix was
|
|
9
|
+
written.
|
|
10
|
+
|
|
11
|
+
### The two that were exploitable
|
|
12
|
+
|
|
13
|
+
**`edit_field` executed its own argument (XSS).** The editor built its
|
|
14
|
+
title with `innerHTML` and concatenated the `nac_id` into it, so an id
|
|
15
|
+
carrying markup ran. The pattern is the one the spec asks adopters for
|
|
16
|
+
-- ids built from data, `"row." + title` -- which makes a user-supplied
|
|
17
|
+
title a stored XSS triggered when an agent opens that row's editor.
|
|
18
|
+
Measured in Chromium: `data-nac-id='row.<img src=x onerror=...>'` plus
|
|
19
|
+
`NAC.edit_field(thatId)` set the flag. The title is now written as
|
|
20
|
+
text, the way `toast()` and `confirm_dialog()` already did -- the same
|
|
21
|
+
`<span class="title">`, same styling.
|
|
22
|
+
|
|
23
|
+
**The interop sent the host's bearer wherever the peer pointed.**
|
|
24
|
+
`import_remote_tree(payload, conn)` takes the connection from the HOST
|
|
25
|
+
and the payload from the PEER; the ack subscription was built from
|
|
26
|
+
`payload.ack_endpoint` and carried `conn.bearer` on the query string,
|
|
27
|
+
with no same-origin check. A peer could name its own collector and the
|
|
28
|
+
browser delivered the credential. Now the credential travels only to
|
|
29
|
+
the origin of `conn.endpoint`, or to an endpoint the host names itself
|
|
30
|
+
in the new `conn.ack_endpoint`. A same-origin `ack_endpoint` -- the
|
|
31
|
+
shape every real bridge has -- still works. A cross-origin one is
|
|
32
|
+
refused by name on the handle (`handle.ack_refused`) and announced as
|
|
33
|
+
`nac:interop:ack_refused`, never in silence. The bearer still rides the
|
|
34
|
+
query string, because `EventSource` cannot carry headers: that is why
|
|
35
|
+
pinning the origin is the fix.
|
|
36
|
+
|
|
37
|
+
### SPEC 19.3 now applies to the family, not to eight names
|
|
38
|
+
|
|
39
|
+
19.3 lists eight primitives and then says *"and any other that
|
|
40
|
+
resolves a name by querying the document"*. Measured: 69 of the 151
|
|
41
|
+
exports still died with a raw `ReferenceError: document is not
|
|
42
|
+
defined` in a process with no document -- the same defect D-26 closed
|
|
43
|
+
one layer up. All of them now refuse by name with `no_document`,
|
|
44
|
+
**through the channel each one already used**: a primitive that returns
|
|
45
|
+
a promise rejects, one that returns a value throws. `NAC.documentPrimitives()`
|
|
46
|
+
publishes the declaration so a caller can ask before calling.
|
|
47
|
+
|
|
48
|
+
The worst of the 69 was **`wait_for`**, which scheduled its timeout
|
|
49
|
+
BEFORE touching the document: the error came out of the timer, outside
|
|
50
|
+
every `try/catch` the caller could write, and **killed the Node
|
|
51
|
+
process**. A `.catch()` could not reach it. Guarded at entry now, so
|
|
52
|
+
no timer is ever scheduled.
|
|
53
|
+
|
|
54
|
+
### A `nac_id` is escaped before it reaches a selector
|
|
55
|
+
|
|
56
|
+
Every id the runtime resolves went straight into a quoted attribute
|
|
57
|
+
selector. An id with a double quote closed the string and the browser
|
|
58
|
+
answered with a raw `DOMException` ("is not a valid selector") where
|
|
59
|
+
the contract promises `not_found`; a comma could continue the selector
|
|
60
|
+
LIST and resolve a different element. 59 interpolations now go through
|
|
61
|
+
one escaper, which escapes the only two characters that can break out
|
|
62
|
+
of a CSS string and leaves the dots in every id alone. Not
|
|
63
|
+
`CSS.escape()`: that one escapes for use as an identifier.
|
|
64
|
+
|
|
65
|
+
### Smaller, and each measured
|
|
66
|
+
|
|
67
|
+
* **A colon in a peer's `app_id` made an ambiguous namespace.**
|
|
68
|
+
`remote:<ns>:<peer_id>` splits at the first colon, and the namespace
|
|
69
|
+
defaults to the `app_id` the peer chose: a peer declaring
|
|
70
|
+
`"bank:widget"` routed `remote:bank:widget:pay` to an unrelated peer
|
|
71
|
+
named `bank`. Refused at import now.
|
|
72
|
+
* **An outgoing `postMessage` with no declared `target_origin` went
|
|
73
|
+
to `'*'`.** It now goes to the origin of the iframe the adopter
|
|
74
|
+
pointed at, read from its `src`, and says so once per message.
|
|
75
|
+
`'*'` survives where it is the only thing that works -- `srcdoc`,
|
|
76
|
+
`about:blank`, no `src` -- and where an adopter declares it.
|
|
77
|
+
* **`nac validate --harness` runs the page inside a Node `vm`**, and a
|
|
78
|
+
`vm` is not a security boundary. The implementation has said so since
|
|
79
|
+
it was written; the CLI help and this package's README now say it
|
|
80
|
+
too, where an adopter reads.
|
|
81
|
+
|
|
82
|
+
### No behaviour of the contract changed
|
|
83
|
+
|
|
84
|
+
No role, event, attribute or manifest field was added, removed or
|
|
85
|
+
renamed. The one API addition is `NAC.documentPrimitives()`, which
|
|
86
|
+
reports a declaration. Everything else is a refusal that used to be a
|
|
87
|
+
crash, or a destination that used to be "anywhere".
|
|
88
|
+
|
|
89
|
+
|
|
3
90
|
## 2.9.0 -- 2026-11-27
|
|
4
91
|
|
|
5
92
|
A MINOR release, additive, and the one this project found by measuring
|
package/README.md
CHANGED
|
@@ -131,6 +131,15 @@ asks the runtime the same questions the browser mode asks -- with the
|
|
|
131
131
|
same observer and the same decider table, so the two modes cannot form
|
|
132
132
|
two opinions about what the contract says.
|
|
133
133
|
|
|
134
|
+
> **Only point `--harness` at HTML you trust.** The sandbox is a Node
|
|
135
|
+
> `vm` context with no network, no filesystem and no storage beyond a
|
|
136
|
+
> stub, which is a long way from nothing -- but a `vm` is not a
|
|
137
|
+
> security boundary, and a script that reaches a constructor can leave
|
|
138
|
+
> it. Running this mode over a page you did not write is running that
|
|
139
|
+
> page's code. The plain directory mode (`validate <dir>` with no
|
|
140
|
+
> flag) never executes anything and is the one to use on markup from
|
|
141
|
+
> elsewhere.
|
|
142
|
+
|
|
134
143
|
Of the eleven requirements of SPEC.md section 8 it **decides five** and
|
|
135
144
|
**declares the other six**, each with the reason it cannot:
|
|
136
145
|
|
package/SPEC.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# NAC3 -- Native Agent Contract
|
|
2
2
|
|
|
3
|
-
**Version:** 2.9.
|
|
3
|
+
**Version:** 2.9.1 (stable -- the v2.5 surface, the v2.6 plugin extension hooks (discovery, self-description, emitter-listen), the v2.7 authenticity surface (HMAC-verified manifests, dispatch provenance, the probing validator, the surface doors of 15.12, the headless profile), the v2.8 vocabulary (45 surface roles, 7 declared aliases, the complete event table of 6.4, and `register_role`) and the v2.9 document vocabulary: the five roles this project's own generated pages had been painting since before the vocabulary existed)
|
|
4
4
|
**Status:** Stable release. The npm dist-tag `latest` points here; section 9.1 states what that guarantees and what a prerelease does not. This document states its version in exactly one place, the line above. The shipped RFCs and their Layer 2 + Layer 3 evidence are listed in `README.md` and `runtime/CHANGELOG.md`.
|
|
5
5
|
**License:** Apache-2.0
|
|
6
6
|
**Editor:** Yujin (yujin.app)
|
package/contract-head.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"api_schema": 1,
|
|
3
|
-
"chain_head": "sha384-
|
|
4
|
-
"entry_count":
|
|
3
|
+
"chain_head": "sha384-P3/WbjZLa15msTk9IR2RExuDrf4pZOhSWLx7SwdHyhZDcxmUerjgNn4iWtLHQfIU",
|
|
4
|
+
"entry_count": 10,
|
|
5
5
|
"generated_by": "scripts/build-contract-api.mjs",
|
|
6
6
|
"note": "The third of three independent witnesses of the contract chain head (audit N-24). This copy is immutable once published: npm does not allow a version to be republished, so a host that rewrites the chain cannot reach back and change it. If this head disagrees with the one the host serves for this version, do not trust the host. Present from 2.5.0 onward; earlier releases were published before this API existed.",
|
|
7
7
|
"protocol": "NAC3",
|
|
8
|
-
"published_at": "2026-11-
|
|
9
|
-
"runtime_version": "2.9.
|
|
8
|
+
"published_at": "2026-11-28",
|
|
9
|
+
"runtime_version": "2.9.1",
|
|
10
10
|
"surface": "contract-head-witness",
|
|
11
11
|
"witnesses": {
|
|
12
12
|
"host": "api/index.json served by the web host (chain_head)",
|
package/dist/cli-levels.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"generated_by": "runtime/build.mjs from SPEC.md section 8 via scripts/spec-levels.mjs",
|
|
3
3
|
"note": "Build input for the CLI validator. The published, signed copy of the same facts is api/v/<version>/levels.json.",
|
|
4
|
-
"version": "2.9.
|
|
4
|
+
"version": "2.9.1",
|
|
5
5
|
"spec_version": "2.9",
|
|
6
6
|
"locales_required": [
|
|
7
7
|
"es",
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/* =====================================================================
|
|
3
|
-
NAC CLI v2.9.
|
|
3
|
+
NAC CLI v2.9.1 -- the entry point.
|
|
4
4
|
|
|
5
5
|
THREE modes since 2026-11-27, and they do not pretend to be each
|
|
6
6
|
other:
|
|
@@ -52,7 +52,7 @@ import fs from 'node:fs';
|
|
|
52
52
|
import path from 'node:path';
|
|
53
53
|
import { lintTree, manifestInventory, lintableFiles, LINT_EXTENSIONS } from './cli-lint.mjs';
|
|
54
54
|
|
|
55
|
-
const VERSION = '2.9.
|
|
55
|
+
const VERSION = '2.9.1';
|
|
56
56
|
const SPEC_VERSION = '2.9';
|
|
57
57
|
|
|
58
58
|
const args = process.argv.slice(2);
|
|
@@ -100,6 +100,9 @@ function showHelp() {
|
|
|
100
100
|
console.log(' and report a verdict per conformance requirement.');
|
|
101
101
|
console.log(' It executes the page in a sandbox with no network;');
|
|
102
102
|
console.log(' the plain directory mode never executes anything.');
|
|
103
|
+
console.log(' A Node vm is NOT a security boundary: do not point');
|
|
104
|
+
console.log(' --harness at HTML you do not trust. Use the plain');
|
|
105
|
+
console.log(' directory mode for that -- it only reads bytes.');
|
|
103
106
|
console.log(' --requirements with --harness: the full breakdown, all 11 of them,');
|
|
104
107
|
console.log(' each DECIDED (pass/fail) or NOT-DECIDABLE with why');
|
|
105
108
|
console.log(' --ext=.a,.b ALSO read these extensions in directory mode.');
|
|
@@ -198,6 +198,19 @@
|
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
/* ---------- DOM helpers ---------- */
|
|
201
|
+
/* 2.9.1 -- a nac_id arrives here from the intermediary's answer, so
|
|
202
|
+
it is outside data on its way into a quoted attribute selector. A
|
|
203
|
+
double quote closed the selector and the browser answered with a
|
|
204
|
+
raw DOMException. Escapes the only two characters that can break
|
|
205
|
+
out of a CSS string; see _nac_attrValue in js/nac.js for the long
|
|
206
|
+
form of why it is not CSS.escape(). */
|
|
207
|
+
function _nacAttrValue(value) {
|
|
208
|
+
return String(value)
|
|
209
|
+
.replace(/[\\"]/g, function (c) { return '\\' + c; })
|
|
210
|
+
.replace(/[\n\r\f]/g, function (c) {
|
|
211
|
+
return '\\' + c.charCodeAt(0).toString(16) + ' ';
|
|
212
|
+
});
|
|
213
|
+
}
|
|
201
214
|
function $(sel, root) { return (root || document).querySelector(sel); }
|
|
202
215
|
function _bubble(role, text) {
|
|
203
216
|
if (!NacChat._chatLog) return;
|
|
@@ -349,7 +362,7 @@
|
|
|
349
362
|
effect; we just don't wait for the conformance ack. */
|
|
350
363
|
function _directClick(nacId) {
|
|
351
364
|
if (!nacId) throw new Error('click: nac_id required');
|
|
352
|
-
var el = document.querySelector('[data-nac-id="' + nacId + '"]');
|
|
365
|
+
var el = document.querySelector('[data-nac-id="' + _nacAttrValue(nacId) + '"]');
|
|
353
366
|
if (!el) throw new Error('click: element not found ' + nacId);
|
|
354
367
|
try { el.click(); return { ok: true, dispatched: 'direct' }; }
|
|
355
368
|
catch (e) { throw new Error('click threw: ' + (e && e.message)); }
|
|
@@ -368,9 +381,9 @@
|
|
|
368
381
|
/* Fallback: walk the DOM looking for an element under this
|
|
369
382
|
plugin whose data-nac-action matches the verb. */
|
|
370
383
|
var root = plugin
|
|
371
|
-
? document.querySelector('[data-nac-plugin="' + plugin + '"]')
|
|
384
|
+
? document.querySelector('[data-nac-plugin="' + _nacAttrValue(plugin) + '"]')
|
|
372
385
|
: document;
|
|
373
|
-
var hit = root && root.querySelector('[data-nac-action="' + verb + '"][data-nac-id]');
|
|
386
|
+
var hit = root && root.querySelector('[data-nac-action="' + _nacAttrValue(verb) + '"][data-nac-id]');
|
|
374
387
|
if (!hit) throw new Error('click_by_verb: no nac_id for verb=' + verb + ' plugin=' + plugin);
|
|
375
388
|
try { hit.click(); return { ok: true, dispatched: 'direct_dom_walk' }; }
|
|
376
389
|
catch (e) { throw new Error('click_by_verb threw: ' + e.message); }
|
|
@@ -379,7 +392,7 @@
|
|
|
379
392
|
}
|
|
380
393
|
function _directFill(nacId, value) {
|
|
381
394
|
if (!nacId) throw new Error('fill: nac_id required');
|
|
382
|
-
var el = document.querySelector('[data-nac-id="' + nacId + '"]');
|
|
395
|
+
var el = document.querySelector('[data-nac-id="' + _nacAttrValue(nacId) + '"]');
|
|
383
396
|
if (!el) throw new Error('fill: element not found ' + nacId);
|
|
384
397
|
try {
|
|
385
398
|
el.focus();
|
|
@@ -391,7 +404,7 @@
|
|
|
391
404
|
}
|
|
392
405
|
function _directSelect(nacId, value) {
|
|
393
406
|
if (!nacId) throw new Error('select: nac_id required');
|
|
394
|
-
var el = document.querySelector('[data-nac-id="' + nacId + '"]');
|
|
407
|
+
var el = document.querySelector('[data-nac-id="' + _nacAttrValue(nacId) + '"]');
|
|
395
408
|
if (!el) throw new Error('select: element not found ' + nacId);
|
|
396
409
|
try {
|
|
397
410
|
if (el.tagName === 'SELECT') {
|
|
@@ -399,7 +412,7 @@
|
|
|
399
412
|
el.dispatchEvent(new Event('change', { bubbles: true }));
|
|
400
413
|
} else {
|
|
401
414
|
/* radio/checkbox: find the option with matching value */
|
|
402
|
-
var opt = el.querySelector('[value="' + value + '"]');
|
|
415
|
+
var opt = el.querySelector('[value="' + _nacAttrValue(value) + '"]');
|
|
403
416
|
if (opt) {
|
|
404
417
|
opt.checked = true;
|
|
405
418
|
opt.dispatchEvent(new Event('change', { bubbles: true }));
|
package/dist/nac-chat-client.cjs
CHANGED
|
@@ -199,6 +199,19 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
/* ---------- DOM helpers ---------- */
|
|
202
|
+
/* 2.9.1 -- a nac_id arrives here from the intermediary's answer, so
|
|
203
|
+
it is outside data on its way into a quoted attribute selector. A
|
|
204
|
+
double quote closed the selector and the browser answered with a
|
|
205
|
+
raw DOMException. Escapes the only two characters that can break
|
|
206
|
+
out of a CSS string; see _nac_attrValue in js/nac.js for the long
|
|
207
|
+
form of why it is not CSS.escape(). */
|
|
208
|
+
function _nacAttrValue(value) {
|
|
209
|
+
return String(value)
|
|
210
|
+
.replace(/[\\"]/g, function (c) { return '\\' + c; })
|
|
211
|
+
.replace(/[\n\r\f]/g, function (c) {
|
|
212
|
+
return '\\' + c.charCodeAt(0).toString(16) + ' ';
|
|
213
|
+
});
|
|
214
|
+
}
|
|
202
215
|
function $(sel, root) { return (root || document).querySelector(sel); }
|
|
203
216
|
function _bubble(role, text) {
|
|
204
217
|
if (!NacChat._chatLog) return;
|
|
@@ -350,7 +363,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
350
363
|
effect; we just don't wait for the conformance ack. */
|
|
351
364
|
function _directClick(nacId) {
|
|
352
365
|
if (!nacId) throw new Error('click: nac_id required');
|
|
353
|
-
var el = document.querySelector('[data-nac-id="' + nacId + '"]');
|
|
366
|
+
var el = document.querySelector('[data-nac-id="' + _nacAttrValue(nacId) + '"]');
|
|
354
367
|
if (!el) throw new Error('click: element not found ' + nacId);
|
|
355
368
|
try { el.click(); return { ok: true, dispatched: 'direct' }; }
|
|
356
369
|
catch (e) { throw new Error('click threw: ' + (e && e.message)); }
|
|
@@ -369,9 +382,9 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
369
382
|
/* Fallback: walk the DOM looking for an element under this
|
|
370
383
|
plugin whose data-nac-action matches the verb. */
|
|
371
384
|
var root = plugin
|
|
372
|
-
? document.querySelector('[data-nac-plugin="' + plugin + '"]')
|
|
385
|
+
? document.querySelector('[data-nac-plugin="' + _nacAttrValue(plugin) + '"]')
|
|
373
386
|
: document;
|
|
374
|
-
var hit = root && root.querySelector('[data-nac-action="' + verb + '"][data-nac-id]');
|
|
387
|
+
var hit = root && root.querySelector('[data-nac-action="' + _nacAttrValue(verb) + '"][data-nac-id]');
|
|
375
388
|
if (!hit) throw new Error('click_by_verb: no nac_id for verb=' + verb + ' plugin=' + plugin);
|
|
376
389
|
try { hit.click(); return { ok: true, dispatched: 'direct_dom_walk' }; }
|
|
377
390
|
catch (e) { throw new Error('click_by_verb threw: ' + e.message); }
|
|
@@ -380,7 +393,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
380
393
|
}
|
|
381
394
|
function _directFill(nacId, value) {
|
|
382
395
|
if (!nacId) throw new Error('fill: nac_id required');
|
|
383
|
-
var el = document.querySelector('[data-nac-id="' + nacId + '"]');
|
|
396
|
+
var el = document.querySelector('[data-nac-id="' + _nacAttrValue(nacId) + '"]');
|
|
384
397
|
if (!el) throw new Error('fill: element not found ' + nacId);
|
|
385
398
|
try {
|
|
386
399
|
el.focus();
|
|
@@ -392,7 +405,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
392
405
|
}
|
|
393
406
|
function _directSelect(nacId, value) {
|
|
394
407
|
if (!nacId) throw new Error('select: nac_id required');
|
|
395
|
-
var el = document.querySelector('[data-nac-id="' + nacId + '"]');
|
|
408
|
+
var el = document.querySelector('[data-nac-id="' + _nacAttrValue(nacId) + '"]');
|
|
396
409
|
if (!el) throw new Error('select: element not found ' + nacId);
|
|
397
410
|
try {
|
|
398
411
|
if (el.tagName === 'SELECT') {
|
|
@@ -400,7 +413,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
400
413
|
el.dispatchEvent(new Event('change', { bubbles: true }));
|
|
401
414
|
} else {
|
|
402
415
|
/* radio/checkbox: find the option with matching value */
|
|
403
|
-
var opt = el.querySelector('[value="' + value + '"]');
|
|
416
|
+
var opt = el.querySelector('[value="' + _nacAttrValue(value) + '"]');
|
|
404
417
|
if (opt) {
|
|
405
418
|
opt.checked = true;
|
|
406
419
|
opt.dispatchEvent(new Event('change', { bubbles: true }));
|
package/dist/nac-chat-client.mjs
CHANGED
|
@@ -199,6 +199,19 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
/* ---------- DOM helpers ---------- */
|
|
202
|
+
/* 2.9.1 -- a nac_id arrives here from the intermediary's answer, so
|
|
203
|
+
it is outside data on its way into a quoted attribute selector. A
|
|
204
|
+
double quote closed the selector and the browser answered with a
|
|
205
|
+
raw DOMException. Escapes the only two characters that can break
|
|
206
|
+
out of a CSS string; see _nac_attrValue in js/nac.js for the long
|
|
207
|
+
form of why it is not CSS.escape(). */
|
|
208
|
+
function _nacAttrValue(value) {
|
|
209
|
+
return String(value)
|
|
210
|
+
.replace(/[\\"]/g, function (c) { return '\\' + c; })
|
|
211
|
+
.replace(/[\n\r\f]/g, function (c) {
|
|
212
|
+
return '\\' + c.charCodeAt(0).toString(16) + ' ';
|
|
213
|
+
});
|
|
214
|
+
}
|
|
202
215
|
function $(sel, root) { return (root || document).querySelector(sel); }
|
|
203
216
|
function _bubble(role, text) {
|
|
204
217
|
if (!NacChat._chatLog) return;
|
|
@@ -350,7 +363,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
350
363
|
effect; we just don't wait for the conformance ack. */
|
|
351
364
|
function _directClick(nacId) {
|
|
352
365
|
if (!nacId) throw new Error('click: nac_id required');
|
|
353
|
-
var el = document.querySelector('[data-nac-id="' + nacId + '"]');
|
|
366
|
+
var el = document.querySelector('[data-nac-id="' + _nacAttrValue(nacId) + '"]');
|
|
354
367
|
if (!el) throw new Error('click: element not found ' + nacId);
|
|
355
368
|
try { el.click(); return { ok: true, dispatched: 'direct' }; }
|
|
356
369
|
catch (e) { throw new Error('click threw: ' + (e && e.message)); }
|
|
@@ -369,9 +382,9 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
369
382
|
/* Fallback: walk the DOM looking for an element under this
|
|
370
383
|
plugin whose data-nac-action matches the verb. */
|
|
371
384
|
var root = plugin
|
|
372
|
-
? document.querySelector('[data-nac-plugin="' + plugin + '"]')
|
|
385
|
+
? document.querySelector('[data-nac-plugin="' + _nacAttrValue(plugin) + '"]')
|
|
373
386
|
: document;
|
|
374
|
-
var hit = root && root.querySelector('[data-nac-action="' + verb + '"][data-nac-id]');
|
|
387
|
+
var hit = root && root.querySelector('[data-nac-action="' + _nacAttrValue(verb) + '"][data-nac-id]');
|
|
375
388
|
if (!hit) throw new Error('click_by_verb: no nac_id for verb=' + verb + ' plugin=' + plugin);
|
|
376
389
|
try { hit.click(); return { ok: true, dispatched: 'direct_dom_walk' }; }
|
|
377
390
|
catch (e) { throw new Error('click_by_verb threw: ' + e.message); }
|
|
@@ -380,7 +393,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
380
393
|
}
|
|
381
394
|
function _directFill(nacId, value) {
|
|
382
395
|
if (!nacId) throw new Error('fill: nac_id required');
|
|
383
|
-
var el = document.querySelector('[data-nac-id="' + nacId + '"]');
|
|
396
|
+
var el = document.querySelector('[data-nac-id="' + _nacAttrValue(nacId) + '"]');
|
|
384
397
|
if (!el) throw new Error('fill: element not found ' + nacId);
|
|
385
398
|
try {
|
|
386
399
|
el.focus();
|
|
@@ -392,7 +405,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
392
405
|
}
|
|
393
406
|
function _directSelect(nacId, value) {
|
|
394
407
|
if (!nacId) throw new Error('select: nac_id required');
|
|
395
|
-
var el = document.querySelector('[data-nac-id="' + nacId + '"]');
|
|
408
|
+
var el = document.querySelector('[data-nac-id="' + _nacAttrValue(nacId) + '"]');
|
|
396
409
|
if (!el) throw new Error('select: element not found ' + nacId);
|
|
397
410
|
try {
|
|
398
411
|
if (el.tagName === 'SELECT') {
|
|
@@ -400,7 +413,7 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
400
413
|
el.dispatchEvent(new Event('change', { bubbles: true }));
|
|
401
414
|
} else {
|
|
402
415
|
/* radio/checkbox: find the option with matching value */
|
|
403
|
-
var opt = el.querySelector('[value="' + value + '"]');
|
|
416
|
+
var opt = el.querySelector('[value="' + _nacAttrValue(value) + '"]');
|
|
404
417
|
if (opt) {
|
|
405
418
|
opt.checked = true;
|
|
406
419
|
opt.dispatchEvent(new Event('change', { bubbles: true }));
|
|
@@ -83,6 +83,48 @@
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/* 2.9.1 (PND-161) -- WHERE THE HOST'S CREDENTIAL IS ALLOWED TO GO.
|
|
87
|
+
|
|
88
|
+
import_remote_tree takes two arguments with very different
|
|
89
|
+
standing: `conn`, which the HOST wrote, and `payload`, which is
|
|
90
|
+
DATA THE PEER SENT. The ack subscription was built from
|
|
91
|
+
payload.ack_endpoint and carried conn.bearer on the query string,
|
|
92
|
+
so the other side of the channel chose the destination of the
|
|
93
|
+
host's credential: a peer that is malicious, or merely
|
|
94
|
+
compromised, pointed it at its own collector and the browser
|
|
95
|
+
delivered it.
|
|
96
|
+
|
|
97
|
+
The rule now is the one the host can actually reason about: the
|
|
98
|
+
credential travels only to the origin the HOST already trusted
|
|
99
|
+
with it -- the origin of conn.endpoint -- or to an endpoint the
|
|
100
|
+
host named itself in conn.ack_endpoint. A same-origin
|
|
101
|
+
payload.ack_endpoint still works, which is the shape every real
|
|
102
|
+
bridge has (the SSE route lives beside the RPC route), so no
|
|
103
|
+
legitimate deployment changes.
|
|
104
|
+
|
|
105
|
+
What this does NOT fix, and is accepted and documented: the bearer
|
|
106
|
+
still rides the query string, because EventSource cannot carry
|
|
107
|
+
headers. That is why pinning the origin matters -- a query string
|
|
108
|
+
ends up in proxy logs and Referer headers, and now at least it is
|
|
109
|
+
the logs of the host's own bridge. */
|
|
110
|
+
function _originOf(url, base) {
|
|
111
|
+
try {
|
|
112
|
+
if (typeof URL !== 'function') return null;
|
|
113
|
+
var b = base || (typeof location !== 'undefined' ? location.href : undefined);
|
|
114
|
+
return new URL(String(url), b).origin;
|
|
115
|
+
} catch (e) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function _ackEndpointAllowed(ackEndpoint, connEndpoint) {
|
|
120
|
+
var want = _originOf(connEndpoint);
|
|
121
|
+
var got = _originOf(ackEndpoint, connEndpoint);
|
|
122
|
+
/* Fail closed: an origin that cannot be resolved is not an origin
|
|
123
|
+
that was checked. */
|
|
124
|
+
if (!want || !got) return false;
|
|
125
|
+
return want === got;
|
|
126
|
+
}
|
|
127
|
+
|
|
86
128
|
function _parseRemote(nac_id) {
|
|
87
129
|
if (typeof nac_id !== 'string') return null;
|
|
88
130
|
if (nac_id.indexOf(REMOTE_PREFIX) !== 0) return null;
|
|
@@ -213,6 +255,20 @@
|
|
|
213
255
|
var transport = conn.transport || 'http';
|
|
214
256
|
var namespace = conn.namespace || payload.app_id;
|
|
215
257
|
if (!namespace) throw _err('invalid', 'import_remote_tree: namespace required (no app_id in payload)');
|
|
258
|
+
/* 2.9.1 (PND-166) -- the namespace is the first segment of
|
|
259
|
+
"remote:<ns>:<peer_id>" and _parseRemote splits at the FIRST
|
|
260
|
+
colon, so a namespace containing one makes every id under it
|
|
261
|
+
ambiguous. It defaults to payload.app_id, which the PEER chose:
|
|
262
|
+
measured, a peer declaring app_id "bank:widget" routed
|
|
263
|
+
NAC.click('remote:bank:widget:pay') to the endpoint and bearer of
|
|
264
|
+
an unrelated peer named "bank". Refused by name instead of
|
|
265
|
+
imported into an ambiguity. */
|
|
266
|
+
if (String(namespace).indexOf(':') >= 0) {
|
|
267
|
+
throw _err('invalid',
|
|
268
|
+
'import_remote_tree: namespace "' + namespace + '" contains ":", which is the '
|
|
269
|
+
+ 'separator of remote:<namespace>:<peer_id> -- every id under it would be '
|
|
270
|
+
+ 'ambiguous. Pass conn.namespace with no colon.');
|
|
271
|
+
}
|
|
216
272
|
if (_remotes[namespace]) {
|
|
217
273
|
throw _err('conflict', 'import_remote_tree: namespace "' + namespace + '" already imported; disconnect first');
|
|
218
274
|
}
|
|
@@ -263,9 +319,33 @@
|
|
|
263
319
|
};
|
|
264
320
|
_remotes[namespace] = handle;
|
|
265
321
|
|
|
266
|
-
/* Auto-subscribe to ack events
|
|
267
|
-
|
|
268
|
-
|
|
322
|
+
/* Auto-subscribe to ack events -- see _ackEndpointAllowed for why
|
|
323
|
+
the host's endpoint wins over the peer's. */
|
|
324
|
+
if (conn.auto_subscribe !== false && transport === 'http') {
|
|
325
|
+
var hostAck = conn.ack_endpoint || null;
|
|
326
|
+
var peerAck = payload.ack_endpoint || null;
|
|
327
|
+
if (hostAck) {
|
|
328
|
+
_subscribeRemote(handle, hostAck);
|
|
329
|
+
} else if (peerAck && _ackEndpointAllowed(peerAck, conn.endpoint)) {
|
|
330
|
+
_subscribeRemote(handle, peerAck);
|
|
331
|
+
} else if (peerAck) {
|
|
332
|
+
/* Refused by name, never in silence: the import stands (the
|
|
333
|
+
tree is data and it is already registered) but the channel
|
|
334
|
+
that would have carried the bearer does not open, and the
|
|
335
|
+
host can see exactly that on the handle and on the event. */
|
|
336
|
+
handle.ack_refused = {
|
|
337
|
+
reason: 'ack_endpoint_cross_origin',
|
|
338
|
+
ack_endpoint: String(peerAck),
|
|
339
|
+
conn_origin: _originOf(conn.endpoint),
|
|
340
|
+
ack_origin: _originOf(peerAck, conn.endpoint),
|
|
341
|
+
};
|
|
342
|
+
console.warn('[nac-interop] refused the peer ack_endpoint: it is not the origin of '
|
|
343
|
+
+ 'conn.endpoint, and the bearer would have travelled to it. Pass conn.ack_endpoint '
|
|
344
|
+
+ 'to name one yourself.', handle.ack_refused);
|
|
345
|
+
document.dispatchEvent(new CustomEvent('nac:interop:ack_refused', {
|
|
346
|
+
detail: Object.assign({ namespace: namespace }, handle.ack_refused)
|
|
347
|
+
}));
|
|
348
|
+
}
|
|
269
349
|
}
|
|
270
350
|
|
|
271
351
|
document.dispatchEvent(new CustomEvent('nac:interop:imported', {
|
package/dist/nac-mcp-interop.cjs
CHANGED
|
@@ -84,6 +84,48 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
/* 2.9.1 (PND-161) -- WHERE THE HOST'S CREDENTIAL IS ALLOWED TO GO.
|
|
88
|
+
|
|
89
|
+
import_remote_tree takes two arguments with very different
|
|
90
|
+
standing: `conn`, which the HOST wrote, and `payload`, which is
|
|
91
|
+
DATA THE PEER SENT. The ack subscription was built from
|
|
92
|
+
payload.ack_endpoint and carried conn.bearer on the query string,
|
|
93
|
+
so the other side of the channel chose the destination of the
|
|
94
|
+
host's credential: a peer that is malicious, or merely
|
|
95
|
+
compromised, pointed it at its own collector and the browser
|
|
96
|
+
delivered it.
|
|
97
|
+
|
|
98
|
+
The rule now is the one the host can actually reason about: the
|
|
99
|
+
credential travels only to the origin the HOST already trusted
|
|
100
|
+
with it -- the origin of conn.endpoint -- or to an endpoint the
|
|
101
|
+
host named itself in conn.ack_endpoint. A same-origin
|
|
102
|
+
payload.ack_endpoint still works, which is the shape every real
|
|
103
|
+
bridge has (the SSE route lives beside the RPC route), so no
|
|
104
|
+
legitimate deployment changes.
|
|
105
|
+
|
|
106
|
+
What this does NOT fix, and is accepted and documented: the bearer
|
|
107
|
+
still rides the query string, because EventSource cannot carry
|
|
108
|
+
headers. That is why pinning the origin matters -- a query string
|
|
109
|
+
ends up in proxy logs and Referer headers, and now at least it is
|
|
110
|
+
the logs of the host's own bridge. */
|
|
111
|
+
function _originOf(url, base) {
|
|
112
|
+
try {
|
|
113
|
+
if (typeof URL !== 'function') return null;
|
|
114
|
+
var b = base || (typeof location !== 'undefined' ? location.href : undefined);
|
|
115
|
+
return new URL(String(url), b).origin;
|
|
116
|
+
} catch (e) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function _ackEndpointAllowed(ackEndpoint, connEndpoint) {
|
|
121
|
+
var want = _originOf(connEndpoint);
|
|
122
|
+
var got = _originOf(ackEndpoint, connEndpoint);
|
|
123
|
+
/* Fail closed: an origin that cannot be resolved is not an origin
|
|
124
|
+
that was checked. */
|
|
125
|
+
if (!want || !got) return false;
|
|
126
|
+
return want === got;
|
|
127
|
+
}
|
|
128
|
+
|
|
87
129
|
function _parseRemote(nac_id) {
|
|
88
130
|
if (typeof nac_id !== 'string') return null;
|
|
89
131
|
if (nac_id.indexOf(REMOTE_PREFIX) !== 0) return null;
|
|
@@ -214,6 +256,20 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
214
256
|
var transport = conn.transport || 'http';
|
|
215
257
|
var namespace = conn.namespace || payload.app_id;
|
|
216
258
|
if (!namespace) throw _err('invalid', 'import_remote_tree: namespace required (no app_id in payload)');
|
|
259
|
+
/* 2.9.1 (PND-166) -- the namespace is the first segment of
|
|
260
|
+
"remote:<ns>:<peer_id>" and _parseRemote splits at the FIRST
|
|
261
|
+
colon, so a namespace containing one makes every id under it
|
|
262
|
+
ambiguous. It defaults to payload.app_id, which the PEER chose:
|
|
263
|
+
measured, a peer declaring app_id "bank:widget" routed
|
|
264
|
+
NAC.click('remote:bank:widget:pay') to the endpoint and bearer of
|
|
265
|
+
an unrelated peer named "bank". Refused by name instead of
|
|
266
|
+
imported into an ambiguity. */
|
|
267
|
+
if (String(namespace).indexOf(':') >= 0) {
|
|
268
|
+
throw _err('invalid',
|
|
269
|
+
'import_remote_tree: namespace "' + namespace + '" contains ":", which is the '
|
|
270
|
+
+ 'separator of remote:<namespace>:<peer_id> -- every id under it would be '
|
|
271
|
+
+ 'ambiguous. Pass conn.namespace with no colon.');
|
|
272
|
+
}
|
|
217
273
|
if (_remotes[namespace]) {
|
|
218
274
|
throw _err('conflict', 'import_remote_tree: namespace "' + namespace + '" already imported; disconnect first');
|
|
219
275
|
}
|
|
@@ -264,9 +320,33 @@ const _g = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== '
|
|
|
264
320
|
};
|
|
265
321
|
_remotes[namespace] = handle;
|
|
266
322
|
|
|
267
|
-
/* Auto-subscribe to ack events
|
|
268
|
-
|
|
269
|
-
|
|
323
|
+
/* Auto-subscribe to ack events -- see _ackEndpointAllowed for why
|
|
324
|
+
the host's endpoint wins over the peer's. */
|
|
325
|
+
if (conn.auto_subscribe !== false && transport === 'http') {
|
|
326
|
+
var hostAck = conn.ack_endpoint || null;
|
|
327
|
+
var peerAck = payload.ack_endpoint || null;
|
|
328
|
+
if (hostAck) {
|
|
329
|
+
_subscribeRemote(handle, hostAck);
|
|
330
|
+
} else if (peerAck && _ackEndpointAllowed(peerAck, conn.endpoint)) {
|
|
331
|
+
_subscribeRemote(handle, peerAck);
|
|
332
|
+
} else if (peerAck) {
|
|
333
|
+
/* Refused by name, never in silence: the import stands (the
|
|
334
|
+
tree is data and it is already registered) but the channel
|
|
335
|
+
that would have carried the bearer does not open, and the
|
|
336
|
+
host can see exactly that on the handle and on the event. */
|
|
337
|
+
handle.ack_refused = {
|
|
338
|
+
reason: 'ack_endpoint_cross_origin',
|
|
339
|
+
ack_endpoint: String(peerAck),
|
|
340
|
+
conn_origin: _originOf(conn.endpoint),
|
|
341
|
+
ack_origin: _originOf(peerAck, conn.endpoint),
|
|
342
|
+
};
|
|
343
|
+
console.warn('[nac-interop] refused the peer ack_endpoint: it is not the origin of '
|
|
344
|
+
+ 'conn.endpoint, and the bearer would have travelled to it. Pass conn.ack_endpoint '
|
|
345
|
+
+ 'to name one yourself.', handle.ack_refused);
|
|
346
|
+
document.dispatchEvent(new CustomEvent('nac:interop:ack_refused', {
|
|
347
|
+
detail: Object.assign({ namespace: namespace }, handle.ack_refused)
|
|
348
|
+
}));
|
|
349
|
+
}
|
|
270
350
|
}
|
|
271
351
|
|
|
272
352
|
document.dispatchEvent(new CustomEvent('nac:interop:imported', {
|