Skip to content
TypeScript

fix(server): preview status and snapshot never echo a data: page's contents (#22302)

shivamb8ca826bf6a9
diff --git a/apps/server/src/preview/ServerBrowser.test.ts b/apps/server/src/preview/ServerBrowser.test.ts
index f4671d89b56..dee5a5c3764 100644
--- a/apps/server/src/preview/ServerBrowser.test.ts
+++ b/apps/server/src/preview/ServerBrowser.test.ts
@@ -1236,6 +1236,45 @@ it.live.each([false, true])(
).pipe(Effect.provide(layer)),
);
+it.effect("a tab showing a data: page reports its URL without the content", () =>
+ Effect.scoped(
+ Effect.gen(function* () {
+ const { broker, tabId } = yield* ready;
+ const sibling = yield* broker.invoke<PreviewAutomationStatus>({
+ scope: asSession("agent-b"),
+ operation: "open",
+ input: { reuseExistingTab: false, show: false },
+ });
+ yield* Effect.promise(() => contexts[1]!.page.goto("data:text/html,<p>SIBLING-SECRET</p>"));
+ const manager = yield* Manager.PreviewManager;
+ const events = yield* manager.subscribeEvents;
+ yield* Effect.promise(() => contexts[0]!.page.goto("data:text/html,<p>SECRET-KEY</p>"));
+ let event = yield* PubSub.take(events);
+ while (
+ event.type !== "navigated" ||
+ event.tabId !== tabId ||
+ event.snapshot.navStatus._tag !== "Success"
+ ) {
+ event = yield* PubSub.take(events);
+ }
+ const status = yield* broker.invoke<PreviewAutomationStatus>({
+ scope,
+ tabId,
+ operation: "status",
+ input: {},
+ });
+ expect(event.snapshot.navStatus).toMatchObject({ url: "data:text/html,…" });
+ expect(status.url).toBe("data:text/html,…");
+ expect(status.tabs?.find((entry) => entry.tabId === tabId)?.url).toBe("data:text/html,…");
+ expect(status.tabs?.find((entry) => entry.tabId === sibling.tabId)?.url).toBe(
+ "data:text/html,…",
+ );
+ expect(JSON.stringify([event, status])).not.toContain("SECRET-KEY");
+ expect(JSON.stringify([event, status])).not.toContain("SIBLING-SECRET");
+ }),
+ ).pipe(Effect.provide(layer)),
+);
+
it.live.each(["save failed", "oversized"])(
"a rejected download releases the original and keeps no saved copy (%s)",
(outcome) =>
diff --git a/apps/server/src/preview/ServerBrowser.ts b/apps/server/src/preview/ServerBrowser.ts
index 84299d3e924..9947aed88f6 100644
--- a/apps/server/src/preview/ServerBrowser.ts
+++ b/apps/server/src/preview/ServerBrowser.ts
@@ -592,7 +592,11 @@ const make = Effect.gen(function* () {
if (url === "about:blank" || url.startsWith("chrome-error://")) return;
const title = (await tab.page.title().catch(() => "")).slice(0, 512);
if (tab.loading || tab.page.url() !== url) return;
- report(tab, { _tag: "Success", url: url.slice(0, 2048), title });
+ report(tab, {
+ _tag: "Success",
+ url: ServerBrowserPage.withoutDataPayload(url).slice(0, 2048),
+ title,
+ });
};
const reportLiveTabs = () => {
@@ -1560,7 +1564,7 @@ const make = Effect.gen(function* () {
...profileStatus(),
};
}
- const url = tab.page.url();
+ const url = ServerBrowserPage.withoutDataPayload(tab.page.url());
const viewport = tab.desktop ? await layoutSize(tab) : tab.page.viewportSize();
const status = {
available: true,
@@ -1584,7 +1588,10 @@ const make = Effect.gen(function* () {
.filter((candidate) => candidate.threadId === tab.threadId)
.map((candidate) => ({
tabId: candidate.tabId,
- url: candidate.page.url() === "about:blank" ? null : candidate.page.url(),
+ url:
+ candidate.page.url() === "about:blank"
+ ? null
+ : ServerBrowserPage.withoutDataPayload(candidate.page.url()),
...(candidate.openerTabId === undefined ? {} : { openerTabId: candidate.openerTabId }),
owner: tabOwner(candidate),
ownedByCaller: candidate.control.agentId === agentSessionId,
diff --git a/apps/server/src/preview/ServerBrowserPage.test.ts b/apps/server/src/preview/ServerBrowserPage.test.ts
index eee077fbf05..d58fe63047b 100644
--- a/apps/server/src/preview/ServerBrowserPage.test.ts
+++ b/apps/server/src/preview/ServerBrowserPage.test.ts
@@ -212,6 +212,11 @@ describe("server browser element refs", () => {
expect(tree).not.toContain("PAYLOAD");
});
+ it("shows a data: page's own URL by media type only", async () => {
+ await page.goto("data:text/html,<title>Key</title>PAYLOAD");
+ expect((await takeSnapshot()).url).toBe("data:text/html,…");
+ });
+
it("rejects refs from another tab", async () => {
await page.setContent("<button>same label</button>");
const locator = buttonLocator((await takeSnapshot()).accessibilityTree, "same label");
diff --git a/apps/server/src/preview/ServerBrowserPage.ts b/apps/server/src/preview/ServerBrowserPage.ts
index 88308ed691e..d573cd6387c 100644
--- a/apps/server/src/preview/ServerBrowserPage.ts
+++ b/apps/server/src/preview/ServerBrowserPage.ts
@@ -583,6 +583,7 @@ const capture = async (
});
return {
...page,
+ url: withoutDataPayload(page.url),
// Mask text before truncating so a value crossing the cut cannot leak its prefix.
visibleText: mask(page.visibleText).slice(0, MAX_VISIBLE_TEXT_LENGTH),
accessibilityTree,
diff --git a/packages/shared/src/preview.ts b/packages/shared/src/preview.ts
index 4f337f5be3d..30a6bdc8b1c 100644
--- a/packages/shared/src/preview.ts
+++ b/packages/shared/src/preview.ts
@@ -200,8 +200,6 @@ export function normalizePreviewUrl(rawUrl: string): string {
cause,
});
}
- // The server preview browser reports page URLs unredacted; a data: URL would put its
- // content in tool results and logs.
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
throw new PreviewUrlNormalizationError({
inputLength: rawUrl.length,