@botiverse/porthole 0.9.0 → 0.10.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.
@@ -37,12 +37,18 @@ async function rtcSendsHere(context, udp) {
37
37
  const childDocument = (stun) => `<script>parent.postMessage({ tag: "child-ran" }, "*"); try { const p = new RTCPeerConnection({ iceServers: [{ urls: ${js(stun)} }], iceCandidatePoolSize: 4 }); p.createDataChannel("x"); p.createOffer().then((o) => p.setLocalDescription(o)); } catch (e) {}</script>`;
38
38
  /** The verdict of a nested-frame attack: the child never ran, and nothing reached the oracle. */
39
39
  async function expectNoChild(context, display, udp) {
40
- const verdict = await context.result(display, 15_000);
40
+ // A document written over (`document.write`, once the shell's lock is gone) or navigated away
41
+ // is started again before it reports: that is the escape itself, the probe's verdict (P096).
42
+ const verdict = await context.result(display, 15_000).catch(async (error) => {
43
+ const restarts = (await display.events()).filter((event) => event.type === "navigated");
44
+ expect(restarts, "probe: the content's document was replaced before it reported").toEqual([]);
45
+ throw error;
46
+ });
41
47
  await settle(1_000);
42
48
  expect(verdict.error, "the attack itself failed").toBeUndefined();
43
- expect(verdict.childRan ?? false, "a nested frame's script ran").toBe(false);
44
- expect(verdict.frames ?? 0, "a nested frame is still in the tree").toBe(0);
45
- expect(udp.packets(), "STUN packets reached the oracle").toBe(0);
49
+ expect(verdict.childRan ?? false, "probe: a nested frame's script ran").toBe(false);
50
+ expect(verdict.frames ?? 0, "probe: a nested frame is still in the tree").toBe(0);
51
+ expect(udp.packets(), "probe: STUN packets reached the oracle").toBe(0);
46
52
  if (verdict.reached !== undefined || verdict.blocked !== undefined) {
47
53
  context.measured(`${context.engine}: a new frame's realm, in the task that added it, was ${verdict.blocked === undefined ? `reachable (RTCPeerConnection: ${JSON.stringify(verdict.reached)})` : `unreachable (${JSON.stringify(verdict.blocked)})`}`);
48
54
  }
@@ -54,8 +60,13 @@ const childSetup = (stun) => `
54
60
  window.addEventListener("message", (event) => { if (event.data && event.data.tag === "child-ran") r.childRan = true; });
55
61
  const child = ${js(childDocument(stun))};
56
62
  const makeFrame = () => { const f = document.createElement("iframe"); f.setAttribute("srcdoc", child); return f; };`;
57
- /** A navigated document's beacon to an allowed witness: heard only if that document ran. */
58
- const witnessScript = (origin) => `<script>fetch(${js(`${origin}/ran`)}).catch(() => {});</script>`;
63
+ /**
64
+ * A navigated document's beacon to an allowed witness, heard only if that document ran: its first
65
+ * act, a real beacon, which the browser delivers even when the frame is removed a moment later (the
66
+ * display started again). A fetch at its end raced that restart: the embedder-csp control saw
67
+ * blob: and data: documents run only some of the time (P096).
68
+ */
69
+ const witnessScript = (origin) => `<script>navigator.sendBeacon(${js(`${origin}/ran`)}) || fetch(${js(`${origin}/ran`)}, { keepalive: true }).catch(() => {});</script>`;
59
70
  /**
60
71
  * A document the frame navigates to must never run: it would be a fresh realm without the shell's
61
72
  * defenses. (Starting the display again on the navigation can cut it short, but that is a race,
@@ -63,15 +74,15 @@ const witnessScript = (origin) => `<script>fetch(${js(`${origin}/ran`)}).catch((
63
74
  */
64
75
  function measureWitness(context, witness, scheme) {
65
76
  const ran = witness.requests().some((request) => request.path === "/ran");
66
- expect(ran, `a ${scheme} document the frame navigated to ran`).toBe(false);
77
+ expect(ran, `probe: a ${scheme} document the frame navigated to ran`).toBe(false);
67
78
  }
68
79
  /** Every navigation attempt's verdict: nothing reached the oracle, and the content stayed or restarted. */
69
80
  async function expectNoNavigation(context, display, canary, udp) {
70
81
  await settle(1_500);
71
- expect(canary.requests(), "the navigation reached the canary").toEqual([]);
72
- expect(context.requestsTo(canary.origin), "the page requested the canary").toEqual([]);
82
+ expect(canary.requests(), "probe: the navigation reached the canary").toEqual([]);
83
+ expect(context.requestsTo(canary.origin), "probe: the page requested the canary").toEqual([]);
73
84
  if (udp !== undefined) {
74
- expect(udp.packets(), "a navigated document reached the STUN oracle").toBe(0);
85
+ expect(udp.packets(), "probe: a navigated document reached the STUN oracle").toBe(0);
75
86
  }
76
87
  const events = await display.events();
77
88
  const restarts = events.filter((event) => event.type === "navigated").length;
@@ -80,7 +91,7 @@ async function expectNoNavigation(context, display, canary, udp) {
80
91
  return;
81
92
  }
82
93
  const frame = await display.frame();
83
- await expect(frame.locator("#marker"), "the frame lost its content without being started again").toHaveCount(1);
94
+ await expect(frame.locator("#marker"), "probe: the frame lost its content without being started again").toHaveCount(1);
84
95
  context.measured(`${context.engine}: the frame kept its content`);
85
96
  }
86
97
  const navigation = (id, title, code, markup = "") => ({
@@ -139,9 +150,9 @@ const escape = (id, title, code) => ({
139
150
  });
140
151
  const before = context.page.url();
141
152
  await expectNoNavigation(context, display, canary);
142
- expect(popups, "a popup opened").toEqual([]);
143
- expect(downloads, "a download started").toEqual([]);
144
- expect(context.page.url(), "the top page navigated").toBe(before);
153
+ expect(popups, "probe: a popup opened").toEqual([]);
154
+ expect(downloads, "probe: a download started").toEqual([]);
155
+ expect(context.page.url(), "probe: the top page navigated").toBe(before);
145
156
  },
146
157
  });
147
158
  /**
@@ -192,8 +203,8 @@ const hint = (id, make) => ({
192
203
  });
193
204
  await context.result(display, 15_000);
194
205
  await settle(1_000);
195
- expect(canary.requests(), "a hint fetched from the canary").toEqual([]);
196
- expect(canary.connections(), "a hint opened a connection to the canary").toBe(0);
206
+ expect(canary.requests(), "probe: a hint fetched from the canary").toEqual([]);
207
+ expect(canary.connections(), "probe: a hint opened a connection to the canary").toBe(0);
197
208
  },
198
209
  });
199
210
  /** The official MCP Apps App SDK as one ES module, if it is installed where the suite runs. */
@@ -250,9 +261,12 @@ const sdkProbe = (preset) => ({
250
261
  document: page,
251
262
  });
252
263
  const verdict = await context.result(display, 20_000);
253
- expect(verdict.error, "App.connect failed").toBeUndefined();
254
- expect(verdict).toMatchObject({ connected: true, theme: "light" });
255
- expect(verdict.styles).toBeGreaterThan(0);
264
+ expect(verdict.error, "probe: App.connect failed").toBeUndefined();
265
+ expect(verdict, "probe: the App SDK didn't connect with the host's theme").toMatchObject({
266
+ connected: true,
267
+ theme: "light",
268
+ });
269
+ expect(verdict.styles, "probe: the host context carried no theme variables").toBeGreaterThan(0);
256
270
  },
257
271
  });
258
272
  export { attack } from "./kit.js";
@@ -272,7 +286,7 @@ export const PROBES = [
272
286
  config: inline(),
273
287
  content: attack(`r.origin = window.origin;`),
274
288
  });
275
- expect((await context.result(display)).origin).toBe("null");
289
+ expect((await context.result(display)).origin, "probe: the content's origin isn't opaque").toBe("null");
276
290
  },
277
291
  },
278
292
  {
@@ -289,7 +303,7 @@ export const PROBES = [
289
303
  try { window.sendPrompt = () => "replaced"; } catch (e) {}
290
304
  r.replaced = window.sendPrompt !== original;`),
291
305
  });
292
- expect(await context.result(display)).toMatchObject({
306
+ expect(await context.result(display), "probe: a global was defined without its capability, or replaced").toMatchObject({
293
307
  sendPrompt: "function",
294
308
  openLink: "undefined",
295
309
  replaced: false,
@@ -311,7 +325,7 @@ export const PROBES = [
311
325
  r.accent = style.getPropertyValue("--color-accent").trim();
312
326
  r.theme = document.documentElement.getAttribute("data-theme");`),
313
327
  });
314
- expect(await context.result(display)).toMatchObject({
328
+ expect(await context.result(display), "probe: the declared theme wasn't applied").toMatchObject({
315
329
  accent: resolveTheme(config.theme, "dark")["--color-accent"],
316
330
  theme: "dark",
317
331
  });
@@ -331,9 +345,9 @@ export const PROBES = [
331
345
  });
332
346
  await context.result(display);
333
347
  const frame = await display.frame();
334
- await expect(frame.locator("body")).toHaveAttribute("data-ran", "1");
348
+ await expect(frame.locator("body"), "probe: the content didn't run exactly once").toHaveAttribute("data-ran", "1");
335
349
  await settle(300);
336
- await expect(frame.locator("body")).toHaveAttribute("data-ran", "1");
350
+ await expect(frame.locator("body"), "probe: the content ran again").toHaveAttribute("data-ran", "1");
337
351
  },
338
352
  },
339
353
  sdkProbe("inline"),
@@ -374,9 +388,9 @@ export const PROBES = [
374
388
  }
375
389
  expect(verdict.allowed, "the allowed origin (the positive control)").toBe("oracle");
376
390
  expect(allowed.requests().map((request) => request.path)).toContain("/allowed");
377
- expect(canary.requests(), "requests reached the canary").toEqual([]);
378
- expect(context.requestsTo(canary.origin)).toEqual([]);
379
- expect(verdict).toMatchObject({
391
+ expect(canary.requests(), "probe: requests reached the canary").toEqual([]);
392
+ expect(context.requestsTo(canary.origin), "probe: the page requested the canary").toEqual([]);
393
+ expect(verdict, "probe: a channel to the canary wasn't blocked").toMatchObject({
380
394
  fetch: "blocked",
381
395
  xhr: "blocked",
382
396
  websocket: "blocked",
@@ -424,9 +438,9 @@ export const PROBES = [
424
438
  context.inapplicable(INHERITED("img-src", allowed.origin));
425
439
  }
426
440
  expect(verdict.allowed, "the allowed image (the positive control)").toBe("loaded");
427
- expect(canary.requests(), "resources loaded from the canary").toEqual([]);
428
- expect(context.requestsTo(canary.origin)).toEqual([]);
429
- expect(verdict.script).toBe("undefined");
441
+ expect(canary.requests(), "probe: resources loaded from the canary").toEqual([]);
442
+ expect(context.requestsTo(canary.origin), "probe: the page requested the canary").toEqual([]);
443
+ expect(verdict.script, "probe: a script from the canary ran").toBe("undefined");
430
444
  },
431
445
  },
432
446
  // ── 3: WebRTC ──────────────────────────────────────────────────────────────────────────────
@@ -456,14 +470,14 @@ export const PROBES = [
456
470
  });
457
471
  const verdict = await context.result(display, 15_000);
458
472
  await settle();
459
- expect(verdict).toMatchObject({
473
+ expect(verdict, "probe: a WebRTC constructor was reachable or came back").toMatchObject({
460
474
  names: [],
461
475
  peer: "undefined",
462
476
  prefixed: "undefined",
463
477
  restored: "undefined",
464
478
  });
465
- expect(verdict.connected).toBeUndefined();
466
- expect(udp.packets(), "STUN reached the oracle").toBe(0);
479
+ expect(verdict.connected, "probe: the content reached a peer connection").toBeUndefined();
480
+ expect(udp.packets(), "probe: STUN reached the oracle").toBe(0);
467
481
  if (!sends) {
468
482
  context.measured(`${context.engine}: the STUN oracle has no positive control here; the constructors' absence is the evidence`);
469
483
  }
@@ -619,7 +633,7 @@ export const PROBES = [
619
633
  await expectNoNavigation(context, display, canary);
620
634
  expect(context
621
635
  .requestsTo(new URL(context.page.url()).origin)
622
- .filter((url) => url.includes("/__probe/")), "the frame navigated to the host's own origin").toEqual([]);
636
+ .filter((url) => url.includes("/__probe/")), "probe: the frame navigated to the host's own origin").toEqual([]);
623
637
  },
624
638
  },
625
639
  {
@@ -630,7 +644,7 @@ export const PROBES = [
630
644
  const canary = await context.http();
631
645
  const udp = await context.udp();
632
646
  const witness = await context.http();
633
- const page = `<p id="blob">blob</p>${childDocument(udp.stun)}${witnessScript(witness.origin)}`;
647
+ const page = `${witnessScript(witness.origin)}<p id="blob">blob</p>${childDocument(udp.stun)}`;
634
648
  const display = await context.launch({
635
649
  config: inline({ egress: { connect: [witness.origin] } }),
636
650
  content: attack(`
@@ -649,7 +663,7 @@ export const PROBES = [
649
663
  const canary = await context.http();
650
664
  const udp = await context.udp();
651
665
  const witness = await context.http();
652
- const page = `<p id="data">data</p>${childDocument(udp.stun)}${witnessScript(witness.origin)}`;
666
+ const page = `${witnessScript(witness.origin)}<p id="data">data</p>${childDocument(udp.stun)}`;
653
667
  const display = await context.launch({
654
668
  config: inline({ egress: { connect: [witness.origin] } }),
655
669
  content: attack(`
@@ -700,9 +714,12 @@ export const PROBES = [
700
714
  });
701
715
  const verdict = await context.result(display);
702
716
  await settle();
703
- expect(verdict).toMatchObject({ baseChanged: false, plugins: 0 });
704
- expect(canary.requests()).toEqual([]);
705
- expect(context.requestsTo(canary.origin)).toEqual([]);
717
+ expect(verdict, "probe: a <base> took effect or a plugin element stayed").toMatchObject({
718
+ baseChanged: false,
719
+ plugins: 0,
720
+ });
721
+ expect(canary.requests(), "probe: requests reached the canary").toEqual([]);
722
+ expect(context.requestsTo(canary.origin), "probe: the page requested the canary").toEqual([]);
706
723
  },
707
724
  },
708
725
  // ── 8: resource hints ──────────────────────────────────────────────────────────────────────
@@ -734,8 +751,8 @@ export const PROBES = [
734
751
  });
735
752
  await context.result(display, 15_000);
736
753
  await settle(1_000);
737
- expect(canary.requests()).toEqual([]);
738
- expect(canary.connections()).toBe(0);
754
+ expect(canary.requests(), "probe: speculation rules fetched from the canary").toEqual([]);
755
+ expect(canary.connections(), "probe: speculation rules opened a connection to the canary").toBe(0);
739
756
  },
740
757
  },
741
758
  // ── 9: the host ────────────────────────────────────────────────────────────────────────────
@@ -765,8 +782,8 @@ export const PROBES = [
765
782
  localStorage.setItem("porthole-host-secret", "porthole-host-secret-value");
766
783
  });
767
784
  const verdict = await context.result(display);
768
- expect(verdict.origin).toBe("null");
769
- expect(verdict).toMatchObject({
785
+ expect(verdict.origin, "probe: the content's origin isn't opaque").toBe("null");
786
+ expect(verdict, "probe: the content reached the host's document, storage or opener").toMatchObject({
770
787
  parentDocument: "blocked",
771
788
  topDocument: "blocked",
772
789
  parentLocation: "blocked",
@@ -775,8 +792,8 @@ export const PROBES = [
775
792
  html: false,
776
793
  opener: true,
777
794
  });
778
- expect(["blocked", ""]).toContain(verdict.cookie);
779
- expect(canary.requests()).toEqual([]);
795
+ expect(["blocked", ""], "probe: the content read the host's cookie").toContain(verdict.cookie);
796
+ expect(canary.requests(), "probe: requests reached the canary").toEqual([]);
780
797
  },
781
798
  },
782
799
  {
@@ -805,10 +822,10 @@ export const PROBES = [
805
822
  const verdict = await context.result(display);
806
823
  await settle();
807
824
  expect(verdict.siblings, "the probe found its sibling").toBeGreaterThan(0);
808
- expect(canary.requests()).toEqual([]);
825
+ expect(canary.requests(), "probe: a sibling was navigated to the canary").toEqual([]);
809
826
  const frame = await victim.frame();
810
- await expect(frame.locator("#victim")).toHaveText("victim");
811
- await expect(frame.locator("#hijacked")).toHaveCount(0);
827
+ await expect(frame.locator("#victim"), "probe: the other display lost its content").toHaveText("victim");
828
+ await expect(frame.locator("#hijacked"), "probe: the other display was driven").toHaveCount(0);
812
829
  },
813
830
  },
814
831
  // ── 10: the embedding page's own origin ────────────────────────────────────────────────────
@@ -828,7 +845,7 @@ export const PROBES = [
828
845
  });
829
846
  await context.result(display, 15_000);
830
847
  await settle();
831
- expect(context.requestsTo(host).filter((url) => url.includes("/portholeProbe/"))).toEqual([]);
848
+ expect(context.requestsTo(host).filter((url) => url.includes("/portholeProbe/")), "probe: something loaded from the embedding page's own origin").toEqual([]);
832
849
  },
833
850
  },
834
851
  ...BEHAVIOR_PROBES,
@@ -129,13 +129,13 @@ export function servedTests(host, options = {}) {
129
129
  const display = await showMode(page, mode, instance(`${mode}-origin`));
130
130
  const frame = await display.frame();
131
131
  const origin = await frame.evaluate(() => window.origin);
132
- expect(origin).toBe(display.origin);
133
- expect(origin).not.toBe(new URL(page.url()).origin);
132
+ expect(origin, "probe: content runs on its own origin").toBe(display.origin);
133
+ expect(origin, "probe: content runs on the host's origin").not.toBe(new URL(page.url()).origin);
134
134
  });
135
135
  define(`served.${mode}.no-reach`, "content can't reach the host's DOM, storage, cookies or URL", async ({ page }) => {
136
136
  const display = await showMode(page, mode, instance(`${mode}-reach`));
137
137
  await plantHostSecrets(page);
138
- expect(await reachIntoHost(await display.frame())).toEqual(CLOSED);
138
+ expect(await reachIntoHost(await display.frame()), "probe: content reached into the host").toEqual(CLOSED);
139
139
  });
140
140
  define(`served.${mode}.no-top-navigation`, "content can't navigate the host's page, even after a click", async ({ page }) => {
141
141
  const display = await showMode(page, mode, instance(`${mode}-top`));
@@ -164,8 +164,8 @@ export function servedTests(host, options = {}) {
164
164
  }, target);
165
165
  await frame.click("#porthole-probe-top");
166
166
  await page.waitForTimeout(SETTLE_MS);
167
- expect(page.url()).toBe(before);
168
- expect(await host.canaryHits(`${mode}-top`)).toBe(0);
167
+ expect(page.url(), "probe: the host's page stays").toBe(before);
168
+ expect(await host.canaryHits(`${mode}-top`), "probe: the navigation reached the canary").toBe(0);
169
169
  });
170
170
  define(`served.${mode}.no-popups`, "content can't open a window, even after a click", async ({ page }) => {
171
171
  const display = await showMode(page, mode, instance(`${mode}-popup`));
@@ -194,10 +194,10 @@ export function servedTests(host, options = {}) {
194
194
  }, target);
195
195
  await frame.click("#porthole-probe-popup");
196
196
  await page.waitForTimeout(SETTLE_MS);
197
- expect(programmatic).toBe(false);
198
- expect(await frame.evaluate(() => document.body.dataset.popup)).toBe("false");
199
- expect(opened).toHaveLength(0);
200
- expect(await host.canaryHits(`${mode}-popup`)).toBe(0);
197
+ expect(programmatic, "probe: a window opened on load").toBe(false);
198
+ expect(await frame.evaluate(() => document.body.dataset.popup), "probe: a window opened after a click").toBe("false");
199
+ expect(opened, "probe: a window opened").toHaveLength(0);
200
+ expect(await host.canaryHits(`${mode}-popup`), "probe: the popup reached the canary").toBe(0);
201
201
  });
202
202
  }
203
203
  define("served.domain.address", "a served frame's address is its own, carrying at most Porthole's ticket: never the app's", async ({ page }) => {
@@ -210,10 +210,10 @@ export function servedTests(host, options = {}) {
210
210
  search: location.search,
211
211
  hash: location.hash,
212
212
  }));
213
- expect(seen.origin).toBe(display.origin);
214
- expect(seen.search).toMatch(/^(\?ticket=[^&]+)?$/u);
215
- expect(seen.hash).toBe("");
216
- expect(seen.origin).not.toBe(new URL(page.url()).origin);
213
+ expect(seen.origin, "probe: the frame's address is on its own origin").toBe(display.origin);
214
+ expect(seen.search, "probe: the frame's address carries more than the ticket").toMatch(/^(\?ticket=[^&]+)?$/u);
215
+ expect(seen.hash, "probe: the frame's address carries a fragment").toBe("");
216
+ expect(seen.origin, "probe: the frame's address is the host's origin").not.toBe(new URL(page.url()).origin);
217
217
  });
218
218
  define("served.domain.storage-scope", "storage persists within a scope and is never shared across scopes", async ({ page }) => {
219
219
  const first = await host.show(page, await host.shell("scope-a"), {
@@ -229,8 +229,8 @@ export function servedTests(host, options = {}) {
229
229
  const other = await host.show(page, await host.shell("scope-b"), {
230
230
  content: SHELL_CONTENT,
231
231
  });
232
- expect(other.origin).not.toBe(first.origin);
233
- expect(await (await other.frame()).evaluate(() => localStorage.getItem("kept"))).toBeNull();
232
+ expect(other.origin, "probe: another scope shares the origin").not.toBe(first.origin);
233
+ expect(await (await other.frame()).evaluate(() => localStorage.getItem("kept")), "probe: another scope read the storage").toBeNull();
234
234
  });
235
235
  define("served.artifact.versions", "each version of a page shows as stored, on its scope's origin, hardened before it runs", async ({ page }) => {
236
236
  const one = await host.show(page, await host.artifact("artifact-scope", "1"));
@@ -242,7 +242,7 @@ export function servedTests(host, options = {}) {
242
242
  ]) {
243
243
  const frame = await display.frame();
244
244
  await expect(frame.locator("#artifact")).toHaveText(`version ${version}`);
245
- expect(await frame.evaluate(() => document.documentElement.dataset.rtc)).toBe("undefined");
245
+ expect(await frame.evaluate(() => document.documentElement.dataset.rtc), "probe: the page ran before it was hardened").toBe("undefined");
246
246
  }
247
247
  });
248
248
  define("served.domain.ticket-once", "a ticket opens its content once; without it there is nothing", async ({ page, browserName }) => {
@@ -254,8 +254,8 @@ export function servedTests(host, options = {}) {
254
254
  try {
255
255
  const other = await fresh.newPage();
256
256
  const again = await other.goto(location.url);
257
- expect(again?.status(), browserName).toBe(401);
258
- expect(await other.locator("#porthole-root").count()).toBe(0);
257
+ expect(again?.status(), `probe: ${browserName}`).toBe(401);
258
+ expect(await other.locator("#porthole-root").count(), "probe: a used ticket showed content").toBe(0);
259
259
  }
260
260
  finally {
261
261
  await fresh.close();
@@ -292,10 +292,10 @@ export function servedTests(host, options = {}) {
292
292
  const stays = await frame
293
293
  .evaluate(() => window.portholeProbeStays === true)
294
294
  .catch(() => false);
295
- expect(stays, "another content origin: the frame's document stays").toBe(true);
296
- expect(new URL(frame.url()).origin, "another content origin").toBe(display.origin);
295
+ expect(stays, "probe: another content origin: the frame's document stays").toBe(true);
296
+ expect(new URL(frame.url()).origin, "probe: another content origin").toBe(display.origin);
297
297
  await away(outside);
298
- expect(await host.canaryHits("self-navigation"), "the outside site").toBe(0);
298
+ expect(await host.canaryHits("self-navigation"), "probe: the outside site").toBe(0);
299
299
  });
300
300
  // A served page on a tab of its own (P099, the review's S4): a public link, "open in a new
301
301
  // tab", a bookmark. No frame's sandbox is there: the page's own (its CSP's `sandbox`) must
@@ -367,11 +367,11 @@ export function servedTests(host, options = {}) {
367
367
  }, target);
368
368
  await press(page, "#porthole-probe-open");
369
369
  await page.waitForTimeout(SETTLE_MS);
370
- expect(programmatic, "on load").toBe(false);
371
- expect(await page.evaluate(() => document.body.dataset.popup), "after a click").toBe("false");
372
- expect(["absent", "refused"], "picture-in-picture").toContain(await page.evaluate(() => document.body.dataset.pip));
373
- expect(opened, "a window opened").toEqual([]);
374
- expect(await host.canaryHits("tab-window-open")).toBe(0);
370
+ expect(programmatic, "probe: on load").toBe(false);
371
+ expect(await page.evaluate(() => document.body.dataset.popup), "probe: after a click").toBe("false");
372
+ expect(["absent", "refused"], "probe: picture-in-picture").toContain(await page.evaluate(() => document.body.dataset.pip));
373
+ expect(opened, "probe: a window opened").toEqual([]);
374
+ expect(await host.canaryHits("tab-window-open"), "probe: the window reached the canary").toBe(0);
375
375
  });
376
376
  define("served.domain.tab-escapes", "a page on a tab of its own can't open a link in a new window, submit a form, start a download or ask in a browser dialog, even after a click", async ({ page }) => {
377
377
  await onTab(page, "tab-escapes");
@@ -415,12 +415,12 @@ export function servedTests(host, options = {}) {
415
415
  }, urls);
416
416
  await press(page, "#porthole-probe-escape");
417
417
  await page.waitForTimeout(SETTLE_MS);
418
- expect(opened, "a window opened").toEqual([]);
419
- expect(downloads, "a download started").toEqual([]);
420
- expect(dialogs, "a browser dialog showed").toEqual([]);
421
- expect(new URL(page.url()).pathname, "the page stays").not.toMatch(/canary/u);
418
+ expect(opened, "probe: a window opened").toEqual([]);
419
+ expect(downloads, "probe: a download started").toEqual([]);
420
+ expect(dialogs, "probe: a browser dialog showed").toEqual([]);
421
+ expect(new URL(page.url()).pathname, "probe: the page stays").not.toMatch(/canary/u);
422
422
  for (const kind of kinds) {
423
- expect(await host.canaryHits(`tab-${kind}`), kind).toBe(0);
423
+ expect(await host.canaryHits(`tab-${kind}`), `probe: ${kind}`).toBe(0);
424
424
  }
425
425
  });
426
426
  /** A served shell on a tab opened by another page that keeps a reference to it. */
@@ -466,8 +466,8 @@ export function servedTests(host, options = {}) {
466
466
  const away = await host.canary("tab-opener");
467
467
  await clickAway(tab, `${away}?d=secret`, "opener");
468
468
  await page.waitForTimeout(SETTLE_MS);
469
- expect(page.url(), "the opener stays").toBe("about:blank");
470
- expect(await host.canaryHits("tab-opener")).toBe(0);
469
+ expect(page.url(), "probe: the opener stays").toBe("about:blank");
470
+ expect(await host.canaryHits("tab-opener"), "probe: the opener's navigation reached the canary").toBe(0);
471
471
  });
472
472
  define("served.domain.tab-navigation", 'a page on a tab of its own can\'t navigate itself away, to a blob: document of its own or an outside site, by location, a link, navigation.navigate() or open(…, "_self"), however the address is given', async ({ page, browserName }) => {
473
473
  const located = await host.locate(await host.shell("tab-navigation"));
@@ -643,13 +643,13 @@ navigator.mediaDevices && navigator.mediaDevices.getUserMedia({ video: true }).t
643
643
  description: `${browserName}: a blob: document of its own, by ${how}, got ${await tab.title()}`,
644
644
  });
645
645
  }
646
- expect(tab.url(), `a ${name === "blob" ? "blob: document" : "outside site"} by ${how}: the tab stays`).toBe(here);
646
+ expect(tab.url(), `probe: a ${name === "blob" ? "blob: document" : "outside site"} by ${how}: the tab stays`).toBe(here);
647
647
  await tab.close();
648
648
  }
649
649
  }
650
650
  await page.waitForTimeout(SETTLE_MS);
651
651
  const heard = (await Promise.all(ways.map(async (how) => [how, await host.canaryHits(`tab-nav-${how}`)]))).filter(([, hits]) => hits > 0);
652
- expect(heard, "the outside site heard these").toEqual([]);
652
+ expect(heard, "probe: the outside site heard these").toEqual([]);
653
653
  });
654
654
  define("served.domain.tab-links", "a page on a tab of its own can't send a link elsewhere by changing it after the shell read it, or from a shadow root; its fragment links and its own cancels still work", async ({ page }) => {
655
655
  // The browser follows a link with what it is once every listener ran; the shell follows
@@ -722,12 +722,12 @@ navigator.mediaDevices && navigator.mediaDevices.getUserMedia({ video: true }).t
722
722
  setTimeout(() => link.click(), 0);
723
723
  }, [how, canaries[how] ?? ""]);
724
724
  await tab.waitForTimeout(SETTLE_MS);
725
- expect(tab.url(), `${how}: the tab stays`).toBe(here);
725
+ expect(tab.url(), `probe: ${how}: the tab stays`).toBe(here);
726
726
  await tab.close();
727
727
  }
728
728
  await page.waitForTimeout(SETTLE_MS);
729
729
  const heard = (await Promise.all(ways.map(async (how) => [how, await host.canaryHits(`tab-links-${how}`)]))).filter(([, hits]) => hits > 0);
730
- expect(heard, "the outside site heard these").toEqual([]);
730
+ expect(heard, "probe: the outside site heard these").toEqual([]);
731
731
  // Still as before: a fragment link jumps; a link content cancels goes nowhere.
732
732
  const tab = await freshTab();
733
733
  await tab.evaluate(() => {
@@ -809,11 +809,11 @@ navigator.mediaDevices && navigator.mediaDevices.getUserMedia({ video: true }).t
809
809
  .poll(() => page.evaluate(() => document.body.dataset.devices ?? ""), { timeout: 6_000 })
810
810
  .not.toBe("");
811
811
  const said = JSON.parse(await page.evaluate(() => document.body.dataset.devices ?? "{}"));
812
- expect(said.location, "location").toBe("denied 1");
812
+ expect(said.location, "probe: location").toBe("denied 1");
813
813
  // No stream, however it is refused: a machine without a camera says NotFoundError even
814
814
  // where the policy would refuse (measured: Chromium, the header alone).
815
- expect(said.media, "camera and microphone").not.toBe("granted");
816
- expect(["rejected", "absent"], "full screen").toContain(said.fullscreen);
815
+ expect(said.media, "probe: camera and microphone").not.toBe("granted");
816
+ expect(["rejected", "absent"], "probe: full screen").toContain(said.fullscreen);
817
817
  if (warnings.length > 0) {
818
818
  info?.annotations.push({
819
819
  type: "measured",
@@ -912,21 +912,24 @@ navigator.mediaDevices && navigator.mediaDevices.getUserMedia({ video: true }).t
912
912
  document.body.append(button);
913
913
  }, canary);
914
914
  await press(page, "#porthole-probe-prompts");
915
+ // A prompt the page may show waits for the person, and its report never comes: the
916
+ // probe's verdict (P096), as much as one refused too late.
915
917
  await expect
916
918
  .poll(() => page.evaluate(() => document.body.dataset.prompts ?? ""), {
917
919
  timeout: 10_000,
920
+ message: "probe: a prompt was shown and waited, instead of being refused at once",
918
921
  })
919
922
  .not.toBe("");
920
923
  const said = JSON.parse(await page.evaluate(() => document.body.dataset.prompts ?? "{}"));
921
924
  const atOnce = (value) => value === "absent" || (typeof value === "string" && /^refused \w+ at once$/u.test(value));
922
- expect(atOnce(said.passkey), `a passkey: ${String(said.passkey)}`).toBe(true);
923
- expect(atOnce(said.payment), `a payment: ${String(said.payment)}`).toBe(true);
924
- expect(atOnce(said.share), `a share: ${String(said.share)}`).toBe(true);
925
- expect(atOnce(said.applePay), `Apple Pay: ${String(said.applePay)}`).toBe(true);
926
- expect(said.video === "absent" || String(said.video).startsWith("refused"), `a video's full screen: ${String(said.video)}`).toBe(true);
927
- expect(said.shown, "a video in full screen").toBe(false);
925
+ expect(atOnce(said.passkey), `probe: a passkey: ${String(said.passkey)}`).toBe(true);
926
+ expect(atOnce(said.payment), `probe: a payment: ${String(said.payment)}`).toBe(true);
927
+ expect(atOnce(said.share), `probe: a share: ${String(said.share)}`).toBe(true);
928
+ expect(atOnce(said.applePay), `probe: Apple Pay: ${String(said.applePay)}`).toBe(true);
929
+ expect(said.video === "absent" || String(said.video).startsWith("refused"), `probe: a video's full screen: ${String(said.video)}`).toBe(true);
930
+ expect(said.shown, "probe: a video in full screen").toBe(false);
928
931
  await page.waitForTimeout(SETTLE_MS);
929
- expect(await host.canaryHits("tab-payment"), "the payment method's address").toBe(0);
932
+ expect(await host.canaryHits("tab-payment"), "probe: the payment method's address").toBe(0);
930
933
  });
931
934
  define("served.domain.frame-ancestors", "only the host's origins may frame content", async ({ page }) => {
932
935
  const location = await host.locate(await host.shell("foreign"));
@@ -945,8 +948,8 @@ navigator.mediaDevices && navigator.mediaDevices.getUserMedia({ video: true }).t
945
948
  .catch(() => unreachable),
946
949
  new Promise((resolve) => setTimeout(() => resolve(unreachable), 3_000)),
947
950
  ]);
948
- expect(shown.root).toBe(false);
949
- expect(shown.origin).not.toBe(location.origin);
951
+ expect(shown.root, "probe: a foreign origin framed the content").toBe(false);
952
+ expect(shown.origin, "probe: a foreign origin framed the content's origin").not.toBe(location.origin);
950
953
  }
951
954
  });
952
955
  define("served.domain.egress", "the CSP in the document's headers closes egress; only what the config opens to any https site (images, media) reaches it", async ({ page }) => {
@@ -988,18 +991,18 @@ navigator.mediaDevices && navigator.mediaDevices.getUserMedia({ video: true }).t
988
991
  return { fetched, policy: policies.find((policy) => /connect-src/u.test(policy)) ?? "" };
989
992
  }, urls);
990
993
  await page.waitForTimeout(SETTLE_MS);
991
- expect(seen.fetched).toBe("blocked");
992
- expect(seen.policy, "a CSP applied to the document").not.toBe("");
994
+ expect(seen.fetched, "probe: the fetch got out").toBe("blocked");
995
+ expect(seen.policy, "probe: a CSP applied to the document").not.toBe("");
993
996
  const sources = new Map(seen.policy
994
997
  .split(";")
995
998
  .map((directive) => directive.trim().split(/\s+/u))
996
999
  .map(([name = "", ...rest]) => [name, rest]));
997
1000
  // What runs or talks never opens to any site (P059), whatever the config.
998
1001
  for (const name of ["script-src", "style-src", "connect-src", "frame-src", "default-src"]) {
999
- expect(sources.get(name) ?? [], `${name} opens no scheme`).not.toContain("https:");
1002
+ expect(sources.get(name) ?? [], `probe: ${name} opens no scheme`).not.toContain("https:");
1000
1003
  }
1001
1004
  for (const kind of ["fetch", "script", "style", "frame"]) {
1002
- expect(await host.canaryHits(`egress-${kind}`), kind).toBe(0);
1005
+ expect(await host.canaryHits(`egress-${kind}`), `probe: ${kind}`).toBe(0);
1003
1006
  }
1004
1007
  // Images and media: closed, unless the config opened them to any https site (P059);
1005
1008
  // then, the canary being an https site, an image reaches it, as the config means.
@@ -1016,10 +1019,10 @@ navigator.mediaDevices && navigator.mediaDevices.getUserMedia({ video: true }).t
1016
1019
  expect(await host.canaryHits("egress-img"), "the image, as the config opens it").toBeGreaterThan(0);
1017
1020
  }
1018
1021
  else {
1019
- expect(await host.canaryHits("egress-img"), "img").toBe(0);
1022
+ expect(await host.canaryHits("egress-img"), "probe: img").toBe(0);
1020
1023
  }
1021
1024
  if (!https("media")) {
1022
- expect(await host.canaryHits("egress-media"), "media").toBe(0);
1025
+ expect(await host.canaryHits("egress-media"), "probe: media").toBe(0);
1023
1026
  }
1024
1027
  });
1025
1028
  const resourceReady = (html) => ({
@@ -1040,9 +1043,9 @@ navigator.mediaDevices && navigator.mediaDevices.getUserMedia({ video: true }).t
1040
1043
  await expect
1041
1044
  .poll(async () => methodsOf(await display.received()))
1042
1045
  .toContain(MCP_APPS_METHODS.initialize);
1043
- await expect(frame.locator("html")).toHaveAttribute("data-fetch", "blocked");
1044
- expect(await frame.evaluate(() => [window.origin, document.documentElement.dataset.rtc])).toEqual([display.origin, "undefined"]);
1045
- expect(await host.canaryHits("proxy-undeclared")).toBe(0);
1046
+ await expect(frame.locator("html"), "probe: the view's undeclared fetch got out").toHaveAttribute("data-fetch", "blocked");
1047
+ expect(await frame.evaluate(() => [window.origin, document.documentElement.dataset.rtc]), "probe: the view runs hardened on its own origin").toEqual([display.origin, "undefined"]);
1048
+ expect(await host.canaryHits("proxy-undeclared"), "probe: the undeclared fetch reached the canary").toBe(0);
1046
1049
  });
1047
1050
  define("served.proxy.parent-only", "the sandbox proxy takes a view only from its host", async ({ page }) => {
1048
1051
  const display = await host.show(page, await host.proxy("proxy-parent"));
@@ -1050,7 +1053,7 @@ navigator.mediaDevices && navigator.mediaDevices.getUserMedia({ video: true }).t
1050
1053
  const frame = await display.frame();
1051
1054
  await frame.evaluate((message) => window.postMessage(message, "*"), resourceReady('<p id="view">Not from the host.</p>'));
1052
1055
  await page.waitForTimeout(SETTLE_MS);
1053
- expect(await frame.locator("#view").count()).toBe(0);
1056
+ expect(await frame.locator("#view").count(), "probe: the proxy took a view not from its host").toBe(0);
1054
1057
  });
1055
1058
  define("served.proxy.egress", "the sandbox proxy opens what the view declares, and nothing else", async ({ page }) => {
1056
1059
  const canary = await host.canary("proxy-declared");
@@ -1070,8 +1073,8 @@ navigator.mediaDevices && navigator.mediaDevices.getUserMedia({ video: true }).t
1070
1073
  const other = await fresh.newPage();
1071
1074
  const bare = await other.goto(`${location.origin}/`);
1072
1075
  const away = new URL(other.url()).origin !== location.origin;
1073
- expect(bare?.status() === 401 || away, `ended at ${other.url()}`).toBe(true);
1074
- expect(await other.evaluate(() => document.documentElement.dataset.app ?? null)).toBeNull();
1076
+ expect(bare?.status() === 401 || away, `probe: ended at ${other.url()}`).toBe(true);
1077
+ expect(await other.evaluate(() => document.documentElement.dataset.app ?? null), "probe: the app ran without its ticket's cookie").toBeNull();
1075
1078
  }
1076
1079
  finally {
1077
1080
  await fresh.close();
@@ -1130,7 +1133,7 @@ navigator.mediaDevices && navigator.mediaDevices.getUserMedia({ video: true }).t
1130
1133
  const b = await host.show(page, await host.app("url-siblings-b"));
1131
1134
  const frameB = await b.frame();
1132
1135
  await ready(frameB);
1133
- expect(await load(frameB, script), "another app's frame loading it").toBe("error");
1136
+ expect(await load(frameB, script), "probe: another app's frame loading it").toBe("error");
1134
1137
  }
1135
1138
  // Each on a tab of its own, in one browser.
1136
1139
  const c = await host.locate(await host.app("url-siblings-c"));
@@ -1143,7 +1146,7 @@ navigator.mediaDevices && navigator.mediaDevices.getUserMedia({ video: true }).t
1143
1146
  expect(await load(tab.mainFrame(), script), "the app's own load").toBe("load");
1144
1147
  await tab.goto(d.url);
1145
1148
  await ready(tab.mainFrame());
1146
- expect(await load(tab.mainFrame(), script), "another app's tab loading it").toBe("error");
1149
+ expect(await load(tab.mainFrame(), script), "probe: another app's tab loading it").toBe("error");
1147
1150
  }
1148
1151
  finally {
1149
1152
  await tab.close();