惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Last Week in AI
Last Week in AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
雷峰网
雷峰网
IT之家
IT之家
I
InfoQ
酷 壳 – CoolShell
酷 壳 – CoolShell
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
B
Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 【当耐特】
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
月光博客
月光博客
P
Proofpoint News Feed
博客园 - 三生石上(FineUI控件)
J
Java Code Geeks
G
Google Developers Blog
小众软件
小众软件
宝玉的分享
宝玉的分享
Jina AI
Jina AI
V
Visual Studio Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(browser): validate hook download timeouts · openclaw/...
steipete · 2026-05-29 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -1,3 +1,4 @@

1+

import { formatErrorMessage } from "../../infra/errors.js";

12

import { getBrowserProfileCapabilities } from "../profile-capabilities.js";

23

import type { BrowserRouteContext } from "../server-context.js";

34

import {

@@ -9,8 +10,9 @@ import {

910

import { EXISTING_SESSION_LIMITS } from "./existing-session-limits.js";

1011

import { ensureOutputRootDir, resolveWritableOutputPathOrRespond } from "./output-paths.js";

1112

import { DEFAULT_DOWNLOAD_DIR } from "./path-output.js";

13+

import { readRoutePositiveInteger } from "./route-numeric.js";

1214

import type { BrowserRouteRegistrar } from "./types.js";

13-

import { asyncBrowserRoute, jsonError, toNumber, toStringOrEmpty } from "./utils.js";

15+

import { asyncBrowserRoute, jsonError, toStringOrEmpty } from "./utils.js";

1416
1517

function buildDownloadRequestBase(cdpUrl: string, targetId: string, timeoutMs: number | undefined) {

1618

return {

@@ -30,7 +32,12 @@ export function registerBrowserAgentActDownloadRoutes(

3032

const body = readBody(req);

3133

const targetId = resolveTargetIdFromBody(body);

3234

const out = toStringOrEmpty(body.path) || "";

33-

const timeoutMs = toNumber(body.timeoutMs);

35+

let timeoutMs: number | undefined;

36+

try {

37+

timeoutMs = readRoutePositiveInteger(body.timeoutMs, "timeoutMs");

38+

} catch (err) {

39+

return jsonError(res, 400, formatErrorMessage(err));

40+

}

3441
3542

await withRouteTabContext({

3643

req,

@@ -78,7 +85,12 @@ export function registerBrowserAgentActDownloadRoutes(

7885

const targetId = resolveTargetIdFromBody(body);

7986

const ref = toStringOrEmpty(body.ref);

8087

const out = toStringOrEmpty(body.path);

81-

const timeoutMs = toNumber(body.timeoutMs);

88+

let timeoutMs: number | undefined;

89+

try {

90+

timeoutMs = readRoutePositiveInteger(body.timeoutMs, "timeoutMs");

91+

} catch (err) {

92+

return jsonError(res, 400, formatErrorMessage(err));

93+

}

8294

if (!ref) {

8395

return jsonError(res, 400, "ref is required");

8496

}

Original file line numberDiff line numberDiff line change

@@ -1,3 +1,4 @@

1+

import { formatErrorMessage } from "../../infra/errors.js";

12

import { evaluateChromeMcpScript, uploadChromeMcpFile } from "../chrome-mcp.js";

23

import { getBrowserProfileCapabilities } from "../profile-capabilities.js";

34

import type { BrowserRouteContext } from "../server-context.js";

@@ -9,12 +10,12 @@ import {

910

} from "./agent.shared.js";

1011

import { EXISTING_SESSION_LIMITS } from "./existing-session-limits.js";

1112

import { DEFAULT_UPLOAD_DIR, pathScope } from "./path-output.js";

13+

import { readRoutePositiveInteger } from "./route-numeric.js";

1214

import type { BrowserRouteRegistrar } from "./types.js";

1315

import {

1416

asyncBrowserRoute,

1517

jsonError,

1618

toBoolean,

17-

toNumber,

1819

toStringArray,

1920

toStringOrEmpty,

2021

} from "./utils.js";

@@ -32,7 +33,12 @@ export function registerBrowserAgentActHookRoutes(

3233

const inputRef = toStringOrEmpty(body.inputRef) || undefined;

3334

const element = toStringOrEmpty(body.element) || undefined;

3435

const paths = toStringArray(body.paths) ?? [];

35-

const timeoutMs = toNumber(body.timeoutMs);

36+

let timeoutMs: number | undefined;

37+

try {

38+

timeoutMs = readRoutePositiveInteger(body.timeoutMs, "timeoutMs");

39+

} catch (err) {

40+

return jsonError(res, 400, formatErrorMessage(err));

41+

}

3642

if (!paths.length) {

3743

return jsonError(res, 400, "paths are required");

3844

}

@@ -118,7 +124,12 @@ export function registerBrowserAgentActHookRoutes(

118124

const targetId = resolveTargetIdFromBody(body);

119125

const accept = toBoolean(body.accept);

120126

const promptText = toStringOrEmpty(body.promptText) || undefined;

121-

const timeoutMs = toNumber(body.timeoutMs);

127+

let timeoutMs: number | undefined;

128+

try {

129+

timeoutMs = readRoutePositiveInteger(body.timeoutMs, "timeoutMs");

130+

} catch (err) {

131+

return jsonError(res, 400, formatErrorMessage(err));

132+

}

122133

const dialogId = toStringOrEmpty(body.dialogId) || undefined;

123134

if (accept === undefined) {

124135

return jsonError(res, 400, "accept is required");

Original file line numberDiff line numberDiff line change

@@ -1,4 +1,3 @@

1-

import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";

21

import { formatErrorMessage } from "../../infra/errors.js";

32

import {

43

clickChromeMcpElement,

@@ -41,6 +40,7 @@ import {

4140

} from "./agent.shared.js";

4241

import { resolveTargetIdAfterNavigate } from "./agent.snapshot-target.js";

4342

import { EXISTING_SESSION_LIMITS } from "./existing-session-limits.js";

43+

import { readRoutePositiveInteger } from "./route-numeric.js";

4444

import type { BrowserRouteRegistrar } from "./types.js";

4545

import { asyncBrowserRoute, jsonError, toStringOrEmpty } from "./utils.js";

4646

@@ -348,14 +348,6 @@ function getExistingSessionUnsupportedMessage(action: BrowserActRequest): string

348348

throw new Error("Unsupported browser act kind");

349349

}

350350
351-

function readRoutePositiveInteger(value: unknown, fieldName: string): number | undefined {

352-

const parsed = parseStrictPositiveInteger(value);

353-

if (parsed === undefined && value != null) {

354-

throw new Error(`${fieldName} must be a positive integer.`);

355-

}

356-

return parsed;

357-

}

358-
359351

export function registerBrowserAgentActRoutes(

360352

app: BrowserRouteRegistrar,

361353

ctx: BrowserRouteContext,

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,9 @@

1+

import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";

2+
3+

export function readRoutePositiveInteger(value: unknown, fieldName: string): number | undefined {

4+

const parsed = parseStrictPositiveInteger(value);

5+

if (parsed === undefined && value != null) {

6+

throw new Error(`${fieldName} must be a positive integer.`);

7+

}

8+

return parsed;

9+

}

Original file line numberDiff line numberDiff line change

@@ -472,6 +472,44 @@ describe("browser control server", () => {

472472

expect(pwMocks.responseBodyViaPlaywright).toHaveBeenCalledTimes(beforeCalls);

473473

});

474474
475+

it("rejects loose hook and download timeout options before dispatch", async () => {

476+

const base = await startServerAndBase();

477+

const uploadCalls = pwMocks.armFileUploadViaPlaywright.mock.calls.length;

478+

const dialogCalls = pwMocks.armDialogViaPlaywright.mock.calls.length;

479+

const waitCalls = pwMocks.waitForDownloadViaPlaywright.mock.calls.length;

480+

const downloadCalls = pwMocks.downloadViaPlaywright.mock.calls.length;

481+
482+

const uploadRes = await postJson<{ error?: string }>(`${base}/hooks/file-chooser`, {

483+

paths: ["a.txt"],

484+

timeoutMs: "1e3",

485+

});

486+

expect(uploadRes.error).toContain("timeoutMs must be a positive integer.");

487+
488+

const dialogRes = await postJson<{ error?: string }>(`${base}/hooks/dialog`, {

489+

accept: true,

490+

timeoutMs: "0x10",

491+

});

492+

expect(dialogRes.error).toContain("timeoutMs must be a positive integer.");

493+
494+

const waitRes = await postJson<{ error?: string }>(`${base}/wait/download`, {

495+

path: "report.pdf",

496+

timeoutMs: "1000ms",

497+

});

498+

expect(waitRes.error).toContain("timeoutMs must be a positive integer.");

499+
500+

const downloadRes = await postJson<{ error?: string }>(`${base}/download`, {

501+

ref: "e12",

502+

path: "report.pdf",

503+

timeoutMs: "1.5",

504+

});

505+

expect(downloadRes.error).toContain("timeoutMs must be a positive integer.");

506+
507+

expect(pwMocks.armFileUploadViaPlaywright).toHaveBeenCalledTimes(uploadCalls);

508+

expect(pwMocks.armDialogViaPlaywright).toHaveBeenCalledTimes(dialogCalls);

509+

expect(pwMocks.waitForDownloadViaPlaywright).toHaveBeenCalledTimes(waitCalls);

510+

expect(pwMocks.downloadViaPlaywright).toHaveBeenCalledTimes(downloadCalls);

511+

});

512+
475513

it("agent contract: hooks + response + downloads + screenshot", async () => {

476514

const base = await startServerAndBase();

477515