Skip to content

Commit 626fad0

Browse files
committed
fix(browser): enforce decimal extension wait values
1 parent 832ea75 commit 626fad0

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

‎extensions/browser/src/browser/extension-install.test.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,15 +1047,20 @@ describe("installer option bounds", () => {
10471047
it("accepts bounded waits and rejects unbounded waits", () => {
10481048
expect(normalizeExtensionInstallWaitMs(undefined)).toBe(30_000);
10491049
expect(normalizeExtensionInstallWaitMs("1000")).toBe(1_000);
1050+
expect(normalizeExtensionInstallWaitMs(10_000)).toBe(10_000);
1051+
expect(normalizeExtensionInstallWaitMs("120000")).toBe(120_000);
10501052
expect(() => normalizeExtensionInstallWaitMs(999)).toThrow("--wait-ms");
10511053
expect(() => normalizeExtensionInstallWaitMs(120_001)).toThrow("--wait-ms");
10521054
});
10531055

1054-
it("rejects non-decimal --wait-ms string coercions instead of silently accepting them", () => {
1055-
// Number("0x1000")===4096 and Number("1e4")===10000 would pass the old
1056-
// range check silently; the strict parser requires plain decimal integers.
1057-
expect(() => normalizeExtensionInstallWaitMs("0x1000")).toThrow("--wait-ms");
1058-
expect(() => normalizeExtensionInstallWaitMs("1e4")).toThrow("--wait-ms");
1056+
it.each(["0x1000", "1e4", "+50000", " 50000", "50000 ", "50000\t"])(
1057+
"rejects non-decimal --wait-ms string %j",
1058+
(value) => {
1059+
expect(() => normalizeExtensionInstallWaitMs(value)).toThrow("--wait-ms");
1060+
},
1061+
);
1062+
1063+
it("accepts ordinary decimal strings", () => {
10591064
expect(normalizeExtensionInstallWaitMs("10000")).toBe(10_000);
10601065
});
10611066
});

‎extensions/browser/src/browser/extension-install.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import crypto from "node:crypto";
22
import fs from "node:fs/promises";
33
import path from "node:path";
4-
import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";
54
import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
65
import {
76
assertOwnedPath,
@@ -382,9 +381,11 @@ export function normalizeExtensionInstallWaitMs(value: unknown): number {
382381
if (value === undefined) {
383382
return BROWSER_EXTENSION_INSTALL_WAIT_DEFAULT_MS;
384383
}
385-
const parsed = typeof value === "number" ? value : parseStrictPositiveInteger(value);
384+
const parsed =
385+
typeof value === "number" || (typeof value === "string" && /^\d+$/u.test(value))
386+
? Number(value)
387+
: Number.NaN;
386388
if (
387-
parsed === undefined ||
388389
!Number.isInteger(parsed) ||
389390
parsed < BROWSER_EXTENSION_INSTALL_WAIT_MIN_MS ||
390391
parsed > BROWSER_EXTENSION_INSTALL_WAIT_MAX_MS

‎extensions/browser/src/cli/browser-cli-extension.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,28 @@ describe("browser extension pairing Gateway URL", () => {
114114
expect(output.at(-1)).toContain("extension identity verified");
115115
});
116116

117+
it.each(["0x1000", "1e4", "+50000", " 50000", "50000 ", "50000\t"])(
118+
"rejects invalid install --wait-ms value %j before installation",
119+
async (value) => {
120+
const errorSpy = vi
121+
.spyOn(cliCoreApiModule.defaultRuntime, "error")
122+
.mockImplementation(runtime.error);
123+
vi.spyOn(cliCoreApiModule.defaultRuntime, "exit").mockImplementation(runtime.exit);
124+
const { registerBrowserExtensionCommands } = await import("./browser-cli-extension.js");
125+
const program = new Command();
126+
registerBrowserExtensionCommands(program.command("browser"), () => ({}));
127+
128+
await expect(
129+
program.parseAsync(["browser", "extension", "install", "--wait-ms", value], {
130+
from: "user",
131+
}),
132+
).rejects.toThrow("__exit__:1");
133+
134+
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining("--wait-ms"));
135+
expect(installMocks.installChromeExtensionBootstrap).not.toHaveBeenCalled();
136+
},
137+
);
138+
117139
it("rejects path-rewriting proxy prefixes for strict v2 resource binding", async () => {
118140
vi.spyOn(cliCoreApiModule, "getRuntimeConfig").mockReturnValue({});
119141
const errorSpy = vi

0 commit comments

Comments
 (0)