@botiverse/porthole 0.3.4 → 0.3.5
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 +2 -0
- package/dist/check/page-source.js +1 -1
- package/dist/conformance/harness-source.js +1 -1
- package/dist/guide/guide.js +18 -11
- package/docs/ADOPTING.md +40 -0
- package/docs/DESIGN.md +3 -1
- package/package.json +1 -1
- package/src/guide/guide.ts +21 -12
package/dist/guide/guide.js
CHANGED
|
@@ -39,6 +39,13 @@ const KIND_WORDS = {
|
|
|
39
39
|
};
|
|
40
40
|
/** What the manual calls `https:` (any https site), where a config opens passive kinds to it. */
|
|
41
41
|
export const ANY_HTTPS_SITE = "any https site";
|
|
42
|
+
/** Kinds in words, as a list: "fonts, images, audio and video" (media's two words are two items). */
|
|
43
|
+
const kindsInWords = (kinds) => {
|
|
44
|
+
const words = kinds.flatMap((kind) => kind === "media" ? ["audio", "video"] : [KIND_WORDS[kind]]);
|
|
45
|
+
return words.length === 1
|
|
46
|
+
? (words[0] ?? "")
|
|
47
|
+
: `${words.slice(0, -1).join(", ")} and ${words.at(-1)}`;
|
|
48
|
+
};
|
|
42
49
|
/** The sources content may load `kind` from, as the manual names them: origins, any https site. */
|
|
43
50
|
const sourcesFor = (config, kind) => [
|
|
44
51
|
...(anyHttps(config, kind) ? [ANY_HTTPS_SITE] : []),
|
|
@@ -60,15 +67,18 @@ function network(config) {
|
|
|
60
67
|
byOrigin.set(origin, [...(byOrigin.get(origin) ?? []), kind]);
|
|
61
68
|
}
|
|
62
69
|
}
|
|
70
|
+
// Any https site last, the widest: "…; fonts, images, audio and video from any https site" (P059).
|
|
71
|
+
const anywhere = byOrigin.get(ANY_HTTPS_SITE);
|
|
72
|
+
byOrigin.delete(ANY_HTTPS_SITE);
|
|
63
73
|
const groups = new Map();
|
|
64
74
|
for (const [origin, each] of byOrigin) {
|
|
65
|
-
const
|
|
66
|
-
const key = words.length === 1
|
|
67
|
-
? (words[0] ?? "")
|
|
68
|
-
: `${words.slice(0, -1).join(", ")} and ${words.at(-1)}`;
|
|
75
|
+
const key = kindsInWords(each);
|
|
69
76
|
groups.set(key, [...(groups.get(key) ?? []), origin]);
|
|
70
77
|
}
|
|
71
|
-
const parts = [
|
|
78
|
+
const parts = [
|
|
79
|
+
...[...groups].map(([words, origins]) => `${words} from ${origins.join(", ")}`),
|
|
80
|
+
...(anywhere === undefined ? [] : [`${kindsInWords(anywhere)} from ${ANY_HTTPS_SITE}`]),
|
|
81
|
+
];
|
|
72
82
|
return `Network: only ${parts.join("; ")}. Anything else fails.`;
|
|
73
83
|
}
|
|
74
84
|
/** Whether a whole document takes the theme only when it declares support (ThemeConfig.documents). */
|
|
@@ -246,12 +256,9 @@ export function generateToolDescription(config) {
|
|
|
246
256
|
const origins = [
|
|
247
257
|
...new Set(["script", "style", "font", "img", "media", "connect"].flatMap((kind) => egressOrigins(config, kind))),
|
|
248
258
|
];
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const fromAnywhere = passive.length === 0
|
|
253
|
-
? ""
|
|
254
|
-
: `${passive.length === 1 ? passive[0] : `${passive.slice(0, -1).join(", ")} and ${passive.at(-1)}`} from ${ANY_HTTPS_SITE}`;
|
|
259
|
+
// The same words, in the same order, as the manual's Network line.
|
|
260
|
+
const passive = ["font", "img", "media"].filter((kind) => anyHttps(config, kind));
|
|
261
|
+
const fromAnywhere = passive.length === 0 ? "" : `${kindsInWords(passive)} from ${ANY_HTTPS_SITE}`;
|
|
255
262
|
const net = origins.length === 0 && fromAnywhere === ""
|
|
256
263
|
? "with no network (nothing loads from outside)"
|
|
257
264
|
: origins.length === 0
|
package/docs/ADOPTING.md
CHANGED
|
@@ -42,6 +42,46 @@ manual tells the agent so (the page scrolls itself; `position: fixed` works). `M
|
|
|
42
42
|
and `<PortholeFrame fill>` are deprecated: they size the frame but leave the manual saying the
|
|
43
43
|
height follows the content.
|
|
44
44
|
|
|
45
|
+
### Choosing egress
|
|
46
|
+
|
|
47
|
+
Egress is what content may load and send out: scripts, styles, fonts, images, audio and video, and
|
|
48
|
+
data (fetch, WebSocket). Every preset starts closed, and a kind opens more only through its
|
|
49
|
+
`options.egress`. There are three levels:
|
|
50
|
+
|
|
51
|
+
| Level | Config (`options`) | What it opens | The risk it re-opens | Typical host | The agent's manual says | Why | Tested by |
|
|
52
|
+
| --- | --- | --- | --- | --- | --- | --- | --- |
|
|
53
|
+
| **Closed** (the default) | nothing to write | Nothing from outside the frame: content runs on what it carries (inline code, `data:` and `blob:` URLs). | None. | Widgets that draw their own SVG and CSS; any host that hasn't decided yet. | `Network: none. Nothing loads from outside` (and `write everything inline`) | [P006](DECISIONS.md#p006--2026-10-11--egress-is-closed-by-default-including-channels-a-frame-csp-doesnt-cover--accepted), [P022](DECISIONS.md#p022--2026-10-11--every-preset-starts-with-egress-closed-library-cdns-are-a-one-line-opt-in--accepted) | probes `1.connect`, `2.resources`, `3.webrtc`, `4.*` (nested frames), `5.*` (navigating out), `8.*` (resource hints), `10.self`; served `served.domain.egress` |
|
|
54
|
+
| **Library CDNs** (`LIBRARY_CDNS`, plus script hosts of your own) | `egress: LIBRARY_CDNS`; more script hosts: `egress: { ...LIBRARY_CDNS, script: [...LIBRARY_CDNS.script, "https://cdn.example.com"] }` | Scripts, styles, fonts, images and data from cdnjs, jsDelivr, unpkg and esm.sh; Google Fonts. Nothing else. | Code you don't control runs in the frame (a compromised or look-alike package), still inside the sandbox and egress; and a path requested from a CDN is a narrow channel out, read by the CDN's operator. The manual tells agents to pin versions. | Ferry's widgets (`LIBRARY_CDNS`), Raft Artifacts' pages (`LIBRARY_CDNS` and a few script hosts of its own): agents load Chart.js, ECharts, d3, Mermaid. | `scripts, styles, fonts, images and data (fetch, WebSocket) from https://cdnjs.cloudflare.com` … and `pin an exact version` | [P022](DECISIONS.md#p022--2026-10-11--every-preset-starts-with-egress-closed-library-cdns-are-a-one-line-opt-in--accepted), [P048](DECISIONS.md#p048--2026-10-11--artifact-pages-reach-library-cdns-only-by-the-hosts-config--accepted) | `leak/cdn.spec.ts` (a CDN library loads only when the config opens it, opaque and served; another origin never); probes `1.connect`, `2.resources` (an allowed origin loads, no other does) |
|
|
55
|
+
| **Passive from any https site** (`anyHttps`, on top of either) | `egress: { ...LIBRARY_CDNS, anyHttps: ["img"] }`; closed but for them: `egress: { anyHttps: ["img"] }` | The passive kinds you name (`img`, `media`, `font`) from any https site. Never scripts, styles, data, workers or frames, and never `http:`: a config naming another kind is refused. | Any site an image names learns that someone viewed the content, and from which address; content can send data out in an image URL to a server of its choosing (the channel P006 closes); whoever owns an image controls what it shows, inside the frame. | A host showing content that already exists, with hotlinked media: Raft's HTML attachment previews, reports whose `<img>` point at other sites (the case P059 was written for). | `images from any https site` (`fonts, images, audio and video from any https site` for all three) | [P059](DECISIONS.md#p059--2026-10-11--passive-content-may-load-from-any-https-site-by-the-hosts-explicit-choice--accepted), [P062](DECISIONS.md#p062--2026-10-11--serveddomainegress-holds-a-host-to-its-own-configs-egress--accepted) | `leak/cdn.spec.ts` (a hotlinked image loads; a script, a stylesheet and a fetch to the same site never reach it; without the flag, nothing does); served `served.domain.egress` (the image must reach an https canary; scripts, styles, fetches and frames never), `leak/served/any-https.spec.ts` |
|
|
56
|
+
|
|
57
|
+
How to decide: **start closed; add `LIBRARY_CDNS` if agents use libraries; add passive `anyHttps`
|
|
58
|
+
only for existing content with hotlinks**, and only the kinds it hotlinks (usually `img`). An
|
|
59
|
+
agent writing new content can inline what it shows, so agent-made pages never need `anyHttps`.
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
import { defineDisplays, LIBRARY_CDNS } from "@botiverse/porthole";
|
|
63
|
+
|
|
64
|
+
export const displays = defineDisplays({
|
|
65
|
+
// Closed: nothing to write.
|
|
66
|
+
widget: { preset: "inlineWidget" },
|
|
67
|
+
// Library CDNs (and, if you need one, a script host of your own).
|
|
68
|
+
artifact: { preset: "artifact", options: { egress: { ...LIBRARY_CDNS, script: [...(LIBRARY_CDNS.script ?? []), "https://cdn.example.com"] } } },
|
|
69
|
+
// Existing pages with hotlinked images: Library CDNs, and images from any https site.
|
|
70
|
+
attachment: { preset: "artifact", options: { egress: { ...LIBRARY_CDNS, anyHttps: ["img"] } } },
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
- Each kind's documents name it as their preset (`document.preset: "attachment"`); `egress` is
|
|
75
|
+
the kind's whole policy, so kinds that differ in egress are kinds of their own.
|
|
76
|
+
- Origins are exact (`https://cdn.example.com`), or `https://*.` a domain of your own; a wildcard
|
|
77
|
+
over a public suffix (`*.com`, `*.github.io`) is refused.
|
|
78
|
+
- An opaque frame also inherits your page's CSP ([P058](DECISIONS.md#p058--2026-10-11--an-opaque-frame-is-as-closed-as-its-page-the-suite-says-when-a-case-cant-be-observed--accepted)): where your page closes images or
|
|
79
|
+
fetches, opaque content is that closed whatever its egress opens (see "The page's CSP"). A
|
|
80
|
+
served frame has only its own policy.
|
|
81
|
+
- `checkPage` and `lintContent` tell the agent when its content reaches past the kind's egress, by
|
|
82
|
+
directive. The manual names exactly the origins the CSP allows (`test/agreement.test.ts`), and
|
|
83
|
+
DESIGN.md § "Egress hardening, each with its test" is the long form.
|
|
84
|
+
|
|
45
85
|
## 3. Opaque displays: the page only
|
|
46
86
|
|
|
47
87
|
```js
|
package/docs/DESIGN.md
CHANGED
|
@@ -748,7 +748,9 @@ absent.
|
|
|
748
748
|
|
|
749
749
|
## Egress hardening, each with its test
|
|
750
750
|
|
|
751
|
-
Closed by default; opened only to origins the config declares.
|
|
751
|
+
Closed by default; opened only to origins the config declares. For a host choosing a level
|
|
752
|
+
(closed, library CDNs, passive media from any https site), ADOPTING.md § "Choosing egress" is the
|
|
753
|
+
summary; this section is the long form. The leak suite
|
|
752
754
|
(`src/conformance/probes.ts`, run by `pnpm test:leak` against the reference host)
|
|
753
755
|
attempts each channel from inside the content, as an agent's code would, and asserts
|
|
754
756
|
with an out-of-band oracle that nothing left: an HTTP canary that also counts raw TCP
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botiverse/porthole",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "A host-side sandbox for agent-made HTML: isolation, egress hardening, a themed shell, gated host functions, and the agent manual, from one config.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"bin": {
|
package/src/guide/guide.ts
CHANGED
|
@@ -87,6 +87,16 @@ const KIND_WORDS: Readonly<Record<EgressKind, string>> = {
|
|
|
87
87
|
/** What the manual calls `https:` (any https site), where a config opens passive kinds to it. */
|
|
88
88
|
export const ANY_HTTPS_SITE = "any https site";
|
|
89
89
|
|
|
90
|
+
/** Kinds in words, as a list: "fonts, images, audio and video" (media's two words are two items). */
|
|
91
|
+
const kindsInWords = (kinds: readonly EgressKind[]): string => {
|
|
92
|
+
const words = kinds.flatMap((kind) =>
|
|
93
|
+
kind === "media" ? ["audio", "video"] : [KIND_WORDS[kind]],
|
|
94
|
+
);
|
|
95
|
+
return words.length === 1
|
|
96
|
+
? (words[0] ?? "")
|
|
97
|
+
: `${words.slice(0, -1).join(", ")} and ${words.at(-1)}`;
|
|
98
|
+
};
|
|
99
|
+
|
|
90
100
|
/** The sources content may load `kind` from, as the manual names them: origins, any https site. */
|
|
91
101
|
const sourcesFor = (config: PortholeConfig, kind: EgressKind): string[] => [
|
|
92
102
|
...(anyHttps(config, kind) ? [ANY_HTTPS_SITE] : []),
|
|
@@ -109,16 +119,18 @@ function network(config: PortholeConfig): string {
|
|
|
109
119
|
byOrigin.set(origin, [...(byOrigin.get(origin) ?? []), kind]);
|
|
110
120
|
}
|
|
111
121
|
}
|
|
122
|
+
// Any https site last, the widest: "…; fonts, images, audio and video from any https site" (P059).
|
|
123
|
+
const anywhere = byOrigin.get(ANY_HTTPS_SITE);
|
|
124
|
+
byOrigin.delete(ANY_HTTPS_SITE);
|
|
112
125
|
const groups = new Map<string, string[]>();
|
|
113
126
|
for (const [origin, each] of byOrigin) {
|
|
114
|
-
const
|
|
115
|
-
const key =
|
|
116
|
-
words.length === 1
|
|
117
|
-
? (words[0] ?? "")
|
|
118
|
-
: `${words.slice(0, -1).join(", ")} and ${words.at(-1)}`;
|
|
127
|
+
const key = kindsInWords(each);
|
|
119
128
|
groups.set(key, [...(groups.get(key) ?? []), origin]);
|
|
120
129
|
}
|
|
121
|
-
const parts = [
|
|
130
|
+
const parts = [
|
|
131
|
+
...[...groups].map(([words, origins]) => `${words} from ${origins.join(", ")}`),
|
|
132
|
+
...(anywhere === undefined ? [] : [`${kindsInWords(anywhere)} from ${ANY_HTTPS_SITE}`]),
|
|
133
|
+
];
|
|
122
134
|
return `Network: only ${parts.join("; ")}. Anything else fails.`;
|
|
123
135
|
}
|
|
124
136
|
|
|
@@ -416,13 +428,10 @@ export function generateToolDescription(config: PortholeConfig): string {
|
|
|
416
428
|
),
|
|
417
429
|
),
|
|
418
430
|
];
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
.map((kind) => KIND_WORDS[kind]);
|
|
431
|
+
// The same words, in the same order, as the manual's Network line.
|
|
432
|
+
const passive = (["font", "img", "media"] as const).filter((kind) => anyHttps(config, kind));
|
|
422
433
|
const fromAnywhere =
|
|
423
|
-
passive.length === 0
|
|
424
|
-
? ""
|
|
425
|
-
: `${passive.length === 1 ? passive[0] : `${passive.slice(0, -1).join(", ")} and ${passive.at(-1)}`} from ${ANY_HTTPS_SITE}`;
|
|
434
|
+
passive.length === 0 ? "" : `${kindsInWords(passive)} from ${ANY_HTTPS_SITE}`;
|
|
426
435
|
const net =
|
|
427
436
|
origins.length === 0 && fromAnywhere === ""
|
|
428
437
|
? "with no network (nothing loads from outside)"
|