Skip to content

Commit b8ca826

Browse files
shivamhwpPR Batch Testerclaudemaria-rcks
authored
fix(server): preview status and snapshot never echo a data: page's contents (#22302)
Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 0b75a85 commit b8ca826

5 files changed

Lines changed: 55 additions & 5 deletions

File tree

‎apps/server/src/preview/ServerBrowser.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,45 @@ it.live.each([false, true])(
12361236
).pipe(Effect.provide(layer)),
12371237
);
12381238

1239+
it.effect("a tab showing a data: page reports its URL without the content", () =>
1240+
Effect.scoped(
1241+
Effect.gen(function* () {
1242+
const { broker, tabId } = yield* ready;
1243+
const sibling = yield* broker.invoke<PreviewAutomationStatus>({
1244+
scope: asSession("agent-b"),
1245+
operation: "open",
1246+
input: { reuseExistingTab: false, show: false },
1247+
});
1248+
yield* Effect.promise(() => contexts[1]!.page.goto("data:text/html,<p>SIBLING-SECRET</p>"));
1249+
const manager = yield* Manager.PreviewManager;
1250+
const events = yield* manager.subscribeEvents;
1251+
yield* Effect.promise(() => contexts[0]!.page.goto("data:text/html,<p>SECRET-KEY</p>"));
1252+
let event = yield* PubSub.take(events);
1253+
while (
1254+
event.type !== "navigated" ||
1255+
event.tabId !== tabId ||
1256+
event.snapshot.navStatus._tag !== "Success"
1257+
) {
1258+
event = yield* PubSub.take(events);
1259+
}
1260+
const status = yield* broker.invoke<PreviewAutomationStatus>({
1261+
scope,
1262+
tabId,
1263+
operation: "status",
1264+
input: {},
1265+
});
1266+
expect(event.snapshot.navStatus).toMatchObject({ url: "data:text/html,…" });
1267+
expect(status.url).toBe("data:text/html,…");
1268+
expect(status.tabs?.find((entry) => entry.tabId === tabId)?.url).toBe("data:text/html,…");
1269+
expect(status.tabs?.find((entry) => entry.tabId === sibling.tabId)?.url).toBe(
1270+
"data:text/html,…",
1271+
);
1272+
expect(JSON.stringify([event, status])).not.toContain("SECRET-KEY");
1273+
expect(JSON.stringify([event, status])).not.toContain("SIBLING-SECRET");
1274+
}),
1275+
).pipe(Effect.provide(layer)),
1276+
);
1277+
12391278
it.live.each(["save failed", "oversized"])(
12401279
"a rejected download releases the original and keeps no saved copy (%s)",
12411280
(outcome) =>

‎apps/server/src/preview/ServerBrowser.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,11 @@ const make = Effect.gen(function* () {
592592
if (url === "about:blank" || url.startsWith("chrome-error://")) return;
593593
const title = (await tab.page.title().catch(() => "")).slice(0, 512);
594594
if (tab.loading || tab.page.url() !== url) return;
595-
report(tab, { _tag: "Success", url: url.slice(0, 2048), title });
595+
report(tab, {
596+
_tag: "Success",
597+
url: ServerBrowserPage.withoutDataPayload(url).slice(0, 2048),
598+
title,
599+
});
596600
};
597601

598602
const reportLiveTabs = () => {
@@ -1560,7 +1564,7 @@ const make = Effect.gen(function* () {
15601564
...profileStatus(),
15611565
};
15621566
}
1563-
const url = tab.page.url();
1567+
const url = ServerBrowserPage.withoutDataPayload(tab.page.url());
15641568
const viewport = tab.desktop ? await layoutSize(tab) : tab.page.viewportSize();
15651569
const status = {
15661570
available: true,
@@ -1584,7 +1588,10 @@ const make = Effect.gen(function* () {
15841588
.filter((candidate) => candidate.threadId === tab.threadId)
15851589
.map((candidate) => ({
15861590
tabId: candidate.tabId,
1587-
url: candidate.page.url() === "about:blank" ? null : candidate.page.url(),
1591+
url:
1592+
candidate.page.url() === "about:blank"
1593+
? null
1594+
: ServerBrowserPage.withoutDataPayload(candidate.page.url()),
15881595
...(candidate.openerTabId === undefined ? {} : { openerTabId: candidate.openerTabId }),
15891596
owner: tabOwner(candidate),
15901597
ownedByCaller: candidate.control.agentId === agentSessionId,

‎apps/server/src/preview/ServerBrowserPage.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ describe("server browser element refs", () => {
212212
expect(tree).not.toContain("PAYLOAD");
213213
});
214214

215+
it("shows a data: page's own URL by media type only", async () => {
216+
await page.goto("data:text/html,<title>Key</title>PAYLOAD");
217+
expect((await takeSnapshot()).url).toBe("data:text/html,…");
218+
});
219+
215220
it("rejects refs from another tab", async () => {
216221
await page.setContent("<button>same label</button>");
217222
const locator = buttonLocator((await takeSnapshot()).accessibilityTree, "same label");

‎apps/server/src/preview/ServerBrowserPage.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ const capture = async (
583583
});
584584
return {
585585
...page,
586+
url: withoutDataPayload(page.url),
586587
// Mask text before truncating so a value crossing the cut cannot leak its prefix.
587588
visibleText: mask(page.visibleText).slice(0, MAX_VISIBLE_TEXT_LENGTH),
588589
accessibilityTree,

‎packages/shared/src/preview.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ export function normalizePreviewUrl(rawUrl: string): string {
200200
cause,
201201
});
202202
}
203-
// The server preview browser reports page URLs unredacted; a data: URL would put its
204-
// content in tool results and logs.
205203
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
206204
throw new PreviewUrlNormalizationError({
207205
inputLength: rawUrl.length,

0 commit comments

Comments
 (0)