fix(browser): scope workers and binary frame sizes
This commit is contained in:
@@ -242,11 +242,15 @@ export class CdpCaptureEvents {
|
||||
}
|
||||
const response = recordValue(params.response);
|
||||
const payload = stringValue(response?.payloadData) ?? "";
|
||||
const opcode = Math.max(0, Math.trunc(numberValue(response?.opcode) ?? 0));
|
||||
this.websockets.push({
|
||||
request_id: requestId,
|
||||
direction,
|
||||
opcode: Math.max(0, Math.trunc(numberValue(response?.opcode) ?? 0)),
|
||||
payload_bytes: Buffer.byteLength(payload),
|
||||
opcode,
|
||||
payload_bytes:
|
||||
opcode === 1
|
||||
? Buffer.byteLength(payload)
|
||||
: Buffer.from(payload, "base64").byteLength,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -131,6 +131,7 @@ const captureAuthorizedPage = async (
|
||||
const workerCapture = await captureWorkers(
|
||||
context,
|
||||
allowedOrigins,
|
||||
new Set(frames.map((frame) => frame.frame_id)),
|
||||
limitations,
|
||||
);
|
||||
if (workerCapture.total > workerCapture.items.length)
|
||||
@@ -384,6 +385,7 @@ const captureScripts = async (
|
||||
const captureWorkers = async (
|
||||
context: CaptureContext,
|
||||
allowedOrigins: ReadonlySet<string>,
|
||||
frameIds: ReadonlySet<string>,
|
||||
limitations: string[],
|
||||
): Promise<{
|
||||
readonly total: number;
|
||||
@@ -400,7 +402,12 @@ const captureWorkers = async (
|
||||
for (const target of recordsValue(recordValue(result)?.targetInfos)) {
|
||||
const type = stringValue(target.type) ?? "";
|
||||
const url = allowedSanitizedUrl(target.url, allowedOrigins);
|
||||
if (!type.includes("worker") || url === undefined) continue;
|
||||
const relatedToPage =
|
||||
stringValue(target.openerId) === context.target.id ||
|
||||
(stringValue(target.parentFrameId) !== undefined &&
|
||||
frameIds.has(stringValue(target.parentFrameId) ?? ""));
|
||||
if (!type.includes("worker") || url === undefined || !relatedToPage)
|
||||
continue;
|
||||
total += 1;
|
||||
if (items.length >= context.input.limits.max_workers) continue;
|
||||
items.push({
|
||||
|
||||
@@ -50,7 +50,11 @@ describe("CdpBrowserProvider", () => {
|
||||
});
|
||||
|
||||
it("captures bounded passive evidence without retaining sensitive values", async () => {
|
||||
const browser = await startFakeCdpBrowser({ foreignSessionEvents: true });
|
||||
const browser = await startFakeCdpBrowser({
|
||||
binaryWebSocketEvent: true,
|
||||
foreignSessionEvents: true,
|
||||
unrelatedWorker: true,
|
||||
});
|
||||
browsers.push(browser);
|
||||
const provider = new CdpBrowserProvider();
|
||||
const result = await provider.inspectPage(
|
||||
@@ -85,6 +89,12 @@ describe("CdpBrowserProvider", () => {
|
||||
opcode: 1,
|
||||
payload_bytes: Buffer.byteLength("websocket-secret"),
|
||||
},
|
||||
{
|
||||
request_id: "websocket-1",
|
||||
direction: "received",
|
||||
opcode: 2,
|
||||
payload_bytes: 3,
|
||||
},
|
||||
]);
|
||||
expect(result.value.console.events[0]?.argument_types).toEqual(["string"]);
|
||||
expect(result.value.workers).toHaveLength(1);
|
||||
|
||||
Vendored
+25
@@ -34,6 +34,8 @@ interface FakeOptions {
|
||||
readonly extraCollections?: boolean;
|
||||
readonly foreignSessionEvents?: boolean;
|
||||
readonly redirectToDisallowedOrigin?: boolean;
|
||||
readonly unrelatedWorker?: boolean;
|
||||
readonly binaryWebSocketEvent?: boolean;
|
||||
}
|
||||
|
||||
/** Start a real HTTP/WebSocket fake at the same seams as a user-owned browser. */
|
||||
@@ -180,6 +182,7 @@ const targets = (
|
||||
title: "Worker",
|
||||
url: `http://127.0.0.1:${String(port)}/worker.js?secret=worker`,
|
||||
attached: false,
|
||||
openerId: "allowed-page",
|
||||
},
|
||||
...(options.extraCollections === true
|
||||
? [
|
||||
@@ -189,6 +192,19 @@ const targets = (
|
||||
title: "Second worker",
|
||||
url: `http://127.0.0.1:${String(port)}/worker-2.js`,
|
||||
attached: false,
|
||||
openerId: "allowed-page",
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(options.unrelatedWorker === true
|
||||
? [
|
||||
{
|
||||
id: "worker-other-page",
|
||||
type: "dedicated_worker",
|
||||
title: "Other page worker",
|
||||
url: `http://127.0.0.1:${String(port)}/other-page-worker.js`,
|
||||
attached: false,
|
||||
openerId: "other-page",
|
||||
},
|
||||
]
|
||||
: []),
|
||||
@@ -285,6 +301,10 @@ const endpointTargetToInfo = (
|
||||
title: target.title,
|
||||
url: target.url,
|
||||
attached: target.attached,
|
||||
...(target.openerId === undefined ? {} : { openerId: target.openerId }),
|
||||
...(target.parentFrameId === undefined
|
||||
? {}
|
||||
: { parentFrameId: target.parentFrameId }),
|
||||
});
|
||||
|
||||
const frameTree = (
|
||||
@@ -521,6 +541,11 @@ const emitEvents = (
|
||||
requestId: "websocket-1",
|
||||
response: { opcode: 1, payloadData: "websocket-secret" },
|
||||
});
|
||||
if (options.binaryWebSocketEvent === true)
|
||||
event(socket, "Network.webSocketFrameReceived", command.sessionId, {
|
||||
requestId: "websocket-1",
|
||||
response: { opcode: 2, payloadData: "AQID" },
|
||||
});
|
||||
}
|
||||
if (command.method === "Runtime.enable") {
|
||||
event(socket, "Runtime.consoleAPICalled", command.sessionId, {
|
||||
|
||||
Reference in New Issue
Block a user