@botiverse/porthole 0.6.0 → 0.8.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 +25 -2
- package/THIRD_PARTY_NOTICES.md +421 -0
- package/dist/bridge/bounded-text.d.ts +34 -0
- package/dist/bridge/bounded-text.js +188 -0
- package/dist/bridge/bridge.d.ts +38 -5
- package/dist/bridge/bridge.js +469 -39
- package/dist/bridge/json-data.d.ts +28 -0
- package/dist/bridge/json-data.js +86 -0
- package/dist/bridge/navigation.d.ts +5 -0
- package/dist/bridge/navigation.js +7 -0
- package/dist/bridge/refusal.d.ts +5 -1
- package/dist/bridge/refusal.js +17 -0
- package/dist/bridge/types.d.ts +73 -5
- package/dist/check/check.d.ts +7 -0
- package/dist/check/check.js +1 -0
- package/dist/check/instrument.d.ts +3 -0
- package/dist/check/lint.js +4 -2
- package/dist/check/page-source.js +1 -1
- package/dist/check/page.js +16 -0
- package/dist/check/tools.js +2 -3
- package/dist/compile/compile.d.ts +6 -0
- package/dist/compile/compile.js +3 -1
- package/dist/compile/policy.d.ts +55 -0
- package/dist/compile/policy.js +157 -0
- package/dist/config/capabilities.d.ts +85 -7
- package/dist/config/capabilities.js +32 -2
- package/dist/config/schema.d.ts +35 -0
- package/dist/config/validate.d.ts +9 -3
- package/dist/config/validate.js +92 -8
- package/dist/config/warnings.d.ts +20 -0
- package/dist/config/warnings.js +25 -0
- package/dist/conformance/behavior.js +46 -1
- package/dist/conformance/cookies.d.ts +15 -0
- package/dist/conformance/cookies.js +80 -0
- package/dist/conformance/harness/page.d.ts +1 -0
- package/dist/conformance/harness/page.js +9 -2
- package/dist/conformance/harness-source.js +1 -1
- package/dist/conformance/host-kit.js +5 -1
- package/dist/conformance/index.d.ts +11 -0
- package/dist/conformance/index.js +2 -0
- package/dist/conformance/limits.js +38 -1
- package/dist/conformance/runtime.d.ts +58 -0
- package/dist/conformance/runtime.js +324 -0
- package/dist/conformance/served.d.ts +2 -0
- package/dist/conformance/served.js +737 -4
- package/dist/files/paths.js +4 -0
- package/dist/guide/gates.d.ts +9 -0
- package/dist/guide/gates.js +31 -0
- package/dist/guide/guide.d.ts +2 -0
- package/dist/guide/guide.js +35 -33
- package/dist/guide/limits.js +4 -4
- package/dist/guide/runtime.d.ts +13 -0
- package/dist/guide/runtime.js +210 -0
- package/dist/host/create-host.js +73 -37
- package/dist/host/locate.js +8 -0
- package/dist/host/locator.js +7 -0
- package/dist/host/pages-of-set.d.ts +43 -0
- package/dist/host/pages-of-set.js +196 -0
- package/dist/host/types.d.ts +26 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.js +11 -2
- package/dist/isolation/types.d.ts +8 -0
- package/dist/mcp/adapter.js +11 -15
- package/dist/node/index.d.ts +36 -4
- package/dist/node/index.js +402 -101
- package/dist/presets/presets.d.ts +22 -8
- package/dist/presets/presets.js +40 -8
- package/dist/protocol/live-data.d.ts +6 -2
- package/dist/protocol/live-data.js +20 -1
- package/dist/protocol/mcp-apps.d.ts +13 -2
- package/dist/protocol/mcp-apps.js +10 -2
- package/dist/protocol/message-text.d.ts +8 -0
- package/dist/protocol/message-text.js +29 -0
- package/dist/protocol/runtime-calls.d.ts +28 -0
- package/dist/protocol/runtime-calls.js +116 -0
- package/dist/protocol/shell-adapter.js +64 -25
- package/dist/react/context-notice.d.ts +32 -0
- package/dist/react/context-notice.js +28 -0
- package/dist/react/dialog.js +91 -16
- package/dist/react/frame.d.ts +25 -1
- package/dist/react/frame.js +85 -2
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/runtime/contract.d.ts +201 -0
- package/dist/runtime/contract.js +245 -0
- package/dist/runtime/db.d.ts +188 -0
- package/dist/runtime/db.js +502 -0
- package/dist/runtime/declaration.d.ts +100 -0
- package/dist/runtime/declaration.js +363 -0
- package/dist/runtime/levels.d.ts +33 -0
- package/dist/runtime/levels.js +41 -0
- package/dist/runtime/requests.d.ts +125 -0
- package/dist/runtime/requests.js +215 -0
- package/dist/runtime/segments.d.ts +8 -0
- package/dist/runtime/segments.js +14 -0
- package/dist/runtime/types.generated.d.ts +1 -0
- package/dist/runtime/types.generated.js +19 -0
- package/dist/server/files.d.ts +19 -1
- package/dist/server/files.js +115 -6
- package/dist/server/host.d.ts +24 -2
- package/dist/server/host.js +137 -2
- package/dist/server/index.d.ts +3 -2
- package/dist/server/index.js +2 -1
- package/dist/server/peer.d.ts +4 -0
- package/dist/server/peer.js +19 -0
- package/dist/server/proxy.d.ts +6 -0
- package/dist/server/proxy.js +12 -3
- package/dist/server/pseudonym.d.ts +9 -0
- package/dist/server/pseudonym.js +20 -0
- package/dist/server/server.d.ts +0 -5
- package/dist/server/server.js +318 -52
- package/dist/server/types.d.ts +74 -2
- package/dist/shell/document.d.ts +16 -0
- package/dist/shell/document.js +19 -2
- package/dist/shell/legacy.d.ts +21 -0
- package/dist/shell/legacy.js +63 -0
- package/dist/shell/plan.d.ts +17 -1
- package/dist/shell/plan.js +13 -2
- package/dist/shell/runtime.js +390 -56
- package/dist/shell/use.d.ts +15 -0
- package/dist/shell/use.js +235 -0
- package/docs/ADOPTING.md +205 -15
- package/docs/ARCHITECTURE.md +34 -5
- package/docs/DECISIONS.md +1867 -11
- package/docs/DESIGN.md +137 -17
- package/docs/THREAT_MODEL.md +616 -0
- package/package.json +16 -3
- package/src/bridge/bounded-text.ts +240 -0
- package/src/bridge/bridge.ts +601 -51
- package/src/bridge/json-data.ts +95 -0
- package/src/bridge/navigation.ts +10 -0
- package/src/bridge/refusal.ts +17 -0
- package/src/bridge/types.ts +76 -5
- package/src/check/check.ts +8 -0
- package/src/check/instrument.ts +3 -0
- package/src/check/lint.ts +4 -2
- package/src/check/page.ts +16 -0
- package/src/check/tools.ts +2 -3
- package/src/compile/compile.ts +9 -1
- package/src/compile/policy.ts +177 -0
- package/src/config/capabilities.ts +71 -5
- package/src/config/schema.ts +35 -0
- package/src/config/validate.ts +141 -8
- package/src/config/warnings.ts +42 -0
- package/src/conformance/behavior.ts +54 -1
- package/src/conformance/cookies.ts +93 -0
- package/src/conformance/harness/page.ts +11 -2
- package/src/conformance/host-kit.ts +10 -1
- package/src/conformance/index.ts +17 -0
- package/src/conformance/limits.ts +39 -1
- package/src/conformance/runtime.ts +594 -0
- package/src/conformance/served.ts +888 -4
- package/src/files/paths.ts +4 -0
- package/src/guide/gates.ts +37 -0
- package/src/guide/guide.ts +61 -55
- package/src/guide/limits.ts +4 -4
- package/src/guide/runtime.ts +253 -0
- package/src/host/create-host.ts +88 -36
- package/src/host/locate.ts +10 -0
- package/src/host/locator.ts +11 -0
- package/src/host/pages-of-set.ts +226 -0
- package/src/host/types.ts +33 -1
- package/src/index.ts +94 -0
- package/src/isolation/types.ts +8 -0
- package/src/mcp/adapter.ts +16 -20
- package/src/node/index.ts +507 -116
- package/src/presets/presets.ts +67 -17
- package/src/protocol/live-data.ts +31 -3
- package/src/protocol/mcp-apps.ts +11 -2
- package/src/protocol/message-text.ts +36 -0
- package/src/protocol/runtime-calls.ts +141 -0
- package/src/protocol/shell-adapter.ts +79 -26
- package/src/react/context-notice.tsx +95 -0
- package/src/react/dialog.tsx +108 -15
- package/src/react/frame.tsx +120 -0
- package/src/react/index.ts +8 -1
- package/src/runtime/contract.ts +339 -0
- package/src/runtime/db.ts +650 -0
- package/src/runtime/declaration.ts +516 -0
- package/src/runtime/levels.ts +69 -0
- package/src/runtime/requests.ts +355 -0
- package/src/runtime/segments.ts +17 -0
- package/src/runtime/types.generated.ts +19 -0
- package/src/server/files.ts +138 -7
- package/src/server/host.ts +170 -3
- package/src/server/index.ts +4 -0
- package/src/server/peer.ts +21 -0
- package/src/server/proxy.ts +13 -3
- package/src/server/pseudonym.ts +21 -0
- package/src/server/server.ts +370 -57
- package/src/server/types.ts +73 -2
- package/src/shell/document.ts +29 -4
- package/src/shell/legacy.ts +64 -0
- package/src/shell/plan.ts +37 -3
- package/src/shell/runtime.ts +390 -56
- package/src/shell/use.ts +235 -0
- package/types/runtime/v1/artifact.d.ts +50 -0
- package/types/runtime/v1/assets.d.ts +43 -0
- package/types/runtime/v1/chat.d.ts +13 -0
- package/types/runtime/v1/clipboard.d.ts +14 -0
- package/types/runtime/v1/comments.d.ts +24 -0
- package/types/runtime/v1/context.d.ts +27 -0
- package/types/runtime/v1/data.d.ts +29 -0
- package/types/runtime/v1/db.d.ts +110 -0
- package/types/runtime/v1/downloads.d.ts +22 -0
- package/types/runtime/v1/links.d.ts +13 -0
- package/types/runtime/v1/porthole.d.ts +44 -0
- package/types/runtime/v1/user.d.ts +19 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON data, as a host function carries it to a host's handler and its dialog (P095, after the
|
|
3
|
+
* review): what `callTool`'s arguments, `setModelContext`'s content and a download's contents are
|
|
4
|
+
* in MCP, and what a host forwards to a server or a model as JSON. A frame's messages come
|
|
5
|
+
* structured-cloned, so they can hold what JSON can't say or says otherwise: a cycle, an object
|
|
6
|
+
* reached twice (a graph of 30 is 2^30 nodes as a tree), a BigInt, NaN, a boxed `String` (JSON
|
|
7
|
+
* writes its value; a handler gets an object), a Map, a typed array, a Date.
|
|
8
|
+
*
|
|
9
|
+
* Plain data only: null, booleans, finite numbers, strings, arrays and objects whose prototype is
|
|
10
|
+
* Object's or none, each object reached once (MCP's arguments are JSON: an object in two places is
|
|
11
|
+
* refused, the simple bound), at most `nodes` values (a field left `undefined`, allowed as JSON
|
|
12
|
+
* leaves it out, counts as one), `depth` levels, and `chars` characters of strings and keys
|
|
13
|
+
* together (after the re-review: neither a field without a value nor a long string is free).
|
|
14
|
+
* Each node is visited once: linear in what was sent, stopped at the budget. Never throws (a
|
|
15
|
+
* value whose read throws is no data).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export interface JsonDataLimits {
|
|
19
|
+
readonly nodes: number;
|
|
20
|
+
readonly depth: number;
|
|
21
|
+
/** The characters of every string and every key, together. */
|
|
22
|
+
readonly chars: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A call's: as many values as one db document holds (P091), nested deeper than any real one, and
|
|
27
|
+
* 4 MiB of text.
|
|
28
|
+
*/
|
|
29
|
+
export const JSON_DATA_LIMITS: JsonDataLimits = { nodes: 100_000, depth: 64, chars: 4_194_304 };
|
|
30
|
+
|
|
31
|
+
export function isJsonData(value: unknown, limits: JsonDataLimits = JSON_DATA_LIMITS): boolean {
|
|
32
|
+
let nodes = limits.nodes;
|
|
33
|
+
let chars = limits.chars;
|
|
34
|
+
const seen = new WeakSet<object>();
|
|
35
|
+
/** Takes `length` characters from the budget: whether it still holds. */
|
|
36
|
+
const text = (length: number): boolean => {
|
|
37
|
+
chars -= length;
|
|
38
|
+
return chars >= 0;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function plain(each: unknown, depth: number): boolean {
|
|
42
|
+
nodes -= 1;
|
|
43
|
+
if (nodes < 0 || depth > limits.depth) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (typeof each === "string") {
|
|
47
|
+
return text(each.length);
|
|
48
|
+
}
|
|
49
|
+
if (each === null || typeof each === "boolean") {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (typeof each === "number") {
|
|
53
|
+
return Number.isFinite(each);
|
|
54
|
+
}
|
|
55
|
+
if (typeof each !== "object" || seen.has(each)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
seen.add(each);
|
|
59
|
+
if (Array.isArray(each)) {
|
|
60
|
+
const list = each as readonly unknown[];
|
|
61
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
62
|
+
if (!plain(list[index], depth + 1)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
const proto: unknown = Object.getPrototypeOf(each);
|
|
69
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
for (const key of Object.keys(each)) {
|
|
73
|
+
if (!text(key.length)) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const field = (each as Record<string, unknown>)[key];
|
|
77
|
+
if (field === undefined) {
|
|
78
|
+
// No value, but a field: it counts.
|
|
79
|
+
nodes -= 1;
|
|
80
|
+
if (nodes < 0) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
} else if (!plain(field, depth + 1)) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
return plain(value, 0);
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
package/src/bridge/navigation.ts
CHANGED
|
@@ -14,6 +14,16 @@ import type { PortholeConfig } from "../config/schema.ts";
|
|
|
14
14
|
const SEALED = /(?:https?:\/\/[^\s"'<>/]+)?\/__porthole\/f\/[A-Za-z0-9_-]{20,}\//gu;
|
|
15
15
|
export const withoutSealedAddresses = (text: string): string => text.replace(SEALED, "./");
|
|
16
16
|
|
|
17
|
+
/** A sealed address's access, cut off by the end of the text: no longer one `SEALED` matches. */
|
|
18
|
+
const UNFINISHED = /\/__porthole\/f\/[A-Za-z0-9_-]*$/u;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* `text`, at most `max` characters (S05, P095): a cut inside a sealed address's access drops what
|
|
22
|
+
* of it is left, so a text cut before it is scrubbed tells no part of one.
|
|
23
|
+
*/
|
|
24
|
+
export const cutText = (text: string, max: number): string =>
|
|
25
|
+
text.length <= max ? text : text.slice(0, max).replace(UNFINISHED, "");
|
|
26
|
+
|
|
17
27
|
/** An address without what could carry data: an http(s) one's origin and path, else its scheme. */
|
|
18
28
|
export function addressWithoutQuery(url: string): string {
|
|
19
29
|
// A page's own file (P084), as the shell names it: its path, without query or fragment.
|
package/src/bridge/refusal.ts
CHANGED
|
@@ -12,6 +12,10 @@ import type { Refusal } from "./types.ts";
|
|
|
12
12
|
* - `not_allowed`: the host doesn't let this content have it, here or at all (a URI it doesn't
|
|
13
13
|
* serve, a page where data never runs).
|
|
14
14
|
* - `failed`: the host tried and couldn't.
|
|
15
|
+
* - `forbidden` (P087): the person viewing it may see the content but not do this (their level).
|
|
16
|
+
* - `conflict` (P088): what it changes moved since it was read (a document's version, the
|
|
17
|
+
* artifact's base): read it again, then write.
|
|
18
|
+
* - `too_large` (P088): more than a limit (a document, a batch, an upload, a publish).
|
|
15
19
|
*/
|
|
16
20
|
export const REFUSAL_CODES = [
|
|
17
21
|
"consent_required",
|
|
@@ -19,6 +23,9 @@ export const REFUSAL_CODES = [
|
|
|
19
23
|
"rate_limited",
|
|
20
24
|
"not_allowed",
|
|
21
25
|
"failed",
|
|
26
|
+
"forbidden",
|
|
27
|
+
"conflict",
|
|
28
|
+
"too_large",
|
|
22
29
|
] as const;
|
|
23
30
|
|
|
24
31
|
export type RefusalCode = (typeof REFUSAL_CODES)[number];
|
|
@@ -89,6 +96,9 @@ const DEFAULT_MESSAGES: { readonly [Code in RefusalCode]: string } = {
|
|
|
89
96
|
rate_limited: "Too many requests: try again in a minute.",
|
|
90
97
|
not_allowed: "This isn't available here.",
|
|
91
98
|
failed: "The app couldn't do this.",
|
|
99
|
+
forbidden: "You don't have permission to do this here.",
|
|
100
|
+
conflict: "This changed since it was read: read it again, then try again.",
|
|
101
|
+
too_large: "This is too large.",
|
|
92
102
|
};
|
|
93
103
|
|
|
94
104
|
/** Where a data capability's words differ: they name the data. */
|
|
@@ -98,6 +108,9 @@ const DATA_MESSAGES: { readonly [Code in RefusalCode]: string } = {
|
|
|
98
108
|
rate_limited: "Too many data requests: try again in a minute.",
|
|
99
109
|
not_allowed: "This data isn't available here.",
|
|
100
110
|
failed: "The app couldn't get this data.",
|
|
111
|
+
forbidden: "You don't have permission to read this data.",
|
|
112
|
+
conflict: DEFAULT_MESSAGES.conflict,
|
|
113
|
+
too_large: DEFAULT_MESSAGES.too_large,
|
|
101
114
|
};
|
|
102
115
|
|
|
103
116
|
/** Each refusal's code, as content is told it. */
|
|
@@ -110,9 +123,13 @@ const CODES: { readonly [R in Refusal]: RefusalCode } = {
|
|
|
110
123
|
redirected: "denied",
|
|
111
124
|
muted: "denied",
|
|
112
125
|
"no-consent": "not_allowed",
|
|
126
|
+
"no-show": "not_allowed",
|
|
113
127
|
denied: "denied",
|
|
114
128
|
"rate-limited": "rate_limited",
|
|
115
129
|
failed: "failed",
|
|
130
|
+
undeclared: "not_allowed",
|
|
131
|
+
level: "forbidden",
|
|
132
|
+
"too-large": "too_large",
|
|
116
133
|
};
|
|
117
134
|
|
|
118
135
|
/** Refusals whose own words say more than their code's. */
|
package/src/bridge/types.ts
CHANGED
|
@@ -5,6 +5,9 @@ import type {
|
|
|
5
5
|
HandledCapability,
|
|
6
6
|
} from "../config/capabilities.ts";
|
|
7
7
|
import type { InstanceRef } from "../isolation/types.ts";
|
|
8
|
+
import type { RuntimeCapabilityName } from "../runtime/contract.ts";
|
|
9
|
+
import type { DeclaredData, DeclaredDb } from "../runtime/declaration.ts";
|
|
10
|
+
import type { ViewerInfo } from "../runtime/levels.ts";
|
|
8
11
|
import type { RefusalReason } from "./refusal.ts";
|
|
9
12
|
|
|
10
13
|
/**
|
|
@@ -20,16 +23,33 @@ export interface CallContext {
|
|
|
20
23
|
/** The display's title, as the host gave it (never the content's words). */
|
|
21
24
|
readonly title: string;
|
|
22
25
|
readonly capability: CapabilityName;
|
|
26
|
+
/** The instance the host gave the display (which artifact, which version), if any. */
|
|
27
|
+
readonly instance?: InstanceRef;
|
|
28
|
+
/**
|
|
29
|
+
* Who is viewing, as the host said (P087): the bridge already checked the method's level
|
|
30
|
+
* against it. A host's own API checks again: it is its data's wall.
|
|
31
|
+
*/
|
|
32
|
+
readonly viewer?: ViewerInfo;
|
|
33
|
+
/**
|
|
34
|
+
* The page's declaration for this capability (P086): its levels, `data`'s resources and tools,
|
|
35
|
+
* `db`'s rules (the fields of the one it is).
|
|
36
|
+
*/
|
|
37
|
+
readonly declared?: DeclaredData & DeclaredDb;
|
|
23
38
|
}
|
|
24
39
|
|
|
25
40
|
export type CapabilityHandler<N extends CapabilityName> = (
|
|
26
41
|
args: CapabilityArgs[N],
|
|
27
|
-
context: N extends "subscribeData"
|
|
42
|
+
context: N extends "subscribeData"
|
|
43
|
+
? SubscriptionContext
|
|
44
|
+
: N extends "db"
|
|
45
|
+
? DbContext
|
|
46
|
+
: CallContext,
|
|
28
47
|
) => CapabilityResults[N] | Promise<CapabilityResults[N]>;
|
|
29
48
|
|
|
30
49
|
/**
|
|
31
|
-
* A subscription's context (`subscribeData`, P079): how the host tells the
|
|
32
|
-
* changed, and when to stop.
|
|
50
|
+
* A subscription's context (`subscribeData`, P079; a `db` watch, P088): how the host tells the
|
|
51
|
+
* content its resource changed, and when to stop. A `db` watch's `changed` takes the new state
|
|
52
|
+
* (a snapshot, or a collection's `{ docs }`), which goes to the content as it is.
|
|
33
53
|
*/
|
|
34
54
|
export interface SubscriptionContext extends CallContext {
|
|
35
55
|
/**
|
|
@@ -42,6 +62,9 @@ export interface SubscriptionContext extends CallContext {
|
|
|
42
62
|
readonly signal: AbortSignal;
|
|
43
63
|
}
|
|
44
64
|
|
|
65
|
+
/** A `db` call's context: a watch's (`op: "watch"`) carries its channel back and its end. */
|
|
66
|
+
export type DbContext = CallContext & Partial<Pick<SubscriptionContext, "changed" | "signal">>;
|
|
67
|
+
|
|
45
68
|
/** The host's handlers: one for each declared capability served by a handler. */
|
|
46
69
|
export type CapabilityHandlers = { readonly [N in HandledCapability]?: CapabilityHandler<N> };
|
|
47
70
|
|
|
@@ -78,6 +101,13 @@ export type ConfirmRequest = {
|
|
|
78
101
|
readonly capability: N;
|
|
79
102
|
readonly args: CapabilityArgs[N];
|
|
80
103
|
readonly display: ConfirmDisplay;
|
|
104
|
+
/**
|
|
105
|
+
* A confirmation only (never a consent's request): the runtime methods whose own gates
|
|
106
|
+
* (`CapabilityConfig.methodGates`, the contract's) asked for it, of those the call runs (P094):
|
|
107
|
+
* a db batch's writes' ops that need a yes, so a dialog can lead with them. Absent where only
|
|
108
|
+
* the host function's own gates ask.
|
|
109
|
+
*/
|
|
110
|
+
readonly askedBy?: readonly string[];
|
|
81
111
|
};
|
|
82
112
|
}[CapabilityName];
|
|
83
113
|
|
|
@@ -96,6 +126,18 @@ export type ConfirmAnswer = boolean | "accepted" | "declined" | "redirected";
|
|
|
96
126
|
*/
|
|
97
127
|
export type Proceed = () => void;
|
|
98
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Puts a call's whole effect in front of the person, outside every frame (the `show` gate, P100):
|
|
131
|
+
* a `setModelContext` update's text and structured content, which the model reads at its next
|
|
132
|
+
* turns. It asks nothing; the call goes once it returns (or its promise resolves), so it resolves
|
|
133
|
+
* only once this very update is visible: drawn, not queued behind a render (after the review). An
|
|
134
|
+
* update the person never saw, because a later one of the display replaced it first, rejects:
|
|
135
|
+
* the call doesn't go. One that throws or rejects stops the call: nobody saw it. Each update
|
|
136
|
+
* replaces the display's last (MCP Apps: the host sends the model the last one), so a surface
|
|
137
|
+
* shows the latest per display.
|
|
138
|
+
*/
|
|
139
|
+
export type Show = (request: ConfirmRequest) => void | Promise<void>;
|
|
140
|
+
|
|
99
141
|
/**
|
|
100
142
|
* Asks a person. Resolves with their answer. The host's UI, or the React binding's default
|
|
101
143
|
* dialog; drawn outside the frame, never inside it. `proceed` (optional to use) runs the effect
|
|
@@ -121,11 +163,26 @@ export type Refusal =
|
|
|
121
163
|
| "muted"
|
|
122
164
|
/** It is `consent`-gated and there is no `consent` function. */
|
|
123
165
|
| "no-consent"
|
|
166
|
+
/** It is `show`-gated and there is no `show` function: nobody could see it (P100). */
|
|
167
|
+
| "no-show"
|
|
124
168
|
/** The host's `consent` said no (for this display's life). */
|
|
125
169
|
| "denied"
|
|
126
170
|
| "rate-limited"
|
|
127
|
-
/** The host's handler threw or rejected. */
|
|
128
|
-
| "failed"
|
|
171
|
+
/** The host's handler threw or rejected (or its `show` did: nobody saw the call, P100). */
|
|
172
|
+
| "failed"
|
|
173
|
+
/**
|
|
174
|
+
* The display's page declared capabilities and not this one (P086): a built-in needs none, any
|
|
175
|
+
* other is reachable only by a page that declared it (and only the resources and tools it named).
|
|
176
|
+
*/
|
|
177
|
+
| "undeclared"
|
|
178
|
+
/**
|
|
179
|
+
* The viewer's level doesn't reach the method's (P087), or the call reaches data that isn't
|
|
180
|
+
* theirs (another person's `data/users/<id>`); or the host gave the display no viewer, which a
|
|
181
|
+
* runtime capability needs.
|
|
182
|
+
*/
|
|
183
|
+
| "level"
|
|
184
|
+
/** Past a limit: a document, a batch, an upload, a publish (P088). */
|
|
185
|
+
| "too-large";
|
|
129
186
|
|
|
130
187
|
export type CallOutcome<T> =
|
|
131
188
|
/** `stale`: a `readData` answered from the host's cache (`DataCache`). */
|
|
@@ -146,6 +203,14 @@ export interface CallOptions {
|
|
|
146
203
|
readonly subscription?: Pick<SubscriptionContext, "changed" | "signal">;
|
|
147
204
|
/** `readData`: the host's cache may answer, marked stale (the content subscribes to it). */
|
|
148
205
|
readonly stale?: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* `readData`: a result the host already gave for this read (a subscription's `changed(result)`,
|
|
208
|
+
* the fresh read after a stale answer), and the URI it was given for. It answers the read after
|
|
209
|
+
* every gate a read has, without the handler or the cache (P094: a kept result is never a way
|
|
210
|
+
* past the read's gates); a `uri` that isn't the read's is refused (`invalid`). Ignored for any
|
|
211
|
+
* capability but `readData`.
|
|
212
|
+
*/
|
|
213
|
+
readonly held?: { readonly uri: string; readonly value: unknown };
|
|
149
214
|
}
|
|
150
215
|
|
|
151
216
|
/** What adapters call; one per display. */
|
|
@@ -157,4 +222,10 @@ export interface HostFunctionBridge {
|
|
|
157
222
|
options?: CallOptions,
|
|
158
223
|
): Promise<CallOutcome<CapabilityResults[N]>>;
|
|
159
224
|
declared(capability: CapabilityName): boolean;
|
|
225
|
+
/**
|
|
226
|
+
* What the runtime offers this display (P085): each runtime capability it may `use`, with its
|
|
227
|
+
* methods. Empty without `config.runtime`. The same whatever the viewer's level: levels refuse
|
|
228
|
+
* at call time.
|
|
229
|
+
*/
|
|
230
|
+
roster(): Readonly<Partial<Record<RuntimeCapabilityName, readonly string[]>>>;
|
|
160
231
|
}
|
package/src/check/check.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PageDeclaration } from "../runtime/declaration.ts";
|
|
1
2
|
import type { ColorScheme, PortholeConfig } from "../config/schema.ts";
|
|
2
3
|
import type { InstanceRef } from "../isolation/types.ts";
|
|
3
4
|
import { presets } from "../presets/presets.ts";
|
|
@@ -68,6 +69,12 @@ export interface CheckOptions {
|
|
|
68
69
|
readonly files?: FileContents;
|
|
69
70
|
/** The page a set opens at (default `index.html`). */
|
|
70
71
|
readonly entry?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Under a runtime (P085): what the page declares (default null: a page with none, so a
|
|
74
|
+
* declared capability is null in the check, as in a preview). Its calls are answered as a
|
|
75
|
+
* declining host answers, by a view-level viewer.
|
|
76
|
+
*/
|
|
77
|
+
readonly declaration?: PageDeclaration | null;
|
|
71
78
|
readonly driver: CheckDriver;
|
|
72
79
|
/** Widths, px. Default: the manual's phone and desktop widths (`config.layout`). */
|
|
73
80
|
readonly widths?: readonly number[];
|
|
@@ -277,6 +284,7 @@ export async function checkPage(options: CheckOptions): Promise<CheckReport> {
|
|
|
277
284
|
content,
|
|
278
285
|
scriptLines,
|
|
279
286
|
...(instance === undefined ? {} : { instance }),
|
|
287
|
+
...(options.declaration === undefined ? {} : { declaration: options.declaration }),
|
|
280
288
|
widthPx: width,
|
|
281
289
|
...(fills ? { heightPx: 700 } : {}),
|
|
282
290
|
scheme,
|
package/src/check/instrument.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PageDeclaration } from "../runtime/declaration.ts";
|
|
1
2
|
import type { ColorScheme, PortholeConfig } from "../config/schema.ts";
|
|
2
3
|
import type { InstanceRef } from "../isolation/types.ts";
|
|
3
4
|
|
|
@@ -14,6 +15,8 @@ export interface CheckRunSpec {
|
|
|
14
15
|
readonly scriptLines: readonly number[];
|
|
15
16
|
/** A served config's instance (located through the check's own server), else opaque. */
|
|
16
17
|
readonly instance?: InstanceRef;
|
|
18
|
+
/** Under a runtime: the page's declaration (null: none). */
|
|
19
|
+
readonly declaration?: PageDeclaration | null;
|
|
17
20
|
readonly widthPx: number;
|
|
18
21
|
readonly heightPx?: number;
|
|
19
22
|
readonly scheme: ColorScheme;
|
package/src/check/lint.ts
CHANGED
|
@@ -190,7 +190,9 @@ export function lintContent(config: PortholeConfig, content: string): Finding[]
|
|
|
190
190
|
"clipboard",
|
|
191
191
|
"warning",
|
|
192
192
|
declared.has("copyText")
|
|
193
|
-
?
|
|
193
|
+
? config.runtime === undefined
|
|
194
|
+
? "The clipboard is closed to content: a copy button calls copyText(text) from its click."
|
|
195
|
+
: 'The clipboard is closed to content: a copy button calls (await porthole.use("clipboard")).copy(text) from its click.'
|
|
194
196
|
: "The clipboard is closed to content: copying from a button doesn't work here.",
|
|
195
197
|
clipboard.index,
|
|
196
198
|
);
|
|
@@ -237,7 +239,7 @@ export function lintContent(config: PortholeConfig, content: string): Finding[]
|
|
|
237
239
|
add(
|
|
238
240
|
"egress",
|
|
239
241
|
"warning",
|
|
240
|
-
`Nothing loads from ${origin} here (${kind}): ${kind === "script" && librarySources(config).length > 0 ? "write it inline, or use one of the libraries served here (the manual's Libraries)" : kind === "script" || kind === "style" ? "write it inline, or use a library from an allowed CDN" : kind === "connect" && config.capabilities.readData !== undefined ?
|
|
242
|
+
`Nothing loads from ${origin} here (${kind}): ${kind === "script" && librarySources(config).length > 0 ? "write it inline, or use one of the libraries served here (the manual's Libraries)" : kind === "script" || kind === "style" ? "write it inline, or use a library from an allowed CDN" : kind === "connect" && config.capabilities.readData !== undefined ? `the content can't call it; read the app's data with ${config.runtime === undefined ? "readData" : "data.read"}` : kind === "connect" ? "the content can't call it; work from data in the content" : "put it inline as a data: URL"}.`,
|
|
241
243
|
match.index,
|
|
242
244
|
);
|
|
243
245
|
}
|
package/src/check/page.ts
CHANGED
|
@@ -39,6 +39,16 @@ const DECLINED: { readonly [N in HandledCapability]: () => unknown } = {
|
|
|
39
39
|
subscribeData: () => {
|
|
40
40
|
throw new Error("The host declined the subscription");
|
|
41
41
|
},
|
|
42
|
+
comments: () => false,
|
|
43
|
+
artifact: () => {
|
|
44
|
+
throw new Error("The host declined the artifact call");
|
|
45
|
+
},
|
|
46
|
+
assets: () => {
|
|
47
|
+
throw new Error("The host declined the asset call");
|
|
48
|
+
},
|
|
49
|
+
db: () => {
|
|
50
|
+
throw new Error("The host declined the db call");
|
|
51
|
+
},
|
|
42
52
|
};
|
|
43
53
|
|
|
44
54
|
/**
|
|
@@ -172,6 +182,8 @@ const check = {
|
|
|
172
182
|
confirm: () => Promise.resolve("declined"),
|
|
173
183
|
// A viewer who doesn't allow a live widget their data (P079): its calls are refused.
|
|
174
184
|
consent: () => false,
|
|
185
|
+
// Model context goes to a surface nobody reads here (P100): the check has no person.
|
|
186
|
+
show: () => {},
|
|
175
187
|
// A served config's instance, issued by the check's own server on this page's origin.
|
|
176
188
|
locator: {
|
|
177
189
|
locate: async (instance) =>
|
|
@@ -184,6 +196,10 @@ const check = {
|
|
|
184
196
|
title: "Check",
|
|
185
197
|
scheme: spec.scheme,
|
|
186
198
|
...(spec.instance === undefined ? {} : { instance: spec.instance }),
|
|
199
|
+
// Under a runtime: the page's declaration (none by default), a viewer who only views.
|
|
200
|
+
...(spec.config.runtime === undefined
|
|
201
|
+
? {}
|
|
202
|
+
: { declaration: spec.declaration ?? null, viewer: { level: "view" as const } }),
|
|
187
203
|
});
|
|
188
204
|
const run: Run = {
|
|
189
205
|
display,
|
package/src/check/tools.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { PortholeConfig } from "../config/schema.ts";
|
|
2
|
-
import {
|
|
3
|
-
import { generateGuide, generateToolDescription } from "../guide/guide.ts";
|
|
2
|
+
import { builtInTopics, generateGuide, generateToolDescription } from "../guide/guide.ts";
|
|
4
3
|
import { fragmentOf, lintContent, type Finding } from "./lint.ts";
|
|
5
4
|
import { lintFiles, whereOf, type FileContents, type FileFinding } from "./files.ts";
|
|
6
5
|
|
|
@@ -29,7 +28,7 @@ const guideName = (config: PortholeConfig) => config.guide.guideToolName ?? `${n
|
|
|
29
28
|
|
|
30
29
|
/** The topics the manual has: the built-in ones and the config's own. */
|
|
31
30
|
export function guideTopics(config: PortholeConfig): string[] {
|
|
32
|
-
return [...
|
|
31
|
+
return [...builtInTopics(config), ...Object.keys(config.guide.topics ?? {})];
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
/** The tool that shows content: `{ title, html }`. */
|
package/src/compile/compile.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PortholeConfig } from "../config/schema.ts";
|
|
2
2
|
import { validateConfig } from "../config/validate.ts";
|
|
3
|
+
import type { ConfigWarning } from "../config/warnings.ts";
|
|
3
4
|
import { generateGuide, generateToolDescription, type GuideTopic } from "../guide/guide.ts";
|
|
4
5
|
import { shellDocument, type ShellDocumentOptions } from "../shell/document.ts";
|
|
5
6
|
import { shellPlan, type ShellPlan } from "../shell/plan.ts";
|
|
@@ -19,6 +20,11 @@ import {
|
|
|
19
20
|
*/
|
|
20
21
|
export interface CompiledConfig {
|
|
21
22
|
readonly config: PortholeConfig;
|
|
23
|
+
/**
|
|
24
|
+
* What the config says that its host likely didn't mean (`configWarnings`): log them at startup.
|
|
25
|
+
* Empty for a config without any.
|
|
26
|
+
*/
|
|
27
|
+
readonly warnings: readonly ConfigWarning[];
|
|
22
28
|
/** The frame's CSP, directive by directive; empty in url mode (the app sends its own). */
|
|
23
29
|
readonly cspDirectives: readonly CspDirective[];
|
|
24
30
|
/** The frame's CSP: in the shell's `<meta>`, or a served document's header. */
|
|
@@ -43,12 +49,14 @@ export interface CompiledConfig {
|
|
|
43
49
|
|
|
44
50
|
/** Validates `config` and derives everything from it. Throws a `ConfigError` on a bad config. */
|
|
45
51
|
export function compile(config: PortholeConfig): CompiledConfig {
|
|
46
|
-
|
|
52
|
+
const warnings: ConfigWarning[] = [];
|
|
53
|
+
validateConfig(config, { onWarning: (warning) => warnings.push(warning) });
|
|
47
54
|
const cspDirectives = frameCspDirectives(config);
|
|
48
55
|
const csp = serializeCsp(cspDirectives);
|
|
49
56
|
const shell = shellPlan(config);
|
|
50
57
|
return {
|
|
51
58
|
config,
|
|
59
|
+
warnings,
|
|
52
60
|
cspDirectives,
|
|
53
61
|
csp,
|
|
54
62
|
sandbox: sandboxTokens(config).join(" "),
|
package/src/compile/policy.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { CAPABILITIES, type CapabilityName, type Gate } from "../config/capabilities.ts";
|
|
2
2
|
import type { PortholeConfig } from "../config/schema.ts";
|
|
3
3
|
import { LIBRARY_PATH } from "../libraries/libraries.ts";
|
|
4
|
+
import { assetCodeRuns, familyOf, methodGates, methodsOfCall } from "../runtime/contract.ts";
|
|
5
|
+
import { ASSET_PATH } from "../runtime/requests.ts";
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* The frame's policies, derived from the config: its CSP (in the shell's `<meta>` for opaque
|
|
@@ -30,6 +32,31 @@ export function effectiveGates(config: PortholeConfig, name: CapabilityName): re
|
|
|
30
32
|
return config.capabilities[name]?.gates ?? CAPABILITIES[name].defaultGates;
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
/**
|
|
36
|
+
* The gates one call runs under: its host function's, and the own gates of each runtime method it
|
|
37
|
+
* runs (after the review: `artifact.publish`, `assets.delete`, an upload whose code may run; P094:
|
|
38
|
+
* a db batch's writes' and a watch's read's too, `methodsOfCall`), every one applying.
|
|
39
|
+
*/
|
|
40
|
+
export function callGates(
|
|
41
|
+
config: PortholeConfig,
|
|
42
|
+
name: CapabilityName,
|
|
43
|
+
args: unknown,
|
|
44
|
+
): readonly Gate[] {
|
|
45
|
+
const gates = [...effectiveGates(config, name)];
|
|
46
|
+
const family = familyOf(name);
|
|
47
|
+
if (family === null) {
|
|
48
|
+
return gates;
|
|
49
|
+
}
|
|
50
|
+
for (const method of new Set(methodsOfCall(name, args))) {
|
|
51
|
+
for (const gate of methodGates(config, family.name, method)) {
|
|
52
|
+
if (!gates.includes(gate)) {
|
|
53
|
+
gates.push(gate);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return gates;
|
|
58
|
+
}
|
|
59
|
+
|
|
33
60
|
const unique = (values: readonly string[]): string[] => [...new Set(values)];
|
|
34
61
|
|
|
35
62
|
/** The origins content may reach for `kind`: the base allowlist plus every declared capability's. */
|
|
@@ -133,6 +160,42 @@ export function fileSetCspDirectives(
|
|
|
133
160
|
});
|
|
134
161
|
}
|
|
135
162
|
|
|
163
|
+
/**
|
|
164
|
+
* The directives a page opens its artifact's asset library to (P089), at `/_blob/` on its own
|
|
165
|
+
* origin: what loads without running, always; what runs (scripts, styles) only where uploads are
|
|
166
|
+
* the admins' alone, who publish the page's code anyway.
|
|
167
|
+
*/
|
|
168
|
+
export const ASSET_DIRECTIVES = ["img-src", "media-src", "font-src", "connect-src"] as const;
|
|
169
|
+
export const ASSET_CODE_DIRECTIVES = ["script-src", "style-src"] as const;
|
|
170
|
+
|
|
171
|
+
export { assetCodeRuns };
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* A served page's CSP with its asset library opened (P089), on `origin` (the page's own, exact:
|
|
175
|
+
* never a sibling's): only where the config declares `assets`. Never `'self'`.
|
|
176
|
+
*/
|
|
177
|
+
export function assetCspDirectives(
|
|
178
|
+
config: PortholeConfig,
|
|
179
|
+
directives: readonly CspDirective[],
|
|
180
|
+
origin: string,
|
|
181
|
+
): CspDirective[] {
|
|
182
|
+
if (config.capabilities.assets === undefined || config.isolation !== "domain") {
|
|
183
|
+
return [...directives];
|
|
184
|
+
}
|
|
185
|
+
const source = `${origin}${ASSET_PATH}`;
|
|
186
|
+
const opened = new Set<string>([
|
|
187
|
+
...ASSET_DIRECTIVES,
|
|
188
|
+
...(assetCodeRuns(config) ? ASSET_CODE_DIRECTIVES : []),
|
|
189
|
+
]);
|
|
190
|
+
return directives.map(([name, ...sources]) => {
|
|
191
|
+
if (!opened.has(name)) {
|
|
192
|
+
return [name, ...sources];
|
|
193
|
+
}
|
|
194
|
+
const kept = sources.filter((each) => each !== "'none'");
|
|
195
|
+
return [name, ...kept, source];
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
136
199
|
/**
|
|
137
200
|
* The CSP of a file of a set that is neither a page nor a script (P081): nothing loads from it,
|
|
138
201
|
* and opened as a document (an SVG, an XML file) it runs nothing, on an opaque origin.
|
|
@@ -161,6 +224,120 @@ export function sandboxTokens(config: PortholeConfig): string[] {
|
|
|
161
224
|
}
|
|
162
225
|
}
|
|
163
226
|
|
|
227
|
+
/**
|
|
228
|
+
* The `sandbox` a served document's CSP header carries (P099): the frame's own tokens, so a page
|
|
229
|
+
* opened on a tab of its own (a public link, a new tab, a bookmark, a frame's address opened
|
|
230
|
+
* outside it) holds no power it lacks in its frame: scripts on its own origin, and no popups,
|
|
231
|
+
* forms, downloads, modals, or navigation of another window (its opener's included). In a frame
|
|
232
|
+
* it repeats the frame's attribute, so it changes nothing there; it is sent on every served page,
|
|
233
|
+
* not only on a `Sec-Fetch-Dest: document` request, so a client that sends no fetch metadata is
|
|
234
|
+
* sandboxed too and one address needs no `Vary`. Domain isolation only: url mode serves the app's
|
|
235
|
+
* own documents, and opaque content is never served. Never in a `<meta>` (browsers ignore it there).
|
|
236
|
+
*/
|
|
237
|
+
export function servedSandboxDirective(config: PortholeConfig): CspDirective | null {
|
|
238
|
+
return config.isolation === "domain" ? ["sandbox", ...sandboxTokens(config)] : null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** A served page's CSP header: the page's directives, then its sandbox (P099). */
|
|
242
|
+
export function servedDocumentCsp(
|
|
243
|
+
config: PortholeConfig,
|
|
244
|
+
directives: readonly CspDirective[],
|
|
245
|
+
): string {
|
|
246
|
+
const sandbox = servedSandboxDirective(config);
|
|
247
|
+
return serializeCsp(sandbox === null ? directives : [...directives, sandbox]);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The features a cross-origin frame never has unless its `allow` names them (each one's default
|
|
252
|
+
* allowlist is `'self'`), and a served page denies itself (P099): devices, location, full screen,
|
|
253
|
+
* the clipboard, payments, credentials, sharing, the built-in AI models, WebMCP's `tools`, the
|
|
254
|
+
* local network, autofill. Every such feature Chromium lists for web pages
|
|
255
|
+
* (`test/reference/permissions-policy-features.json`), but client hints, `cross-origin-isolated`
|
|
256
|
+
* and Chromium's sample (`test/permissions-policy.test.ts` says why). Features whose default is
|
|
257
|
+
* `*` (a video's picture-in-picture, gamepads) are left out: a frame has them, so denying them on
|
|
258
|
+
* a tab would change the frame too. An engine that doesn't know a name ignores it.
|
|
259
|
+
*/
|
|
260
|
+
export const FRAME_DENIED_FEATURES = [
|
|
261
|
+
"accelerometer",
|
|
262
|
+
"ambient-light-sensor",
|
|
263
|
+
"autofill",
|
|
264
|
+
"autoplay",
|
|
265
|
+
"bluetooth",
|
|
266
|
+
"camera",
|
|
267
|
+
"captured-surface-control",
|
|
268
|
+
"clipboard-read",
|
|
269
|
+
"clipboard-write",
|
|
270
|
+
"compute-pressure",
|
|
271
|
+
"deferred-fetch",
|
|
272
|
+
"device-attributes",
|
|
273
|
+
"digital-credentials-create",
|
|
274
|
+
"digital-credentials-get",
|
|
275
|
+
"display-capture",
|
|
276
|
+
"encrypted-media",
|
|
277
|
+
"fullscreen",
|
|
278
|
+
"geolocation",
|
|
279
|
+
"gyroscope",
|
|
280
|
+
"haptics",
|
|
281
|
+
"hid",
|
|
282
|
+
"identity-credentials-get",
|
|
283
|
+
"idle-detection",
|
|
284
|
+
"keyboard-map",
|
|
285
|
+
"language-detector",
|
|
286
|
+
"language-model",
|
|
287
|
+
"local-fonts",
|
|
288
|
+
"local-network",
|
|
289
|
+
"local-network-access",
|
|
290
|
+
"loopback-network",
|
|
291
|
+
"magnetometer",
|
|
292
|
+
"manual-text",
|
|
293
|
+
"microphone",
|
|
294
|
+
"midi",
|
|
295
|
+
"on-device-speech-recognition",
|
|
296
|
+
"otp-credentials",
|
|
297
|
+
"payment",
|
|
298
|
+
"publickey-credentials-create",
|
|
299
|
+
"publickey-credentials-get",
|
|
300
|
+
"publickey-credentials-remote-client-data-json",
|
|
301
|
+
"rewriter",
|
|
302
|
+
"screen-wake-lock",
|
|
303
|
+
"serial",
|
|
304
|
+
"speaker-selection",
|
|
305
|
+
"summarizer",
|
|
306
|
+
"tools",
|
|
307
|
+
"translator",
|
|
308
|
+
"unbounded-element",
|
|
309
|
+
"usb",
|
|
310
|
+
"web-app-installation",
|
|
311
|
+
"web-share",
|
|
312
|
+
"webnn",
|
|
313
|
+
"window-management",
|
|
314
|
+
"writer",
|
|
315
|
+
"xr-spatial-tracking",
|
|
316
|
+
] as const;
|
|
317
|
+
|
|
318
|
+
/** The features a frame's `allow` attribute grants (`allowAttribute`): none but url mode's. */
|
|
319
|
+
export function delegatedFeatures(config: PortholeConfig): string[] {
|
|
320
|
+
return config.mode === "url" ? [...(config.permissions ?? [])] : [];
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* The `Permissions-Policy` header of a served page (P099): every feature of
|
|
325
|
+
* `FRAME_DENIED_FEATURES` its frame's `allow` doesn't grant, denied (`camera=()`), so a page on
|
|
326
|
+
* a tab of its own (no `allow` there) can't ask for the camera, the microphone, location or full
|
|
327
|
+
* screen under the content origin's name. In a frame it changes nothing: the frame's `allow`
|
|
328
|
+
* grants none of them, and a frame's features are the intersection of the two. Domain isolation
|
|
329
|
+
* only, as `servedSandboxDirective`.
|
|
330
|
+
*/
|
|
331
|
+
export function servedPermissionsPolicy(config: PortholeConfig): string | null {
|
|
332
|
+
if (config.isolation !== "domain") {
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
const granted = new Set(delegatedFeatures(config));
|
|
336
|
+
return FRAME_DENIED_FEATURES.filter((feature) => !granted.has(feature))
|
|
337
|
+
.map((feature) => `${feature}=()`)
|
|
338
|
+
.join(", ");
|
|
339
|
+
}
|
|
340
|
+
|
|
164
341
|
/**
|
|
165
342
|
* The frame's `allow` attribute (Permissions Policy). No camera, microphone, geolocation,
|
|
166
343
|
* fullscreen or other powerful feature is delegated to the frame, and the clipboard is denied by
|