@botiverse/porthole 0.14.5 → 0.14.6
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 +53 -0
- package/dist/check/page-source.js +1 -1
- package/dist/check/page.js +5 -1
- package/dist/compile/policy.d.ts +6 -0
- package/dist/compile/policy.js +6 -0
- package/dist/conformance/entry.d.ts +25 -6
- package/dist/conformance/entry.js +69 -18
- package/dist/conformance/harness/page.d.ts +12 -0
- package/dist/conformance/harness/page.js +95 -51
- package/dist/conformance/harness-source.js +1 -1
- package/dist/conformance/host-kit.js +39 -13
- package/dist/conformance/served.js +140 -0
- package/dist/files/paths.d.ts +2 -2
- package/dist/files/paths.js +12 -2
- package/dist/host/client.d.ts +8 -0
- package/dist/host/client.js +47 -17
- package/dist/host/create-host.d.ts +10 -0
- package/dist/host/create-host.js +124 -10
- package/dist/host/door.d.ts +41 -0
- package/dist/host/door.js +55 -0
- package/dist/host/locate.js +2 -0
- package/dist/host/locator.d.ts +55 -3
- package/dist/host/locator.js +152 -42
- package/dist/host/outcome.d.ts +54 -1
- package/dist/host/outcome.js +33 -8
- package/dist/host/types.d.ts +10 -2
- package/dist/isolation/served.d.ts +1 -1
- package/dist/isolation/served.js +35 -0
- package/dist/isolation/types.d.ts +20 -2
- package/dist/isolation/types.js +2 -0
- package/dist/platform/types.d.ts +22 -0
- package/dist/platform/web.js +55 -12
- package/dist/react/view.d.ts +13 -0
- package/dist/react/view.js +101 -2
- package/dist/server/files.d.ts +11 -0
- package/dist/server/files.js +26 -4
- package/dist/server/host.js +106 -28
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +6 -1
- package/dist/server/pages.d.ts +32 -0
- package/dist/server/pages.js +82 -6
- package/dist/server/server.js +140 -11
- package/dist/server/types.d.ts +15 -1
- package/dist/transport/post-message.d.ts +1 -9
- package/dist/transport/post-message.js +2 -8
- package/docs/ADOPTING.md +57 -4
- package/docs/DECISIONS.md +198 -0
- package/docs/DESIGN.md +24 -18
- package/docs/THREAT_MODEL.md +79 -13
- package/package.json +1 -1
- package/src/check/page.ts +6 -1
- package/src/compile/policy.ts +7 -0
- package/src/conformance/entry.ts +129 -24
- package/src/conformance/harness/page.ts +112 -49
- package/src/conformance/host-kit.ts +53 -16
- package/src/conformance/served.ts +175 -0
- package/src/files/paths.ts +11 -2
- package/src/host/client.ts +59 -22
- package/src/host/create-host.ts +144 -18
- package/src/host/door.ts +97 -0
- package/src/host/locate.ts +2 -0
- package/src/host/locator.ts +208 -57
- package/src/host/outcome.ts +41 -9
- package/src/host/types.ts +10 -2
- package/src/isolation/served.ts +40 -1
- package/src/isolation/types.ts +19 -2
- package/src/platform/types.ts +21 -0
- package/src/platform/web.ts +55 -20
- package/src/react/view.tsx +149 -2
- package/src/server/files.ts +37 -5
- package/src/server/host.ts +131 -46
- package/src/server/index.ts +6 -1
- package/src/server/pages.ts +101 -6
- package/src/server/server.ts +186 -19
- package/src/server/types.ts +16 -1
- package/src/transport/post-message.ts +1 -9
package/src/conformance/entry.ts
CHANGED
|
@@ -3,10 +3,13 @@ import type { FrameOutcome } from "../host/types.ts";
|
|
|
3
3
|
import type { ConformanceTest } from "./probes.ts";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Redirect entry's cases (P068): a clean address opens directly, signed in or not,
|
|
7
|
-
* shows content without access; its one-time code works once, on its own origin
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* Redirect entry's cases (P068, P125): a clean address opens directly in a tab, signed in or not,
|
|
7
|
+
* and never shows content without access; its one-time code works once, on its own origin. A clean
|
|
8
|
+
* address is for a tab: a host frames what one names by resolving it through its issue endpoint
|
|
9
|
+
* first (a door, a ticket), and signed out, denied or not found, it builds no frame at all and
|
|
10
|
+
* shows its fallback from that answer. A clean address framed as it is goes nowhere: the host
|
|
11
|
+
* refuses it (no door), and the content origin answers it with a page that says nothing. A host
|
|
12
|
+
* implements `EntryConformanceHost` (or gives `defineHostConformance` its `entry`).
|
|
10
13
|
*/
|
|
11
14
|
|
|
12
15
|
export interface EntryConformanceHost {
|
|
@@ -37,13 +40,32 @@ export interface EntryConformanceHost {
|
|
|
37
40
|
*/
|
|
38
41
|
completeSignIn?(page: Page): Promise<void>;
|
|
39
42
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
43
|
+
* Shows a clean address on the app's page as the app would (P125): resolved through the app's
|
|
44
|
+
* issue endpoint (`client.resolve`, `<PortholeView address>`), then framed through the location
|
|
45
|
+
* it issued. Returns the frame, the display's outcome once it has one, and whether any frame was
|
|
46
|
+
* ever made for it.
|
|
42
47
|
*/
|
|
43
48
|
frame(
|
|
44
49
|
page: Page,
|
|
45
50
|
url: string,
|
|
46
|
-
): Promise<{
|
|
51
|
+
): Promise<{
|
|
52
|
+
frame(): Promise<Frame>;
|
|
53
|
+
outcome(): Promise<FrameOutcome>;
|
|
54
|
+
framed(): Promise<boolean>;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Gives the app's `createHost` a clean address as a frame's location, as it is (no issue, no
|
|
58
|
+
* door), as a host of the wrong kind would. Returns the outcome, whether a frame was made, and
|
|
59
|
+
* the host errors it heard.
|
|
60
|
+
*/
|
|
61
|
+
frameDirectly(
|
|
62
|
+
page: Page,
|
|
63
|
+
url: string,
|
|
64
|
+
): Promise<{
|
|
65
|
+
outcome(): Promise<FrameOutcome>;
|
|
66
|
+
framed(): Promise<boolean>;
|
|
67
|
+
hostErrors(): Promise<readonly { readonly message: string; readonly kind: string }[]>;
|
|
68
|
+
}>;
|
|
47
69
|
}
|
|
48
70
|
|
|
49
71
|
export interface EntrySuiteOptions {
|
|
@@ -214,42 +236,125 @@ export function entryTests(
|
|
|
214
236
|
|
|
215
237
|
define(
|
|
216
238
|
"served.entry.framed",
|
|
217
|
-
"a clean address in a frame
|
|
239
|
+
"a clean address shown in a frame is resolved through issue first, then framed through its door: the content, never the app's sign-in",
|
|
218
240
|
async ({ page, browserName }, info) => {
|
|
219
241
|
await host.signIn(page);
|
|
220
242
|
const before = page.url();
|
|
221
243
|
const shown = await host.frame(page, await host.url("entry-framed"));
|
|
222
|
-
|
|
244
|
+
expect(await shown.outcome(), "probe: the issued frame loaded").toEqual({ state: "loaded" });
|
|
223
245
|
const frame = await shown.frame();
|
|
224
246
|
expect(page.url(), "the app's page stays where it was").toBe(before);
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
expect(await shows(frame)).toBe(false);
|
|
232
|
-
}
|
|
233
|
-
const said = outcome.state === "blocked" ? `blocked: ${outcome.reason}` : outcome.state;
|
|
247
|
+
// An issued frame (P125): Porthole's own document address, never the clean address, and
|
|
248
|
+
// never the app's sign-in. Its access is the ticket's (P083), so every engine shows it.
|
|
249
|
+
expect(new URL(frame.url()).pathname, "probe: framed through issue").toMatch(
|
|
250
|
+
/^\/__porthole\/(d|f)\//u,
|
|
251
|
+
);
|
|
252
|
+
await expect(frame.locator("#artifact")).toHaveText("version 1");
|
|
234
253
|
info.annotations.push({
|
|
235
254
|
type: "measured",
|
|
236
|
-
description: `${browserName}: framed entry
|
|
255
|
+
description: `${browserName}: framed entry loaded`,
|
|
237
256
|
});
|
|
238
257
|
},
|
|
239
258
|
);
|
|
240
259
|
|
|
241
260
|
define(
|
|
242
261
|
"served.entry.framed-signed-out",
|
|
243
|
-
"signed out, a clean address in a frame
|
|
262
|
+
"signed out, a clean address shown in a frame builds no frame: issue says sign in, and the fallback comes from that answer",
|
|
244
263
|
async ({ page }) => {
|
|
245
264
|
await host.signIn(page);
|
|
246
265
|
// The app's page stays; the browser forgets every sign-in.
|
|
247
266
|
await page.context().clearCookies();
|
|
248
267
|
const shown = await host.frame(page, await host.url("entry-framed-out"));
|
|
249
|
-
expect(await shown.outcome()
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
268
|
+
expect(await shown.outcome(), "probe: issue's answer is the outcome").toEqual({
|
|
269
|
+
state: "blocked",
|
|
270
|
+
reason: "sign-in",
|
|
271
|
+
status: 401,
|
|
272
|
+
});
|
|
273
|
+
expect(await shown.framed(), "probe: no frame was made").toBe(false);
|
|
274
|
+
},
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
define(
|
|
278
|
+
"served.entry.framed-denied",
|
|
279
|
+
"a clean address its viewer may not open, shown in a frame, builds no frame: issue says denied",
|
|
280
|
+
async ({ page }, info) => {
|
|
281
|
+
info.skip(
|
|
282
|
+
host.denied === undefined,
|
|
283
|
+
"the host gave no address its viewer may not open (denied)",
|
|
284
|
+
);
|
|
285
|
+
await host.signIn(page);
|
|
286
|
+
const shown = await host.frame(page, (await host.denied?.("entry-framed-denied")) ?? "");
|
|
287
|
+
expect(await shown.outcome(), "probe: issue's answer is the outcome").toMatchObject({
|
|
288
|
+
state: "blocked",
|
|
289
|
+
reason: "denied",
|
|
290
|
+
status: 403,
|
|
291
|
+
});
|
|
292
|
+
expect(await shown.framed(), "probe: no frame was made").toBe(false);
|
|
293
|
+
},
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
define(
|
|
297
|
+
"served.entry.framed-not-found",
|
|
298
|
+
"a clean address that names nothing, shown in a frame, builds no frame: issue says not found",
|
|
299
|
+
async ({ page }, info) => {
|
|
300
|
+
const unknown = (await host.unknown?.()) ?? [];
|
|
301
|
+
// An address under a label the app never assigns: the first one that has a path.
|
|
302
|
+
const address = unknown.find((each) => new URL(each).hostname.split(".").length > 2);
|
|
303
|
+
info.skip(address === undefined, "the host gave no address that names nothing (unknown)");
|
|
304
|
+
await host.signIn(page);
|
|
305
|
+
const shown = await host.frame(page, address ?? "");
|
|
306
|
+
expect(await shown.outcome(), "probe: issue's answer is the outcome").toEqual({
|
|
307
|
+
state: "blocked",
|
|
308
|
+
reason: "not-found",
|
|
309
|
+
status: 404,
|
|
310
|
+
});
|
|
311
|
+
expect(await shown.framed(), "probe: no frame was made").toBe(false);
|
|
312
|
+
},
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
define(
|
|
316
|
+
"served.entry.in-a-frame",
|
|
317
|
+
"a clean address framed as it is goes nowhere: the host refuses it (no door), and the content origin answers a page with no script, never the app",
|
|
318
|
+
async ({ page }) => {
|
|
319
|
+
await host.signIn(page);
|
|
320
|
+
const url = await host.url("entry-in-a-frame");
|
|
321
|
+
// The host's own createHost, given the clean address as a location: refused before any
|
|
322
|
+
// frame (a served display needs a door from issue), and told why.
|
|
323
|
+
const direct = await host.frameDirectly(page, url);
|
|
324
|
+
expect(await direct.outcome(), "probe: refused before any frame").toEqual({
|
|
325
|
+
state: "blocked",
|
|
326
|
+
reason: "locate",
|
|
327
|
+
});
|
|
328
|
+
expect(await direct.framed(), "probe: no frame was made").toBe(false);
|
|
329
|
+
expect(
|
|
330
|
+
(await direct.hostErrors()).map((each) => each.kind),
|
|
331
|
+
"probe: the host heard why (door)",
|
|
332
|
+
).toContain("door");
|
|
333
|
+
// A plain frame of the app's page at the clean address: the content origin answers it with
|
|
334
|
+
// a page of its own that has no script and goes nowhere (never the app's authorize).
|
|
335
|
+
const seen = await page.evaluate(async (address) => {
|
|
336
|
+
const frame = document.createElement("iframe");
|
|
337
|
+
const loaded = new Promise((resolve) =>
|
|
338
|
+
frame.addEventListener("load", resolve, { once: true }),
|
|
339
|
+
);
|
|
340
|
+
frame.src = address;
|
|
341
|
+
document.body.append(frame);
|
|
342
|
+
await loaded;
|
|
343
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
344
|
+
return frame.getAttribute("src");
|
|
345
|
+
}, url);
|
|
346
|
+
expect(seen).toBe(url);
|
|
347
|
+
const frame = page.frames().find((each) => each.url() === url);
|
|
348
|
+
expect(
|
|
349
|
+
frame,
|
|
350
|
+
"probe: the frame stayed on the clean address (never the app's authorize)",
|
|
351
|
+
).toBeDefined();
|
|
352
|
+
expect(
|
|
353
|
+
await frame?.locator("script").count(),
|
|
354
|
+
"probe: the page in the frame has no script",
|
|
355
|
+
).toBe(0);
|
|
356
|
+
await expect(frame!.locator("h1")).toHaveText("Open this in a new tab");
|
|
357
|
+
expect(await shows(frame!), "probe: no content in the frame").toBe(false);
|
|
253
358
|
},
|
|
254
359
|
);
|
|
255
360
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CapabilityHandlers, ConfirmRequest } from "../../bridge/types.ts";
|
|
2
2
|
import type { PortholeConfig } from "../../config/schema.ts";
|
|
3
3
|
import { createHost } from "../../host/create-host.ts";
|
|
4
|
-
import { httpLocator } from "../../host/locator.ts";
|
|
4
|
+
import { httpLocator, resolveAddress } from "../../host/locator.ts";
|
|
5
5
|
import type { DisplayEvents, DisplayHandle } from "../../host/types.ts";
|
|
6
6
|
import type { FrameLocation, InstanceLocator, InstanceRef } from "../../isolation/types.ts";
|
|
7
7
|
import type { LaunchSpec, RecordedCall, RecordedEvent } from "../index.ts";
|
|
@@ -108,6 +108,73 @@ addEventListener("message", (event) => {
|
|
|
108
108
|
}
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
+
/** A display's record, before anything is mounted for it (a no-op handle until then). */
|
|
112
|
+
function recordOf(id: number): Shown {
|
|
113
|
+
box(id, 600, 400);
|
|
114
|
+
const idle = { destroy() {}, setContent() {}, setTheme() {}, on: () => () => {} };
|
|
115
|
+
const shown: Shown = {
|
|
116
|
+
handle: idle as unknown as DisplayHandle,
|
|
117
|
+
calls: [],
|
|
118
|
+
events: [],
|
|
119
|
+
confirmations: [],
|
|
120
|
+
disclosed: [],
|
|
121
|
+
received: [],
|
|
122
|
+
origin: null,
|
|
123
|
+
failure: null,
|
|
124
|
+
frame: null,
|
|
125
|
+
};
|
|
126
|
+
displays.set(id, shown);
|
|
127
|
+
return shown;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Mounts a served display in its box, located by `asked` (the issue endpoint, or a location). */
|
|
131
|
+
function mountServed(
|
|
132
|
+
id: number,
|
|
133
|
+
shown: Shown,
|
|
134
|
+
config: PortholeConfig,
|
|
135
|
+
instance: InstanceRef,
|
|
136
|
+
asked: InstanceLocator,
|
|
137
|
+
content?: string,
|
|
138
|
+
): void {
|
|
139
|
+
const container = document.getElementById(`porthole-display-${id}`) as HTMLElement;
|
|
140
|
+
const locator: InstanceLocator = {
|
|
141
|
+
async locate(each, signal) {
|
|
142
|
+
try {
|
|
143
|
+
const location = await asked.locate(each, signal);
|
|
144
|
+
shown.origin = location.origin;
|
|
145
|
+
return location;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
shown.failure = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
const handle = createHost(config, {
|
|
153
|
+
handlers: recorder(shown.calls),
|
|
154
|
+
locator,
|
|
155
|
+
hostInfo: { name: "porthole-conformance", version: "1" },
|
|
156
|
+
...(nonce === undefined ? {} : { nonce }),
|
|
157
|
+
}).mount(container, {
|
|
158
|
+
displayId: `display-${id}`,
|
|
159
|
+
title: "Probe",
|
|
160
|
+
scheme: "light",
|
|
161
|
+
instance,
|
|
162
|
+
});
|
|
163
|
+
(shown as { handle: DisplayHandle }).handle = handle;
|
|
164
|
+
watch(id, shown);
|
|
165
|
+
// The frame element, once it exists, so its messages can be told from others' (never a door).
|
|
166
|
+
const found = () => {
|
|
167
|
+
shown.frame = container.querySelector("iframe:not([data-porthole-door])");
|
|
168
|
+
if (shown.frame === null) {
|
|
169
|
+
requestAnimationFrame(found);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
found();
|
|
173
|
+
if (content !== undefined) {
|
|
174
|
+
handle.setContent(content);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
111
178
|
const harness = {
|
|
112
179
|
/** An opaque display with the suite's content (the leak suite's `launch`). */
|
|
113
180
|
async launch(spec: LaunchSpec): Promise<number> {
|
|
@@ -178,63 +245,59 @@ const harness = {
|
|
|
178
245
|
): number {
|
|
179
246
|
const id = next;
|
|
180
247
|
next += 1;
|
|
181
|
-
const
|
|
182
|
-
const calls: RecordedCall[] = [];
|
|
183
|
-
const shown: Shown = {
|
|
184
|
-
handle: null as unknown as DisplayHandle,
|
|
185
|
-
calls,
|
|
186
|
-
events: [],
|
|
187
|
-
confirmations: [],
|
|
188
|
-
disclosed: [],
|
|
189
|
-
received: [],
|
|
190
|
-
origin: null,
|
|
191
|
-
failure: null,
|
|
192
|
-
frame: null,
|
|
193
|
-
};
|
|
248
|
+
const shown = recordOf(id);
|
|
194
249
|
const asked: InstanceLocator =
|
|
195
250
|
"issue" in where
|
|
196
251
|
? httpLocator(where.issue, where.headers === undefined ? {} : { headers: where.headers })
|
|
197
252
|
: { locate: () => Promise.resolve(where.location) };
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
253
|
+
mountServed(id, shown, config, instance, asked, content);
|
|
254
|
+
return id;
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* A clean address, shown as a host shows one (P125): resolved through the app's issue endpoint
|
|
259
|
+
* first (`{ address }`, `resolveAddress`), then framed through the location it issued (its
|
|
260
|
+
* door); signed out, denied or not found, the answer is the display's outcome and no frame is
|
|
261
|
+
* ever made. Later runs issue afresh by the resolved instance.
|
|
262
|
+
*/
|
|
263
|
+
showAddress(
|
|
264
|
+
config: PortholeConfig,
|
|
265
|
+
where: { readonly issue: string; readonly headers?: Readonly<Record<string, string>> },
|
|
266
|
+
address: string,
|
|
267
|
+
): number {
|
|
268
|
+
const id = next;
|
|
269
|
+
next += 1;
|
|
270
|
+
const shown = recordOf(id);
|
|
271
|
+
const options = where.headers === undefined ? {} : { headers: where.headers };
|
|
272
|
+
void resolveAddress(where.issue, address, options).then(
|
|
273
|
+
(resolved) => {
|
|
274
|
+
if ("outcome" in resolved) {
|
|
275
|
+
shown.events.push({ type: "outcome", detail: resolved.outcome });
|
|
276
|
+
return;
|
|
208
277
|
}
|
|
278
|
+
shown.origin = resolved.location.origin;
|
|
279
|
+
let first: FrameLocation | null = resolved.location;
|
|
280
|
+
const byInstance = httpLocator(where.issue, options);
|
|
281
|
+
const asked: InstanceLocator = {
|
|
282
|
+
locate(each, signal) {
|
|
283
|
+
const given = first;
|
|
284
|
+
first = null;
|
|
285
|
+
return given === null ? byInstance.locate(each, signal) : Promise.resolve(given);
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
mountServed(id, shown, config, resolved.instance, asked);
|
|
209
289
|
},
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
hostInfo: { name: "porthole-conformance", version: "1" },
|
|
215
|
-
...(nonce === undefined ? {} : { nonce }),
|
|
216
|
-
}).mount(container, {
|
|
217
|
-
displayId: `display-${id}`,
|
|
218
|
-
title: "Probe",
|
|
219
|
-
scheme: "light",
|
|
220
|
-
instance,
|
|
221
|
-
});
|
|
222
|
-
(shown as { handle: DisplayHandle }).handle = handle;
|
|
223
|
-
watch(id, shown);
|
|
224
|
-
// The frame element, once it exists, so its messages can be told from others'.
|
|
225
|
-
const found = () => {
|
|
226
|
-
shown.frame = container.querySelector("iframe");
|
|
227
|
-
if (shown.frame === null) {
|
|
228
|
-
requestAnimationFrame(found);
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
found();
|
|
232
|
-
if (content !== undefined) {
|
|
233
|
-
handle.setContent(content);
|
|
234
|
-
}
|
|
290
|
+
(error: unknown) => {
|
|
291
|
+
shown.failure = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
292
|
+
},
|
|
293
|
+
);
|
|
235
294
|
return id;
|
|
236
295
|
},
|
|
237
296
|
|
|
297
|
+
/** Whether a display's frame was ever made (P125: a refused clean address makes none). */
|
|
298
|
+
framed: (id: number) =>
|
|
299
|
+
(document.getElementById(`porthole-display-${id}`)?.querySelector("iframe") ?? null) !== null,
|
|
300
|
+
|
|
238
301
|
origin: (id: number) => displays.get(id)?.origin ?? null,
|
|
239
302
|
failure: (id: number) => displays.get(id)?.failure ?? null,
|
|
240
303
|
received: (id: number) => displays.get(id)?.received ?? [],
|
|
@@ -138,12 +138,30 @@ function invoke<K extends keyof ConformanceHarness>(
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
/** The display's frame element's document, once it exists. */
|
|
141
|
+
/** A display's first outcome, once it has one (P040, P125). */
|
|
142
|
+
async function outcomeOf(page: Page, id: number): Promise<FrameOutcome> {
|
|
143
|
+
let found: FrameOutcome | null = null;
|
|
144
|
+
await expect
|
|
145
|
+
.poll(
|
|
146
|
+
async () => {
|
|
147
|
+
const events = await invoke(page, "events", id);
|
|
148
|
+
const each = events.find((event) => event.type === "outcome");
|
|
149
|
+
found = each === undefined ? null : each.detail;
|
|
150
|
+
return found !== null;
|
|
151
|
+
},
|
|
152
|
+
{ message: "the display has an outcome", timeout: 15_000 },
|
|
153
|
+
)
|
|
154
|
+
.toBe(true);
|
|
155
|
+
return found as unknown as FrameOutcome;
|
|
156
|
+
}
|
|
157
|
+
|
|
141
158
|
async function frameIn(page: Page, id: number): Promise<Frame> {
|
|
142
159
|
let found: Frame | null = null;
|
|
143
160
|
await expect
|
|
144
161
|
.poll(async () => {
|
|
145
162
|
const element = await page
|
|
146
|
-
|
|
163
|
+
// The display's own frame, never its door (P125), which is gone once it said its word.
|
|
164
|
+
.locator(`#porthole-display-${id} iframe:not([data-porthole-door])`)
|
|
147
165
|
.elementHandle({ timeout: 2_000 })
|
|
148
166
|
.catch(() => null);
|
|
149
167
|
found = (await element?.contentFrame()) ?? null;
|
|
@@ -369,27 +387,45 @@ export function hostConformance(options: HostConformanceOptions): HostConformanc
|
|
|
369
387
|
: given.unknown,
|
|
370
388
|
}),
|
|
371
389
|
async frame(page, url) {
|
|
390
|
+
await ready(page);
|
|
391
|
+
if (options.issue === undefined) {
|
|
392
|
+
throw new Error(
|
|
393
|
+
"A clean address is framed through the app's issue endpoint ({ address }, P125): give defineHostConformance its issue",
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
const instance = await served.artifact("entry", "1");
|
|
397
|
+
const id = await invoke(
|
|
398
|
+
page,
|
|
399
|
+
"showAddress",
|
|
400
|
+
configOf(instance),
|
|
401
|
+
{
|
|
402
|
+
issue: options.issue.url,
|
|
403
|
+
...(options.issue.headers === undefined ? {} : { headers: options.issue.headers }),
|
|
404
|
+
},
|
|
405
|
+
url,
|
|
406
|
+
);
|
|
407
|
+
return {
|
|
408
|
+
frame: () => frameIn(page, id),
|
|
409
|
+
outcome: () => outcomeOf(page, id),
|
|
410
|
+
framed: () => invoke(page, "framed", id),
|
|
411
|
+
};
|
|
412
|
+
},
|
|
413
|
+
async frameDirectly(page, url) {
|
|
372
414
|
await ready(page);
|
|
373
415
|
const instance = await served.artifact("entry", "1");
|
|
374
416
|
const id = await invoke(page, "show", configOf(instance), instance, {
|
|
375
417
|
location: { url, origin: new URL(url).origin },
|
|
376
418
|
});
|
|
377
419
|
return {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
await
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
return found !== null;
|
|
388
|
-
},
|
|
389
|
-
{ message: "the display has an outcome", timeout: 15_000 },
|
|
390
|
-
)
|
|
391
|
-
.toBe(true);
|
|
392
|
-
return found as unknown as FrameOutcome;
|
|
420
|
+
outcome: () => outcomeOf(page, id),
|
|
421
|
+
framed: () => invoke(page, "framed", id),
|
|
422
|
+
async hostErrors() {
|
|
423
|
+
const events = await invoke(page, "events", id);
|
|
424
|
+
return events.flatMap((event) =>
|
|
425
|
+
event.type === "hostError"
|
|
426
|
+
? [event.detail as { readonly message: string; readonly kind: string }]
|
|
427
|
+
: [],
|
|
428
|
+
);
|
|
393
429
|
},
|
|
394
430
|
};
|
|
395
431
|
},
|
|
@@ -450,6 +486,7 @@ const DOMAIN_CASES = [
|
|
|
450
486
|
"served.domain.self-navigation",
|
|
451
487
|
...TAB_CASES,
|
|
452
488
|
"served.domain.frame-ancestors",
|
|
489
|
+
"served.domain.door",
|
|
453
490
|
"served.domain.egress",
|
|
454
491
|
];
|
|
455
492
|
|
|
@@ -1257,6 +1257,181 @@ navigator.mediaDevices && navigator.mediaDevices.getUserMedia({ video: true }).t
|
|
|
1257
1257
|
},
|
|
1258
1258
|
);
|
|
1259
1259
|
|
|
1260
|
+
define(
|
|
1261
|
+
"served.domain.door",
|
|
1262
|
+
"a served display's door is on its own origin, opaque, says open from null, is taken once, refuses the wrong ticket, and says what the content route says (P125)",
|
|
1263
|
+
async ({ page }) => {
|
|
1264
|
+
const doorOf = (location: Awaited<ReturnType<typeof host.locate>>): string => {
|
|
1265
|
+
expect(
|
|
1266
|
+
location.door,
|
|
1267
|
+
"probe: the server gives a door for a served display",
|
|
1268
|
+
).toBeDefined();
|
|
1269
|
+
return location.door!.url;
|
|
1270
|
+
};
|
|
1271
|
+
// Land on a host-origin page first, so the door (framed by it) is within frame-ancestors.
|
|
1272
|
+
await host.show(page, await host.shell("door-nav"), { content: SHELL_CONTENT });
|
|
1273
|
+
// (1) The door is on the display's own origin, at Porthole's door path.
|
|
1274
|
+
const first = await host.locate(await host.shell("door-shape"));
|
|
1275
|
+
const door = new URL(doorOf(first));
|
|
1276
|
+
expect(door.origin, "probe: the door is on the display's origin").toBe(first.origin);
|
|
1277
|
+
expect(door.pathname, "probe: the door is at /__porthole/door/<key>").toMatch(
|
|
1278
|
+
/^\/__porthole\/door\/[A-Za-z0-9_-]+$/u,
|
|
1279
|
+
);
|
|
1280
|
+
|
|
1281
|
+
// (2) Framed opaque (sandbox allow-scripts), it says `open` from the opaque origin within
|
|
1282
|
+
// SETTLE_MS; (5) and a door on a tab of its own is an opaque origin too.
|
|
1283
|
+
const said = await page.evaluate(
|
|
1284
|
+
async ({ url, settle }) => {
|
|
1285
|
+
const frame = document.createElement("iframe");
|
|
1286
|
+
// Opaque: scripts only (the probe frames the door as the host does, P125).
|
|
1287
|
+
frame.sandbox.add("allow-scripts");
|
|
1288
|
+
const got = new Promise<{ origin: string; data: unknown } | null>((resolve) => {
|
|
1289
|
+
const onMessage = (event: MessageEvent) => {
|
|
1290
|
+
if (event.source === frame.contentWindow) {
|
|
1291
|
+
window.removeEventListener("message", onMessage);
|
|
1292
|
+
resolve({ origin: event.origin, data: event.data });
|
|
1293
|
+
}
|
|
1294
|
+
};
|
|
1295
|
+
window.addEventListener("message", onMessage);
|
|
1296
|
+
setTimeout(() => resolve(null), settle);
|
|
1297
|
+
});
|
|
1298
|
+
frame.src = url;
|
|
1299
|
+
document.body.append(frame);
|
|
1300
|
+
const message = await got;
|
|
1301
|
+
frame.remove();
|
|
1302
|
+
return message;
|
|
1303
|
+
},
|
|
1304
|
+
{ url: door.href, settle: SETTLE_MS + 2_000 },
|
|
1305
|
+
);
|
|
1306
|
+
expect(said, "probe: the door said nothing when framed opaque").not.toBeNull();
|
|
1307
|
+
expect(said?.origin, "probe: the door spoke from an opaque origin").toBe("null");
|
|
1308
|
+
expect(
|
|
1309
|
+
(said?.data as { method?: unknown } | null)?.method,
|
|
1310
|
+
"probe: the door spoke a frame status",
|
|
1311
|
+
).toBe("porthole/notifications/frame-status");
|
|
1312
|
+
expect(
|
|
1313
|
+
(said?.data as { params?: { state?: unknown } } | null)?.params?.state,
|
|
1314
|
+
"probe: the door said open",
|
|
1315
|
+
).toBe("open");
|
|
1316
|
+
|
|
1317
|
+
// (5) The door's own answer is sandboxed in its header too (opaque on a tab, and in a frame a
|
|
1318
|
+
// host's platform forgot to sandbox): scripts alone, never its origin, and no cookie.
|
|
1319
|
+
const headered = await host.locate(await host.shell("door-header"));
|
|
1320
|
+
const doorAnswer = await page.request.get(doorOf(headered), { failOnStatusCode: false });
|
|
1321
|
+
const doorCsp = doorAnswer.headers()["content-security-policy"] ?? "";
|
|
1322
|
+
expect(doorAnswer.status(), "probe: a fresh door ticket opens the door").toBe(200);
|
|
1323
|
+
expect(
|
|
1324
|
+
doorCsp
|
|
1325
|
+
.split(";")
|
|
1326
|
+
.map((each) => each.trim())
|
|
1327
|
+
.filter((each) => each.startsWith("sandbox")),
|
|
1328
|
+
"probe: the door's header sandboxes it with scripts alone, keeping no origin of its own",
|
|
1329
|
+
).toEqual(["sandbox allow-scripts"]);
|
|
1330
|
+
expect(
|
|
1331
|
+
doorAnswer.headers()["set-cookie"],
|
|
1332
|
+
"probe: the door sets no cookie",
|
|
1333
|
+
).toBeUndefined();
|
|
1334
|
+
|
|
1335
|
+
// (3) The same door ticket again opens nothing: a used ticket is `session`.
|
|
1336
|
+
const again = await page.request.get(door.href, { failOnStatusCode: false });
|
|
1337
|
+
expect(again.status(), "probe: a used door ticket is 401 session").toBe(401);
|
|
1338
|
+
|
|
1339
|
+
// (4) The door ticket at the content route, and the content ticket at the door, open
|
|
1340
|
+
// nothing; (6) a fresh door framed from a foreign origin hears nothing (frame-ancestors).
|
|
1341
|
+
const fresh = await host.locate(await host.shell("door-cross"));
|
|
1342
|
+
const freshDoor = new URL(doorOf(fresh));
|
|
1343
|
+
const freshContent = new URL(fresh.url);
|
|
1344
|
+
const key = freshDoor.pathname.split("/").at(-1) ?? "";
|
|
1345
|
+
const doorTicket = freshDoor.searchParams.get("ticket") ?? "";
|
|
1346
|
+
const contentTicket = freshContent.searchParams.get("ticket") ?? "";
|
|
1347
|
+
const doorTicketAtContent = `${fresh.origin}/__porthole/d/${key}?ticket=${doorTicket}`;
|
|
1348
|
+
const contentTicketAtDoor = `${fresh.origin}/__porthole/door/${key}?ticket=${contentTicket}`;
|
|
1349
|
+
for (const [what, url] of [
|
|
1350
|
+
["the door ticket at the content route", doorTicketAtContent],
|
|
1351
|
+
["the content ticket at the door", contentTicketAtDoor],
|
|
1352
|
+
] as const) {
|
|
1353
|
+
const response = await page.request.get(url, { failOnStatusCode: false });
|
|
1354
|
+
expect(response.status(), `probe: ${what} opens nothing`).toBe(401);
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
// (7) The door and the content route say the same block for the same grant (P125's
|
|
1358
|
+
// invariant): for one issue, its door ticket at the door and its content ticket at
|
|
1359
|
+
// `/__porthole/d/`, each from a browser with no cookie, answer the same status and reason.
|
|
1360
|
+
// `session`: each ticket already used once; `not-found`: a version that doesn't exist.
|
|
1361
|
+
const browser = page.context().browser();
|
|
1362
|
+
const wordOf = async (url: string) => {
|
|
1363
|
+
const isolated = await browser!.newContext();
|
|
1364
|
+
try {
|
|
1365
|
+
const answer = await isolated.request.get(url, {
|
|
1366
|
+
failOnStatusCode: false,
|
|
1367
|
+
maxRedirects: 0,
|
|
1368
|
+
headers: { "sec-fetch-dest": "iframe" },
|
|
1369
|
+
});
|
|
1370
|
+
const body = await answer.text();
|
|
1371
|
+
return {
|
|
1372
|
+
status: answer.status(),
|
|
1373
|
+
reason: /data-porthole-reason="([a-z-]+)"/u.exec(body)?.[1] ?? null,
|
|
1374
|
+
};
|
|
1375
|
+
} finally {
|
|
1376
|
+
await isolated.close();
|
|
1377
|
+
}
|
|
1378
|
+
};
|
|
1379
|
+
const used = await host.locate(await host.shell("door-same-session"));
|
|
1380
|
+
await wordOf(doorOf(used));
|
|
1381
|
+
await wordOf(used.url);
|
|
1382
|
+
const usedDoor = await wordOf(doorOf(used));
|
|
1383
|
+
const usedContent = await wordOf(used.url);
|
|
1384
|
+
expect(usedDoor, "probe: a used door ticket says session").toEqual({
|
|
1385
|
+
status: 401,
|
|
1386
|
+
reason: "session",
|
|
1387
|
+
});
|
|
1388
|
+
expect(usedContent, "probe: the content route says what the door says (used)").toEqual(
|
|
1389
|
+
usedDoor,
|
|
1390
|
+
);
|
|
1391
|
+
const page1 = await host.artifact("door-same-missing", "1");
|
|
1392
|
+
const missing: InstanceRef =
|
|
1393
|
+
page1.document.kind === "artifact"
|
|
1394
|
+
? { ...page1, document: { ...page1.document, version: "porthole-no-such-version" } }
|
|
1395
|
+
: page1;
|
|
1396
|
+
let gone: FrameLocation | null = null;
|
|
1397
|
+
try {
|
|
1398
|
+
gone = await host.locate(missing);
|
|
1399
|
+
} catch {
|
|
1400
|
+
// A host that refuses to issue for a version it doesn't have answers before any frame.
|
|
1401
|
+
info?.annotations.push({
|
|
1402
|
+
type: "measured",
|
|
1403
|
+
description:
|
|
1404
|
+
"the host refuses to issue for a missing version: not-found is never framed",
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
if (gone !== null) {
|
|
1408
|
+
const goneDoor = await wordOf(doorOf(gone));
|
|
1409
|
+
const goneContent = await wordOf(gone.url);
|
|
1410
|
+
expect(goneDoor, "probe: a missing document's door says not-found").toEqual({
|
|
1411
|
+
status: 404,
|
|
1412
|
+
reason: "not-found",
|
|
1413
|
+
});
|
|
1414
|
+
expect(goneContent, "probe: the content route says what the door says (missing)").toEqual(
|
|
1415
|
+
goneDoor,
|
|
1416
|
+
);
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
// (6) A fresh door from a foreign origin: frame-ancestors refuses it, so it says nothing.
|
|
1420
|
+
const foreignDoor = await host.locate(await host.shell("door-foreign"));
|
|
1421
|
+
await host.frameFromForeignOrigin(page, doorOf(foreignDoor));
|
|
1422
|
+
await page.waitForTimeout(SETTLE_MS);
|
|
1423
|
+
for (const frame of page.frames().slice(1)) {
|
|
1424
|
+
const reached = await Promise.race([
|
|
1425
|
+
frame
|
|
1426
|
+
.evaluate(() => document.querySelector("[data-porthole-door]") !== null)
|
|
1427
|
+
.catch(() => false),
|
|
1428
|
+
new Promise<boolean>((resolve) => setTimeout(() => resolve(false), 2_000)),
|
|
1429
|
+
]);
|
|
1430
|
+
expect(reached, "probe: a foreign origin framed the door").toBe(false);
|
|
1431
|
+
}
|
|
1432
|
+
},
|
|
1433
|
+
);
|
|
1434
|
+
|
|
1260
1435
|
define(
|
|
1261
1436
|
"served.domain.egress",
|
|
1262
1437
|
"the CSP in the document's headers closes egress; only what the config opens to any https site (images, media) reaches it",
|