Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(browser): reject blank-page website navigation verification

agooll420d8f3df5dd
diff --git a/server/browser-runtime.test.ts b/server/browser-runtime.test.ts
index 6cb7048f5e..aad1a04186 100644
--- a/server/browser-runtime.test.ts
+++ b/server/browser-runtime.test.ts
@@ -229,6 +229,7 @@ lines.on('line', line => {
else if (m.params.name === 'agent_browser_snapshot' && process.env.HANG_VERIFICATION === '1') return;
else if (m.params.name === 'agent_browser_snapshot' && process.env.EMPTY_VERIFICATION === '1') result = { content:[] };
else if (m.params.name === 'agent_browser_snapshot' && process.env.FAIL_VERIFICATION === '1') result = { isError:true, content:[{type:'text',text:'Snapshot unavailable'}] };
+ else if (m.params.name === 'agent_browser_snapshot' && process.env.SNAPSHOT_ORIGIN) result = { content:[{type:'text',text:'(empty page)'}], structuredContent:{ response:{ success:true, data:{ origin:process.env.SNAPSHOT_ORIGIN, refs:{}, snapshot:'(empty page)' }, error:null } } };
// LEAK: a page that shows a filled password back, in every kind of result.
else if (process.env.LEAK && m.params.name !== 'agent_browser_get_url') result = { content:[{type:'text',text:'page says ' + process.env.LEAK},{type:'image',data:'AAAA',mimeType:'image/png'}], structuredContent:{ value: process.env.LEAK } };
else if (m.params.name === 'agent_browser_eval' && process.env.FAIL_EVAL === '1') result = { isError:true, content:[{type:'text',text:'Evaluation failed'}] };
@@ -359,6 +360,36 @@ describe("server-owned browser MCP runtime", () => {
expect(result.content[1].text).toContain("Its refs are current");
expect(JSON.parse(result.content[2].text)).toEqual({ name: "agent_browser_snapshot", arguments: { compact: true } });
});
+ it("rejects a successful website navigation whose verification observes about:blank, without retrying", async () => {
+ const daemon = daemonSpec();
+ daemon.spec.env.SNAPSHOT_ORIGIN = "about:blank";
+ try {
+ const result = await runtime().agentRpc("lost-page", daemon.spec, "tools/call", {
+ name: "agent_browser_open", arguments: { url: "https://example.com" },
+ }) as { isError?: boolean; content: Array<{ text: string }> };
+ expect(result.isError).toBe(true);
+ expect(JSON.parse(result.content[0].text).name).toBe("agent_browser_open");
+ expect(result.content[1].text).toContain("verification failed");
+ expect(result.content[1].text).not.toContain("Its refs are current");
+ expect(result.content[2].text).toBe("(empty page)");
+ expect(daemon.calls()).toEqual(["agent_browser_open", "agent_browser_snapshot"]);
+ } finally { daemon.cleanup(); }
+ });
+ it.each([
+ [{ url: "about:blank" }, "about:blank"],
+ [{}, "about:blank"],
+ [{ url: "https://example.com" }, "https://example.com/"],
+ [{ url: "https://example.com" }, "https://signin.example.net/login"],
+ ])("allows an intentional blank page, empty website or redirect: %j -> %s", async (args, origin) => {
+ const daemon = spec();
+ daemon.env.SNAPSHOT_ORIGIN = origin;
+ const result = await runtime().agentRpc("allowed-page", daemon, "tools/call", {
+ name: "agent_browser_open", arguments: args,
+ }) as { isError?: boolean; content: Array<{ text: string }> };
+ expect(result.isError).not.toBe(true);
+ expect(result.content[1].text).toContain("Its refs are current");
+ expect(result.content[2].text).toBe("(empty page)");
+ });
it("says what an action changed on the page, read with eval so the model's refs stay valid", async () => {
const result = await runtime().agentRpc("act", spec(), "tools/call", {
name: "agent_browser_click", arguments: { selector: "@e5" },
diff --git a/server/browser-runtime.ts b/server/browser-runtime.ts
index 50b474f521..1aed61fba3 100644
--- a/server/browser-runtime.ts
+++ b/server/browser-runtime.ts
@@ -1,6 +1,6 @@
import { killCliTree, spawnCli } from "./procs.ts";
import { scrubHeldSecrets } from "../shared/redact.ts";
-import { DEFAULT_BROWSER_RESULT_BUDGET, describePageChange, OBSERVE_PAGE_SCRIPT, parsePageState, READ_OPEN_PAGE_ONLY, readsAroundBrowser, scrubBrowserResult, shapeBrowserToolResult, slimBrowserToolList, stripHarnessOwnedArguments, type PageState } from "./browser-tool-shape.ts";
+import { DEFAULT_BROWSER_RESULT_BUDGET, describePageChange, OBSERVE_PAGE_SCRIPT, parsePageState, READ_OPEN_PAGE_ONLY, readsAroundBrowser, scrubBrowserResult, shapeBrowserToolResult, slimBrowserToolList, stripHarnessOwnedArguments, verifiedBrowserNavigation, type PageState } from "./browser-tool-shape.ts";
import { BrowserLanes } from "./browser-lane.ts";
import { PageSizes, type PageSize } from "./browser-page-size.ts";
import { SECRET_ON_PAGE, SecretHolds, type SecretHold } from "./browser-secret-hold.ts";
@@ -608,9 +608,7 @@ export class BrowserRuntime {
beforeDispatch?.();
const navigation = result as { content?: unknown[]; structuredContent?: unknown };
const page = observation as { content?: unknown[]; isError?: boolean } | null;
- const observed = page?.isError !== true && Array.isArray(page?.content) && page.content.some((item) =>
- item && typeof item === "object" && (item as { type?: unknown }).type === "text" &&
- typeof (item as { text?: unknown }).text === "string" && (item as { text: string }).text.trim().length > 0);
+ const observed = verifiedBrowserNavigation(args, observation);
result = {
content: [
...(Array.isArray(navigation.content) ? navigation.content : []),
diff --git a/server/browser-tool-shape.ts b/server/browser-tool-shape.ts
index 7927a2af75..dc48e894d3 100644
--- a/server/browser-tool-shape.ts
+++ b/server/browser-tool-shape.ts
@@ -22,6 +22,18 @@ function isRecord(value: unknown): value is Record<string, unknown> {
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
}
+export function verifiedBrowserNavigation(args: unknown, observation: unknown): boolean {
+ if (!isRecord(observation) || observation.isError === true || !Array.isArray(observation.content)) return false;
+ const structured = observation.structuredContent;
+ const response = isRecord(structured) ? structured.response : undefined;
+ const data = isRecord(response) ? response.data : undefined;
+ const url = isRecord(args) ? args.url : undefined;
+ if (typeof url === "string" && /^https?:\/\//i.test(url.trim()) &&
+ isRecord(data) && data.origin === "about:blank") return false;
+ return observation.content.some((item) => isRecord(item) && item.type === "text" &&
+ typeof item.text === "string" && item.text.trim().length > 0);
+}
+
/** agent-browser 0.37.0 fetches a `url` given to agent_browser_read with its own HTTP client, around the browser and its
* egress gate, and ignores every proxy setting; without one it reads the open tab. */
const READ_TOOL = "agent_browser_read";