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

推荐订阅源

Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
L
LangChain Blog
I
InfoQ
D
Docker
F
Fortinet All Blogs
Y
Y Combinator Blog
Martin Fowler
Martin Fowler
月光博客
月光博客
B
Blog
Engineering at Meta
Engineering at Meta
T
Tailwind CSS Blog
罗磊的独立博客
博客园_首页
G
Google Developers Blog
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
D
DataBreaches.Net
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog RSS Feed
IT之家
IT之家
V
V2EX

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
Highlight exec command risks in Web approvals (#77153) · ...
jesse-merhi · 2026-05-08 · via Recent Commits to openclaw:main

@@ -4,21 +4,53 @@ import {

44

DEFAULT_APPROVAL_TIMEOUT_MS,

55

} from "./bash-tools.exec-runtime.js";

667+

const commandExplainerMock = vi.hoisted(() => ({

8+

importCount: 0,

9+

explainShellCommand: vi.fn(async (command: string): Promise<string> => command),

10+

formatCommandSpans: vi.fn((command: string) => {

11+

if (command.startsWith("node ")) {

12+

return [{ startIndex: 0, endIndex: 4 }];

13+

}

14+

return [

15+

{ startIndex: 0, endIndex: 2 },

16+

{ startIndex: 0, endIndex: 4 },

17+

{ startIndex: 5, endIndex: 9 },

18+

{ startIndex: 20, endIndex: 26 },

19+

];

20+

}),

21+

}));

22+23+

vi.mock("../infra/command-explainer/index.js", () => {

24+

commandExplainerMock.importCount += 1;

25+

return {

26+

explainShellCommand: commandExplainerMock.explainShellCommand,

27+

formatCommandSpans: commandExplainerMock.formatCommandSpans,

28+

};

29+

});

30+731

vi.mock("./tools/gateway.js", () => ({

832

callGatewayTool: vi.fn(),

933

}));

10341135

let callGatewayTool: typeof import("./tools/gateway.js").callGatewayTool;

1236

let requestExecApprovalDecision: typeof import("./bash-tools.exec-approval-request.js").requestExecApprovalDecision;

37+

let registerExecApprovalRequestForHost: typeof import("./bash-tools.exec-approval-request.js").registerExecApprovalRequestForHost;

13381439

describe("requestExecApprovalDecision", () => {

1540

beforeAll(async () => {

1641

({ callGatewayTool } = await import("./tools/gateway.js"));

17-

({ requestExecApprovalDecision } = await import("./bash-tools.exec-approval-request.js"));

42+

({ requestExecApprovalDecision, registerExecApprovalRequestForHost } =

43+

await import("./bash-tools.exec-approval-request.js"));

1844

});

19452046

beforeEach(() => {

2147

vi.mocked(callGatewayTool).mockClear();

48+

commandExplainerMock.explainShellCommand.mockClear();

49+

commandExplainerMock.formatCommandSpans.mockClear();

50+

});

51+52+

it("does not load the command explainer when importing approval requests", () => {

53+

expect(commandExplainerMock.importCount).toBe(0);

2254

});

23552456

it("returns string decisions", async () => {

@@ -174,4 +206,79 @@ describe("requestExecApprovalDecision", () => {

174206

expect(result).toBe("deny");

175207

expect(vi.mocked(callGatewayTool).mock.calls).toHaveLength(1);

176208

});

209+210+

it("adds command spans to host approval registration payloads", async () => {

211+

vi.mocked(callGatewayTool).mockResolvedValue({ id: "approval-id", expiresAtMs: 1234 });

212+213+

await registerExecApprovalRequestForHost({

214+

approvalId: "approval-id",

215+

command: 'ls | grep "stuff" | python -c \'print("hi")\'',

216+

workdir: "/tmp/project",

217+

host: "node",

218+

security: "allowlist",

219+

ask: "always",

220+

});

221+222+

expect(callGatewayTool).toHaveBeenCalledWith(

223+

"exec.approval.request",

224+

expect.anything(),

225+

expect.objectContaining({

226+

commandSpans: expect.arrayContaining([

227+

{ startIndex: 0, endIndex: 2 },

228+

{ startIndex: 5, endIndex: 9 },

229+

{ startIndex: 20, endIndex: 26 },

230+

]),

231+

}),

232+

expect.anything(),

233+

);

234+

});

235+236+

it("uses system run plan command text for host approval explanations", async () => {

237+

vi.mocked(callGatewayTool).mockResolvedValue({ id: "approval-id", expiresAtMs: 1234 });

238+239+

await registerExecApprovalRequestForHost({

240+

approvalId: "approval-id",

241+

systemRunPlan: {

242+

argv: ["node", "-e", "console.log(1)"],

243+

cwd: "/tmp/project",

244+

commandText: 'node -e "console.log(1)"',

245+

agentId: null,

246+

sessionKey: null,

247+

},

248+

workdir: "/tmp/project",

249+

host: "node",

250+

security: "allowlist",

251+

ask: "always",

252+

});

253+254+

expect(callGatewayTool).toHaveBeenCalledWith(

255+

"exec.approval.request",

256+

expect.anything(),

257+

expect.objectContaining({

258+

commandSpans: expect.arrayContaining([{ startIndex: 0, endIndex: 4 }]),

259+

}),

260+

expect.anything(),

261+

);

262+

});

263+264+

it("keeps explicit command spans", async () => {

265+

vi.mocked(callGatewayTool).mockResolvedValue({ id: "approval-id", expiresAtMs: 1234 });

266+267+

await registerExecApprovalRequestForHost({

268+

approvalId: "approval-id",

269+

command: "echo hi",

270+

commandSpans: [{ startIndex: 0, endIndex: 4 }],

271+

workdir: "/tmp/project",

272+

host: "node",

273+

security: "allowlist",

274+

ask: "always",

275+

});

276+277+

expect(callGatewayTool).toHaveBeenCalledWith(

278+

"exec.approval.request",

279+

expect.anything(),

280+

expect.objectContaining({ commandSpans: [{ startIndex: 0, endIndex: 4 }] }),

281+

expect.anything(),

282+

);

283+

});

177284

});