fix(browser): validate and bound source-map evidence
This commit is contained in:
@@ -27,6 +27,50 @@ export async function startBrowserVerifierSite() {
|
||||
response.end(sourceMap());
|
||||
return;
|
||||
}
|
||||
if (request.url === "/bad.js.map") {
|
||||
response.setHeader("content-type", "application/source-map+json");
|
||||
response.end(
|
||||
JSON.stringify({
|
||||
version: 3,
|
||||
names: [],
|
||||
sources: ["../src/bad.ts"],
|
||||
mappings: "AAAAD",
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (request.url === "/expanded.js.map") {
|
||||
response.setHeader("content-type", "application/source-map+json");
|
||||
response.end(
|
||||
JSON.stringify({
|
||||
version: 3,
|
||||
names: [],
|
||||
sources: ["../src/" + "x".repeat(300000) + ".ts"],
|
||||
mappings: "AAAA" + ",CAAA".repeat(127),
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (request.url === "/overflow.js.map") {
|
||||
response.setHeader("content-type", "application/source-map+json");
|
||||
response.end(
|
||||
JSON.stringify({
|
||||
version: 3,
|
||||
sections: [
|
||||
{
|
||||
offset: { line: 0, column: Number.MAX_SAFE_INTEGER },
|
||||
map: {
|
||||
version: 3,
|
||||
names: [],
|
||||
sources: ["overflow.ts"],
|
||||
mappings: "CAAA",
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (request.url === "/session-generation") {
|
||||
response.setHeader("content-type", "application/json");
|
||||
response.end(JSON.stringify({ generation: sessionGeneration }));
|
||||
@@ -37,6 +81,27 @@ export async function startBrowserVerifierSite() {
|
||||
response.end(browserScript(port));
|
||||
return;
|
||||
}
|
||||
if (request.url?.startsWith("/bad.js") === true) {
|
||||
response.setHeader("content-type", "text/javascript");
|
||||
response.end(
|
||||
"export const badMapProbe = true;\n//# sourceMappingURL=/bad.js.map",
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (request.url?.startsWith("/expanded.js") === true) {
|
||||
response.setHeader("content-type", "text/javascript");
|
||||
response.end(
|
||||
"export const expandedMapProbe = true;\n//# sourceMappingURL=/expanded.js.map",
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (request.url?.startsWith("/overflow.js") === true) {
|
||||
response.setHeader("content-type", "text/javascript");
|
||||
response.end(
|
||||
"export const overflowMapProbe = true;\n//# sourceMappingURL=/overflow.js.map",
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (request.url?.startsWith("/api") === true) {
|
||||
response.setHeader("content-type", "application/json");
|
||||
response.setHeader(
|
||||
@@ -113,6 +178,9 @@ const browserScript = (port) => `
|
||||
socket.addEventListener("open", () => socket.send(JSON.stringify({ token: "websocket-secret-value" })));
|
||||
socket.addEventListener("message", () => socket.close());
|
||||
};
|
||||
void import("/bad.js");
|
||||
void import("/expanded.js");
|
||||
void import("/overflow.js");
|
||||
observe();
|
||||
setInterval(observe, 150);
|
||||
let observedGeneration = 0;
|
||||
|
||||
@@ -150,7 +150,7 @@ export function assertBundleAnalysis(result) {
|
||||
)
|
||||
throw new Error("Real Chrome static bundle findings were missing");
|
||||
if (
|
||||
result.observations.source_maps.status !== "included" ||
|
||||
result.observations.source_maps.status !== "partial" ||
|
||||
!result.observations.source_maps.items.some(
|
||||
({ status, original_sources, original_module_edges, mappings }) =>
|
||||
status === "included" &&
|
||||
@@ -166,6 +166,41 @@ export function assertBundleAnalysis(result) {
|
||||
throw new Error(
|
||||
`Real Chrome approved source-map reconstruction was missing: ${JSON.stringify(sourceMapSummary(result.observations.source_maps))}`,
|
||||
);
|
||||
if (
|
||||
!result.observations.source_maps.items.some(
|
||||
({ declared_url, status, artifact, mappings }) =>
|
||||
declared_url.endsWith("/bad.js.map") &&
|
||||
status === "invalid" &&
|
||||
artifact === null &&
|
||||
mappings.length === 0,
|
||||
)
|
||||
)
|
||||
throw new Error(
|
||||
`Real Chrome malformed-map isolation was missing: ${JSON.stringify(sourceMapSummary(result.observations.source_maps))}`,
|
||||
);
|
||||
if (
|
||||
!result.observations.source_maps.items.some(
|
||||
({ declared_url, status, limitation, mappings }) =>
|
||||
declared_url.endsWith("/expanded.js.map") &&
|
||||
status === "fetch_failed" &&
|
||||
limitation.includes("Expanded source-map evidence") &&
|
||||
mappings.length === 0,
|
||||
)
|
||||
)
|
||||
throw new Error(
|
||||
`Real Chrome expanded-map omission was missing: ${JSON.stringify(sourceMapSummary(result.observations.source_maps))}`,
|
||||
);
|
||||
if (
|
||||
!result.observations.source_maps.items.some(
|
||||
({ declared_url, status, mappings }) =>
|
||||
declared_url.endsWith("/overflow.js.map") &&
|
||||
status === "invalid" &&
|
||||
mappings.length === 0,
|
||||
)
|
||||
)
|
||||
throw new Error(
|
||||
`Real Chrome overflowing-map isolation was missing: ${JSON.stringify(sourceMapSummary(result.observations.source_maps))}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** Assert explicitly selected console text and JSON/WebSocket shape capture. */
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { spawn } from "node:child_process";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { access, mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { CdpBrowserProvider } from "../dist/browser/CdpBrowserProvider.js";
|
||||
import { waitForBrowserDevtoolsPort } from "../dist/browser/BrowserProcessStartup.js";
|
||||
@@ -12,7 +15,6 @@ import {
|
||||
inspectWebPageInputSchema,
|
||||
listBrowserTargetsInputSchema,
|
||||
} from "../dist/domain/browserObservation.js";
|
||||
import { analyzeWebBundleInputSchema } from "../dist/domain/webBundleAnalysis.js";
|
||||
import { observeWebSessionInputSchema } from "../dist/domain/browserSession.js";
|
||||
import { compareWebCapturesInputSchema } from "../dist/domain/webCaptureDiff.js";
|
||||
import {
|
||||
@@ -39,6 +41,7 @@ import { verifyBrowserNetworkEvidence } from "./lib/browser-network-e2e.mjs";
|
||||
import { verifyBrowserScriptExport } from "./lib/browser-script-export-e2e.mjs";
|
||||
import { verifyBrowserModules } from "./lib/browser-module-e2e.mjs";
|
||||
import { verifyBrowserDomDestinations } from "./lib/browser-dom-destinations-e2e.mjs";
|
||||
import { artifactCliEvidence, artifactMcpResult } from "./lib/artifact-e2e.mjs";
|
||||
|
||||
const REAL_BROWSER_STARTUP_TIMEOUT_MS = 60_000;
|
||||
const SCENARIO_SECRET_VALUE = "rea-browser-verifier-secret";
|
||||
@@ -160,17 +163,7 @@ try {
|
||||
);
|
||||
assertSensitiveShapes(withSource.value);
|
||||
|
||||
const bundle = await provider.analyzeBundle(
|
||||
analyzeWebBundleInputSchema.parse({
|
||||
cdp_endpoint: endpoint,
|
||||
allowed_origins: [site.origin],
|
||||
target_id: target,
|
||||
observation_ms: 200,
|
||||
fetch_source_maps: true,
|
||||
}),
|
||||
);
|
||||
if (!bundle.ok) throw bundle.error;
|
||||
assertBundleAnalysis(bundle.value);
|
||||
const bundle = await verifyPublicBundle(endpoint, target, site.origin);
|
||||
|
||||
const captureDiff = await provider.compareCaptures(
|
||||
compareWebCapturesInputSchema.parse({
|
||||
@@ -349,8 +342,9 @@ try {
|
||||
networkRequests: observed.value.network.requests.length,
|
||||
consoleEvents: observed.value.console.events.length,
|
||||
websocketEvents: observed.value.network.websocket_events.length,
|
||||
bundleScripts: bundle.value.capture.scripts_analyzed,
|
||||
sourceMaps: bundle.value.observations.source_maps.processed,
|
||||
bundleScripts: bundle.capture.scripts_analyzed,
|
||||
sourceMaps: bundle.observations.source_maps.processed,
|
||||
bundle_cli_and_stdio_mcp: true,
|
||||
sessionEvents: session.value.timeline.length,
|
||||
pageScopedTransport: true,
|
||||
screenshotBytes: screenshot.value.artifact.bytes,
|
||||
@@ -383,6 +377,43 @@ process.stdout.write(
|
||||
})}\n`,
|
||||
);
|
||||
|
||||
async function verifyPublicBundle(endpoint, target, origin) {
|
||||
const evidence = await artifactCliEvidence("analyze-web-bundle", endpoint, [
|
||||
target,
|
||||
"--allowed-origins",
|
||||
origin,
|
||||
"--fetch-source-maps",
|
||||
"--observation-ms",
|
||||
"200",
|
||||
]);
|
||||
assertBundleAnalysis(evidence.normalized_result);
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [fileURLToPath(new URL("./rea.mjs", import.meta.url)), "mcp"],
|
||||
env: { PATH: process.env.PATH ?? "", REA_LOG_LEVEL: "silent" },
|
||||
stderr: "pipe",
|
||||
});
|
||||
const client = new Client({ name: "browser-bundle-e2e", version: "1" });
|
||||
try {
|
||||
await client.connect(transport);
|
||||
const result = await artifactMcpResult(client, "analyze_web_bundle", {
|
||||
cdp_endpoint: endpoint,
|
||||
target_id: target,
|
||||
allowed_origins: [origin],
|
||||
fetch_source_maps: true,
|
||||
observation_ms: 200,
|
||||
});
|
||||
assertBundleAnalysis(result);
|
||||
} finally {
|
||||
try {
|
||||
await client.close();
|
||||
} finally {
|
||||
await transport.close();
|
||||
}
|
||||
}
|
||||
return evidence.normalized_result;
|
||||
}
|
||||
|
||||
async function verifyPageScopedTransport(provider, proxy, origin) {
|
||||
const target = await pageTarget(provider, proxy.endpoint);
|
||||
const input = inspectWebPageInputSchema.parse({
|
||||
|
||||
Reference in New Issue
Block a user