fix(browser): redact transitional target titles
This commit is contained in:
@@ -53,35 +53,40 @@ describe("CdpBrowserProvider", () => {
|
||||
expect(JSON.stringify(result.value)).not.toContain("page-secret");
|
||||
});
|
||||
|
||||
it("sanitizes URL-shaped transitional target titles", async () => {
|
||||
const browser = await startFakeCdpBrowser({
|
||||
urlShapedAllowedTitle: true,
|
||||
});
|
||||
browsers.push(browser);
|
||||
const provider = new CdpBrowserProvider();
|
||||
const input = {
|
||||
cdp_endpoint: browser.endpoint,
|
||||
allowed_origins: [browser.allowedOrigin],
|
||||
approved: true as const,
|
||||
target_id: "allowed-page",
|
||||
};
|
||||
const listed = await provider.listTargets(
|
||||
listBrowserTargetsInputSchema.parse(input),
|
||||
);
|
||||
if (!listed.ok) throw listed.error;
|
||||
expect(listed.value.targets.items[0]?.title).toBe(
|
||||
`${browser.allowedOrigin}/app?startup=%5BREDACTED%5D`,
|
||||
);
|
||||
it.each([
|
||||
["absolute", true, ""],
|
||||
["host/path", "host-path", ""],
|
||||
["root-relative", "root-relative", ""],
|
||||
["prefixed host/path", "prefixed", "Loading "],
|
||||
] as const)(
|
||||
"sanitizes %s transitional target titles",
|
||||
async (_label, urlShapedAllowedTitle, prefix) => {
|
||||
const browser = await startFakeCdpBrowser({ urlShapedAllowedTitle });
|
||||
browsers.push(browser);
|
||||
const provider = new CdpBrowserProvider();
|
||||
const input = {
|
||||
cdp_endpoint: browser.endpoint,
|
||||
allowed_origins: [browser.allowedOrigin],
|
||||
approved: true as const,
|
||||
target_id: "allowed-page",
|
||||
};
|
||||
const expected = `${prefix}${browser.allowedOrigin}/app?startup=%5BREDACTED%5D`;
|
||||
const listed = await provider.listTargets(
|
||||
listBrowserTargetsInputSchema.parse(input),
|
||||
);
|
||||
if (!listed.ok) throw listed.error;
|
||||
expect(listed.value.targets.items[0]?.title).toBe(expected);
|
||||
|
||||
const inspected = await provider.inspectPage(
|
||||
inspectWebPageInputSchema.parse({ ...input, observation_ms: 0 }),
|
||||
);
|
||||
if (!inspected.ok) throw inspected.error;
|
||||
expect(inspected.value.target.title).toBe(
|
||||
`${browser.allowedOrigin}/app?startup=%5BREDACTED%5D`,
|
||||
);
|
||||
expect(JSON.stringify({ listed, inspected })).not.toContain("title-secret");
|
||||
});
|
||||
const inspected = await provider.inspectPage(
|
||||
inspectWebPageInputSchema.parse({ ...input, observation_ms: 0 }),
|
||||
);
|
||||
if (!inspected.ok) throw inspected.error;
|
||||
expect(inspected.value.target.title).toBe(expected);
|
||||
expect(JSON.stringify({ listed, inspected })).not.toContain(
|
||||
"title-secret",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("uses page-scoped discovery sockets as direct target transports", async () => {
|
||||
const browser = await startFakeCdpBrowser({
|
||||
|
||||
Vendored
+19
-5
@@ -62,7 +62,11 @@ interface FakeOptions {
|
||||
readonly webMcpChildLeavesScope?: boolean;
|
||||
readonly electronFileUrl?: string;
|
||||
readonly duplicateElectronInventory?: boolean;
|
||||
readonly urlShapedAllowedTitle?: boolean;
|
||||
readonly urlShapedAllowedTitle?:
|
||||
| boolean
|
||||
| "host-path"
|
||||
| "root-relative"
|
||||
| "prefixed";
|
||||
}
|
||||
|
||||
/** Start a real HTTP/WebSocket fake at the same seams as a user-owned browser. */
|
||||
@@ -226,10 +230,7 @@ const targets = (
|
||||
{
|
||||
id: "allowed-page",
|
||||
type: "page",
|
||||
title:
|
||||
options.urlShapedAllowedTitle === true
|
||||
? `http://127.0.0.1:${String(port)}/app?startup=title-secret#fragment`
|
||||
: "Inspectable application",
|
||||
title: allowedPageTitle(port, options.urlShapedAllowedTitle),
|
||||
url: `http://127.0.0.1:${String(port)}/app?token=page-secret#fragment`,
|
||||
attached: false,
|
||||
...(options.omitTargetWebSocket === true
|
||||
@@ -333,6 +334,19 @@ const targets = (
|
||||
]),
|
||||
];
|
||||
|
||||
const allowedPageTitle = (
|
||||
port: number,
|
||||
style: FakeOptions["urlShapedAllowedTitle"],
|
||||
): string => {
|
||||
const suffix = "/app?startup=title-secret#fragment";
|
||||
const host = `127.0.0.1:${String(port)}`;
|
||||
if (style === true) return `http://${host}${suffix}`;
|
||||
if (style === "host-path") return `${host}${suffix}`;
|
||||
if (style === "root-relative") return suffix;
|
||||
if (style === "prefixed") return `Loading ${host}${suffix}`;
|
||||
return "Inspectable application";
|
||||
};
|
||||
|
||||
const parseCommand = (text: string): FakeCdpCommand => {
|
||||
const value: unknown = JSON.parse(text);
|
||||
if (typeof value !== "object" || value === null)
|
||||
|
||||
Reference in New Issue
Block a user