fix(browser): block node routes when sandbox host control is disabled (#97958)

This commit is contained in:
Agustin Rivera
2026-06-29 17:10:12 -07:00
committed by GitHub
parent fd3f354f46
commit 2cf765f732
2 changed files with 25 additions and 1 deletions
+16 -1
View File
@@ -871,6 +871,21 @@ describe("browser tool snapshot maxChars", () => {
expect(browserClientMocks.browserStatus).not.toHaveBeenCalled();
});
it.each([
["target=node", { target: "node" }],
["an explicit node pin", { node: "node-1" }],
["automatic node routing", {}],
])("blocks %s when host control is disabled", async (_label, route) => {
mockSingleBrowserProxyNode();
const tool = createBrowserTool({ allowHostControl: false });
await expect(tool.execute?.("call-1", { action: "status", ...route })).rejects.toThrow(
/browser control is disabled by sandbox policy/i,
);
expect(gatewayMocks.callGatewayTool).not.toHaveBeenCalled();
expect(browserClientMocks.browserStatus).not.toHaveBeenCalled();
});
it("fails node proxy calls cleanly when payloadJSON is malformed", async () => {
mockSingleBrowserProxyNode();
gatewayMocks.callGatewayTool.mockResolvedValueOnce({
@@ -1247,7 +1262,7 @@ describe("browser tool snapshot maxChars", () => {
setResolvedBrowserProfiles({
user: { driver: "existing-session", attachOnly: true, color: "#00AA00" },
});
const tool = createBrowserTool();
const tool = createBrowserTool({ allowHostControl: true });
await tool.execute?.("call-1", { action: "status", profile: "user", target: "node" });
const { options, request } = lastNodeInvokeCall();
+9
View File
@@ -262,7 +262,15 @@ async function resolveBrowserNodeTarget(params: {
requestedNode?: string;
target?: "sandbox" | "host" | "node";
sandboxBridgeUrl?: string;
allowHostControl?: boolean;
}): Promise<BrowserNodeTarget | null> {
if (params.allowHostControl === false) {
if (params.target === "node" || params.requestedNode) {
throw new Error("Node browser control is disabled by sandbox policy.");
}
return null;
}
const cfg = browserToolDeps.getRuntimeConfig();
const policy = cfg.gateway?.nodes?.browser;
const mode = policy?.mode ?? "auto";
@@ -538,6 +546,7 @@ export function createBrowserTool(opts?: {
requestedNode: requestedNode ?? undefined,
target,
sandboxBridgeUrl: opts?.sandboxBridgeUrl,
allowHostControl: opts?.allowHostControl,
});
} catch (error) {
// Keep the logged-in user browser usable on the host when auto-discovery