@botiverse/porthole 0.14.7 → 0.14.8

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/check/files.js +2 -0
  3. package/dist/check/lint.js +82 -3
  4. package/dist/check/page-source.js +1 -1
  5. package/dist/compile/policy.d.ts +17 -6
  6. package/dist/compile/policy.js +22 -7
  7. package/dist/config/schema.d.ts +13 -0
  8. package/dist/config/validate.js +15 -0
  9. package/dist/conformance/harness-source.js +1 -1
  10. package/dist/conformance/kit.d.ts +5 -0
  11. package/dist/conformance/kit.js +21 -0
  12. package/dist/conformance/limits.js +10 -5
  13. package/dist/conformance/probes.js +139 -28
  14. package/dist/conformance/served.js +25 -4
  15. package/dist/guide/limits.js +8 -1
  16. package/dist/host/create-host.js +35 -4
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/presets/presets.d.ts +6 -0
  20. package/dist/presets/presets.js +6 -0
  21. package/dist/server/files.js +4 -3
  22. package/dist/server/server.js +4 -1
  23. package/dist/shell/plan.d.ts +5 -0
  24. package/dist/shell/plan.js +2 -0
  25. package/dist/shell/runtime.d.ts +30 -1
  26. package/dist/shell/runtime.js +785 -104
  27. package/docs/ADOPTING.md +20 -0
  28. package/docs/DECISIONS.md +294 -0
  29. package/docs/DESIGN.md +7 -4
  30. package/docs/THREAT_MODEL.md +30 -5
  31. package/docs/insertion-entry-points.md +95 -0
  32. package/package.json +1 -1
  33. package/src/check/files.ts +2 -0
  34. package/src/check/lint.ts +97 -8
  35. package/src/compile/policy.ts +23 -6
  36. package/src/config/schema.ts +13 -0
  37. package/src/config/validate.ts +16 -0
  38. package/src/conformance/kit.ts +22 -0
  39. package/src/conformance/limits.ts +10 -5
  40. package/src/conformance/probes.ts +149 -28
  41. package/src/conformance/served.ts +24 -4
  42. package/src/guide/limits.ts +9 -1
  43. package/src/host/create-host.ts +37 -4
  44. package/src/index.ts +1 -0
  45. package/src/presets/presets.ts +15 -0
  46. package/src/server/files.ts +8 -2
  47. package/src/server/server.ts +4 -1
  48. package/src/shell/plan.ts +7 -0
  49. package/src/shell/runtime.ts +788 -104
package/CHANGELOG.md CHANGED
@@ -4,6 +4,53 @@
4
4
  section); the reasons for every change are in [docs/DECISIONS.md](docs/DECISIONS.md), by the
5
5
  P-numbers below.
6
6
 
7
+ ## 0.14.8
8
+
9
+ - **Frame guard: broader coverage of DOM insertion and parsing entry points (P130),** listed in
10
+ [docs/insertion-entry-points.md](docs/insertion-entry-points.md).
11
+ - **Two default behaviours change (P130):**
12
+ - a page script that creates a frame-like element (`iframe`, `frame`, `frameset`, `object`,
13
+ `embed`, `portal`, `fencedframe`) with `createElement`/`createElementNS` now gets a
14
+ `NotSupportedError` there, so the rest of that script doesn't run; before, the element was
15
+ removed when it was inserted. `nestedFrames: "own"` is unchanged.
16
+ - in every default display, pasting or dropping formatted content into an editable element
17
+ (`contenteditable`, `designMode`) inserts its plain text only, so the formatting is lost.
18
+ - **Conformance:** a frame-like element the shell refuses at creation (P130) counts as the guard
19
+ holding, recorded as "refused at creation", not as a probe whose setup failed.
20
+ - **The shell's guards call only built-ins captured before content runs (P129):** step 3's frame
21
+ guard and its observer, the before-change backstop, and the synchronous insertion and HTML-parse
22
+ wrappers (`append`/`appendChild`/… , `innerHTML`/`outerHTML`/`insertAdjacentHTML`/`execCommand`,
23
+ the attribute-turn guards) take every built-in they use from references kept before any content
24
+ runs and call each only through `callOf`, which is `Reflect.apply` captured first — so nothing
25
+ content later puts on a DOM prototype, on `Array.from`/the array iterator/`Array.prototype.indexOf`,
26
+ or on `Function.prototype.apply`/`call`/`bind` takes part in the guard's reads, calls, walks or
27
+ decisions (live collections are indexed loops, arguments are prototype-less lists). Each name or
28
+ value a guard inspects and then forwards (a command name, an attribute name or value, a token) is
29
+ read once and that same reading is both checked and acted on, so a value that converts one way
30
+ when checked and another when the platform reads it can't slip past. Extends P128 and P030 to
31
+ every built-in the guard touches. No default behaviour, CSP, plan or manual changes.
32
+ - **A frame's size, at most once an animation frame (P127, audit 2026-10-29 C-1):** after a run's
33
+ first size (taken at once, as before), the host takes the last `size-changed` a frame sent on the
34
+ next animation frame, and drops a size the same as the last one taken, so content sending sizes as
35
+ fast as it can no longer reflows the host's page and fires `resize` (`onResize`) for each. A size
36
+ after the first now arrives on the next animation frame, not during the message.
37
+ - **A page's own nested frames, opt-in (P128):** `nestedFrames: "own"` (a preset's option, a
38
+ display kind's `options`; default `"none"`, which changes nothing) lets content keep an
39
+ `<iframe>` of one of its version's own files (a relative `src`) or with `srcdoc`, which load and
40
+ run, as in Claude's Artifacts. Frames of other sites, of another path of the origin, `data:`,
41
+ `blob:` and empty ones, `<frame>`, `<object>` and `<embed>` are still removed, and a kept frame
42
+ is removed before a change would point it elsewhere. A file set's page opens `frame-src` to its
43
+ version's path (`fileSetDirectives(config)`, and `fileSetCspDirectives` takes the directives to
44
+ open), and its files' `frame-ancestors` name its own origin. Opaque frames keep `srcdoc` ones
45
+ only. Refused for url mode, nested pages and `presets.liveWidget`. The `nested-frame` lint then
46
+ names only frames that never load; `lintFiles` looks a frame's `src` up in the set.
47
+ - **Security (P128): opting in is a weakening.** A nested frame is a realm of its own where the
48
+ shell's hardening never ran: content there has WebRTC (a way out past `connect-src`), resource
49
+ hints, `document.write`, and a click's `execCommand("copy")` and copy listeners (pastejacking,
50
+ with no notice). Child frames still can't navigate outside the version's path, and inherit the
51
+ sandbox. Leave it off unless your product accepts that; nothing changes for a host that doesn't
52
+ set it.
53
+
7
54
  ## 0.14.7
8
55
 
9
56
  - **`server.doorAnswer(instance, grant, request?, at?)` (P126):** the door's answer for a grant a
@@ -40,6 +40,8 @@ const REFERENCE_ATTRIBUTES = {
40
40
  audio: ["src"],
41
41
  track: ["src"],
42
42
  embed: ["src"],
43
+ // A page's own frame (P128, `nestedFrames: "own"`): a file of the set, looked up as the rest.
44
+ iframe: ["src"],
43
45
  input: ["src"],
44
46
  link: ["href"],
45
47
  a: ["href"],
@@ -1,6 +1,8 @@
1
1
  import { anyHttps, declaredCapabilities, egressOrigins, librarySources, } from "../compile/policy.js";
2
+ import { servesFiles } from "../files/paths.js";
2
3
  import { sizeWords } from "../guide/limits.js";
3
4
  import { originMatchesSource } from "../isolation/served.js";
5
+ import { attributesOf } from "./markup.js";
4
6
  import { scrollLock } from "./scroll.js";
5
7
  const lineOf = (text, index) => text.slice(0, index).split("\n").length;
6
8
  const noun = (config) => config.mode === "artifact" ? "page" : config.mode === "mcp-app" ? "view" : "widget";
@@ -71,6 +73,66 @@ const OWN_CDN = [
71
73
  { name: "jQuery", host: /^https:\/\/code\.jquery\.com\//u, pinned: /\d+\.\d+\.\d+/u },
72
74
  { name: "Plotly", host: /^https:\/\/cdn\.plot\.ly\/plotly/u, pinned: /\d+\.\d+\.\d+/u },
73
75
  ];
76
+ /** The most of a tag's text a frame's attributes are read from: a `srcdoc` may hold markup. */
77
+ const MOST_TAG_CHARS = 65_536;
78
+ /** The most frame-like tags read for `strayFrame`: past them, the rest isn't looked at. */
79
+ const MOST_FRAMES = 200;
80
+ /**
81
+ * A tag's attributes' text, from just past its name to its closing `>` outside any quoted value
82
+ * (a `srcdoc` holds `<` and `>`), read at most `MOST_TAG_CHARS` far: linear in what it reads.
83
+ */
84
+ function tagText(content, from) {
85
+ const end = Math.min(content.length, from + MOST_TAG_CHARS);
86
+ let quote = "";
87
+ for (let at = from; at < end; at += 1) {
88
+ const char = content[at];
89
+ if (quote !== "") {
90
+ if (char === quote) {
91
+ quote = "";
92
+ }
93
+ }
94
+ else if (char === '"' || char === "'") {
95
+ quote = char;
96
+ }
97
+ else if (char === ">") {
98
+ return content.slice(from, at);
99
+ }
100
+ }
101
+ return content.slice(from, end);
102
+ }
103
+ /**
104
+ * Under `nestedFrames: "own"` (P128), the first frame-like element that never loads, and why: a
105
+ * `<frame>`, `<object>` or `<embed>`; an `<iframe>` of another site (any scheme, `//`), of the
106
+ * origin's root (`/`), or with neither `src` nor `srcdoc`; one with a relative `src` where there
107
+ * are no files to frame (`relative`: false). Null where every frame is the page's own.
108
+ */
109
+ function strayFrame(content, relative) {
110
+ let read = 0;
111
+ for (const match of content.matchAll(/<(iframe|frame|object|embed)\b/giu)) {
112
+ read += 1;
113
+ if (read > MOST_FRAMES) {
114
+ break;
115
+ }
116
+ const tag = (match[1] ?? "").toLowerCase();
117
+ if (tag !== "iframe") {
118
+ return { tag, src: "", index: match.index };
119
+ }
120
+ const attributes = attributesOf(tagText(content, match.index + match[0].length));
121
+ if (attributes.some((each) => each.name === "srcdoc")) {
122
+ continue;
123
+ }
124
+ const src = (attributes.find((each) => each.name === "src")?.value ?? "").trim();
125
+ const elsewhere = src === "" ||
126
+ /^[a-z][a-z0-9+.-]*:/iu.test(src) ||
127
+ src.startsWith("/") ||
128
+ src.startsWith("\\") ||
129
+ !relative;
130
+ if (elsewhere) {
131
+ return { tag, src, index: match.index };
132
+ }
133
+ }
134
+ return null;
135
+ }
74
136
  export function lintContent(config, content) {
75
137
  return lintPage(config, content, { scrollLock: true });
76
138
  }
@@ -106,9 +168,26 @@ export function lintPage(config, content, options) {
106
168
  }
107
169
  }
108
170
  }
109
- const frame = /<(iframe|frame|object|embed)\b/iu.exec(content);
110
- if (frame !== null) {
111
- add("nested-frame", "error", `Remove the <${frame[1]?.toLowerCase()}>: nested frames and plugins are taken out of a ${it} and never run. Draw it inline instead.`, frame.index);
171
+ if (config.nestedFrames === "own") {
172
+ // A page's own frames load (P128): only what never does is said.
173
+ const files = servesFiles(config);
174
+ const own = files
175
+ ? 'an <iframe> of one of its own files (a relative src, src="chart.html") or with srcdoc does'
176
+ : "an <iframe> with srcdoc does";
177
+ const stray = strayFrame(content, files);
178
+ if (stray !== null) {
179
+ add("nested-frame", "error", stray.tag !== "iframe"
180
+ ? `Remove the <${stray.tag}>: <frame>, <object> and <embed> are taken out of a ${it} and never run; ${own}.`
181
+ : stray.src === ""
182
+ ? `This <iframe> has neither src nor srcdoc, and is taken out of the ${it}: ${own}.`
183
+ : `Remove the <iframe src="${stray.src.slice(0, 200)}">: ${files ? "frames of other sites (or of another path of the address) are" : "frames of an address are"} taken out of a ${it} and never load; ${own}.`, stray.index);
184
+ }
185
+ }
186
+ else {
187
+ const frame = /<(iframe|frame|object|embed)\b/iu.exec(content);
188
+ if (frame !== null) {
189
+ add("nested-frame", "error", `Remove the <${frame[1]?.toLowerCase()}>: nested frames and plugins are taken out of a ${it} and never run. Draw it inline instead.`, frame.index);
190
+ }
112
191
  }
113
192
  const write = /\bdocument\s*\.\s*write(?:ln)?\s*\(/u.exec(content);
114
193
  if (write !== null) {