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

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
Recent Announcements
Recent Announcements
V
Visual Studio Blog
博客园 - 叶小钗
H
Help Net Security
aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
U
Unit 42
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Fortinet All Blogs
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
D
DataBreaches.Net
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
A
About on SuperTechFans
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
C
Check Point Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
Microsoft Azure Blog
Microsoft Azure Blog
M
MIT News - Artificial intelligence

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
Harden Windows command wrapper resolution (#77472) · open...
drobison00 · 2026-05-05 · via Recent Commits to openclaw:main

@@ -3,6 +3,10 @@ import { EventEmitter } from "node:events";

33

import fs from "node:fs";

44

import path from "node:path";

55

import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";

6+

import {

7+

_resetWindowsInstallRootsForTests,

8+

getWindowsInstallRoots,

9+

} from "../infra/windows-install-roots.js";

610711

const { spawnMock, spawnSyncMock, execFileMock, execFilePromisifyMock } = vi.hoisted(() => {

812

const execFilePromisifyMock = vi.fn();

@@ -101,6 +105,10 @@ function expectCmdWrappedInvocation(params: {

101105

expect(params.captured[2].windowsVerbatimArguments).toBe(true);

102106

}

103107108+

function expectedTrustedCmdExe(): string {

109+

return path.win32.join(getWindowsInstallRoots().systemRoot, "System32", "cmd.exe");

110+

}

111+104112

async function expectShimmedWindowsCommandWithoutExitCodeSucceeds(params?: { killed?: boolean }) {

105113

const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");

106114

const child = createMockChild({

@@ -127,6 +135,10 @@ describe("windows command wrapper behavior", () => {

127135

});

128136129137

beforeEach(() => {

138+

// Stub the registry probe so install-root resolution is fully driven by

139+

// process.env in tests; on real Windows runners the registry returns the

140+

// canonical SystemRoot and would shadow the test's env setup.

141+

_resetWindowsInstallRootsForTests({ queryRegistryValue: () => null });

130142

spawnMock.mockReset();

131143

spawnSyncMock.mockReset();

132144

spawnSyncMock.mockReturnValue({ stdout: "Active code page: 936", stderr: "" });

@@ -157,7 +169,7 @@ describe("windows command wrapper behavior", () => {

157169158170

it("wraps .cmd commands via cmd.exe in runCommandWithTimeout", async () => {

159171

const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");

160-

const expectedComSpec = process.env.ComSpec ?? "cmd.exe";

172+

const expectedComSpec = expectedTrustedCmdExe();

161173162174

spawnMock.mockImplementation(

163175

(_command: string, _args: string[], _options: Record<string, unknown>) => createMockChild(),

@@ -173,9 +185,91 @@ describe("windows command wrapper behavior", () => {

173185

}

174186

});

175187188+

it("ignores ComSpec when selecting the Windows command wrapper", async () => {

189+

const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");

190+

const previousComSpec = process.env.ComSpec;

191+

const previousSystemRoot = process.env.SystemRoot;

192+

process.env.ComSpec = "C:\\workspace\\evil\\cmd.exe";

193+

process.env.SystemRoot = "C:\\Windows";

194+195+

spawnMock.mockImplementation(

196+

(_command: string, _args: string[], _options: Record<string, unknown>) => createMockChild(),

197+

);

198+199+

try {

200+

const result = await runCommandWithTimeout(["pnpm", "--version"], { timeoutMs: 1000 });

201+

expect(result.code).toBe(0);

202+

const captured = spawnMock.mock.calls[0] as SpawnCall | undefined;

203+

expectCmdWrappedInvocation({

204+

captured,

205+

expectedComSpec: path.win32.join("C:\\Windows", "System32", "cmd.exe"),

206+

});

207+

} finally {

208+

if (previousComSpec === undefined) {

209+

delete process.env.ComSpec;

210+

} else {

211+

process.env.ComSpec = previousComSpec;

212+

}

213+

if (previousSystemRoot === undefined) {

214+

delete process.env.SystemRoot;

215+

} else {

216+

process.env.SystemRoot = previousSystemRoot;

217+

}

218+

platformSpy.mockRestore();

219+

}

220+

});

221+222+

it("rejects unsafe Windows root values when selecting the command wrapper", async () => {

223+

const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");

224+

const previousSystemRoot = process.env.SystemRoot;

225+

const previousWindir = process.env.WINDIR;

226+227+

spawnMock.mockImplementation(

228+

(_command: string, _args: string[], _options: Record<string, unknown>) => createMockChild(),

229+

);

230+231+

try {

232+

for (const unsafeRoot of [

233+

"\\\\evil\\share",

234+

"C:\\Windows;C:\\evil",

235+

"\\Windows",

236+

"relative\\path",

237+

]) {

238+

_resetWindowsInstallRootsForTests({ queryRegistryValue: () => null });

239+

// Set every install-root env source to the unsafe value so the

240+

// resolver rejects each one and falls through to the safe default.

241+

// Deleting WINDIR here is unreliable on real Windows runners, so

242+

// overwrite it with the same rejected payload.

243+

process.env.SystemRoot = unsafeRoot;

244+

process.env.WINDIR = unsafeRoot;

245+

spawnMock.mockClear();

246+247+

const result = await runCommandWithTimeout(["pnpm", "--version"], { timeoutMs: 1000 });

248+

expect(result.code).toBe(0);

249+

const captured = spawnMock.mock.calls[0] as SpawnCall | undefined;

250+

expectCmdWrappedInvocation({

251+

captured,

252+

expectedComSpec: path.win32.join("C:\\Windows", "System32", "cmd.exe"),

253+

});

254+

}

255+

} finally {

256+

if (previousSystemRoot === undefined) {

257+

delete process.env.SystemRoot;

258+

} else {

259+

process.env.SystemRoot = previousSystemRoot;

260+

}

261+

if (previousWindir === undefined) {

262+

delete process.env.WINDIR;

263+

} else {

264+

process.env.WINDIR = previousWindir;

265+

}

266+

platformSpy.mockRestore();

267+

}

268+

});

269+176270

it("wraps corepack.cmd via cmd.exe in runCommandWithTimeout", async () => {

177271

const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");

178-

const expectedComSpec = process.env.ComSpec ?? "cmd.exe";

272+

const expectedComSpec = expectedTrustedCmdExe();

179273180274

spawnMock.mockImplementation(

181275

(_command: string, _args: string[], _options: Record<string, unknown>) => createMockChild(),

@@ -243,7 +337,7 @@ describe("windows command wrapper behavior", () => {

243337

it("falls back to npm.cmd when npm-cli.js is unavailable", async () => {

244338

const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");

245339

const existsSpy = vi.spyOn(fs, "existsSync").mockReturnValue(false);

246-

const expectedComSpec = process.env.ComSpec ?? "cmd.exe";

340+

const expectedComSpec = expectedTrustedCmdExe();

247341248342

spawnMock.mockImplementation(

249343

(_command: string, _args: string[], _options: Record<string, unknown>) => createMockChild(),

@@ -297,7 +391,7 @@ describe("windows command wrapper behavior", () => {

297391298392

it("uses cmd.exe wrapper with windowsVerbatimArguments in runExec for .cmd shims", async () => {

299393

const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");

300-

const expectedComSpec = process.env.ComSpec ?? "cmd.exe";

394+

const expectedComSpec = expectedTrustedCmdExe();

301395302396

execFileMock.mockImplementation(

303397

(