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

推荐订阅源

H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
爱范儿
爱范儿
L
LangChain Blog
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog
G
Google Developers Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

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(exec-approvals): guard Windows rename fallback (#7790...
Alex-Alaniz · 2026-05-06 · via Recent Commits to openclaw:main

@@ -79,6 +79,14 @@ function readApprovalsFile(homeDir: string): ExecApprovalsFile {

7979

return JSON.parse(fs.readFileSync(approvalsFilePath(homeDir), "utf8")) as ExecApprovalsFile;

8080

}

818182+

function listExecApprovalTempFiles(homeDir: string): string[] {

83+

const dir = path.dirname(approvalsFilePath(homeDir));

84+

if (!fs.existsSync(dir)) {

85+

return [];

86+

}

87+

return fs.readdirSync(dir).filter((name) => name.endsWith(".tmp"));

88+

}

89+8290

describe("exec approvals store helpers", () => {

8391

it("expands home-prefixed default file and socket paths", () => {

8492

const dir = createHomeDir();

@@ -173,6 +181,189 @@ describe("exec approvals store helpers", () => {

173181

expect(fs.statSync(approvalsPath).ino).not.toBe(fs.statSync(linkedPath).ino);

174182

});

175183184+

it("normalizes successful rename writes to owner-only permissions", () => {

185+

const dir = createHomeDir();

186+

const actualWriteFileSync = fs.writeFileSync.bind(fs);

187+

vi.spyOn(fs, "writeFileSync").mockImplementation((file, data, options) => {

188+

const result = actualWriteFileSync(file, data, options as never);

189+

const filePath = String(file);

190+

if (

191+

typeof file !== "number" &&

192+

filePath.includes(".exec-approvals.") &&

193+

filePath.endsWith(".tmp")

194+

) {

195+

fs.chmodSync(file, 0o000);

196+

}

197+

return result;

198+

});

199+200+

saveExecApprovals({ version: 1, defaults: { security: "full" }, agents: {} });

201+202+

expect(fs.readFileSync(approvalsFilePath(dir), "utf8")).toContain('"security": "full"');

203+

expect(fs.statSync(approvalsFilePath(dir)).mode & 0o777).toBe(0o600);

204+

});

205+206+

it("normalizes the approvals directory to owner-only permissions", () => {

207+

const dir = createHomeDir();

208+

const approvalsDir = path.dirname(approvalsFilePath(dir));

209+

fs.mkdirSync(approvalsDir, { recursive: true });

210+

fs.chmodSync(approvalsDir, 0o777);

211+212+

saveExecApprovals({ version: 1, defaults: { security: "full" }, agents: {} });

213+214+

expect(fs.readFileSync(approvalsFilePath(dir), "utf8")).toContain('"security": "full"');

215+

expect(fs.statSync(approvalsDir).mode & 0o777).toBe(0o700);

216+

});

217+218+

it("falls back to copying when rename cannot overwrite the approvals file", () => {

219+

const dir = createHomeDir();

220+

const approvalsPath = approvalsFilePath(dir);

221+

fs.mkdirSync(path.dirname(approvalsPath), { recursive: true });

222+

fs.writeFileSync(approvalsPath, '{"version":1,"agents":{}}\n', "utf8");

223+

const actualRenameSync = fs.renameSync.bind(fs);

224+

const rename = vi.spyOn(fs, "renameSync").mockImplementation((from, to) => {

225+

if (String(to) === approvalsPath) {

226+

const error = Object.assign(new Error("locked target"), { code: "EPERM" });

227+

throw error;

228+

}

229+

return actualRenameSync(from, to);

230+

});

231+232+

saveExecApprovals({ version: 1, defaults: { security: "full" }, agents: {} });

233+234+

expect(rename).toHaveBeenCalled();

235+

expect(fs.readFileSync(approvalsPath, "utf8")).toContain('"security": "full"');

236+

expect(fs.statSync(approvalsPath).mode & 0o777).toBe(0o600);

237+

expect(listExecApprovalTempFiles(dir)).toEqual([]);

238+

});

239+240+

it("normalizes fallback temp files before copying", () => {

241+

const dir = createHomeDir();

242+

const approvalsPath = approvalsFilePath(dir);

243+

fs.mkdirSync(path.dirname(approvalsPath), { recursive: true });

244+

fs.writeFileSync(approvalsPath, '{"version":1,"agents":{}}\n', "utf8");

245+

const actualWriteFileSync = fs.writeFileSync.bind(fs);

246+

vi.spyOn(fs, "writeFileSync").mockImplementation((file, data, options) => {

247+

const result = actualWriteFileSync(file, data, options as never);

248+

const filePath = String(file);

249+

if (

250+

typeof file !== "number" &&

251+

filePath.includes(".exec-approvals.") &&

252+

filePath.endsWith(".tmp")

253+

) {

254+

fs.chmodSync(file, 0o000);

255+

}

256+

return result;

257+

});

258+

const actualRenameSync = fs.renameSync.bind(fs);

259+

vi.spyOn(fs, "renameSync").mockImplementation((from, to) => {

260+

if (String(to) === approvalsPath) {

261+

const error = Object.assign(new Error("locked target"), { code: "EPERM" });

262+

throw error;

263+

}

264+

return actualRenameSync(from, to);

265+

});

266+267+

saveExecApprovals({ version: 1, defaults: { security: "full" }, agents: {} });

268+269+

expect(fs.readFileSync(approvalsPath, "utf8")).toContain('"security": "full"');

270+

expect(fs.statSync(approvalsPath).mode & 0o777).toBe(0o600);

271+

expect(listExecApprovalTempFiles(dir)).toEqual([]);

272+

});

273+274+

it("restores the previous approvals file when fallback copy fails", () => {

275+

const dir = createHomeDir();

276+

const approvalsPath = approvalsFilePath(dir);

277+

const previousRaw = '{"version":1,"defaults":{"security":"deny"},"agents":{}}\n';

278+

fs.mkdirSync(path.dirname(approvalsPath), { recursive: true });

279+

fs.writeFileSync(approvalsPath, previousRaw, { encoding: "utf8", mode: 0o600 });

280+

const actualRenameSync = fs.renameSync.bind(fs);

281+

vi.spyOn(fs, "renameSync").mockImplementation((from, to) => {

282+

if (String(to) === approvalsPath) {

283+

const error = Object.assign(new Error("locked target"), { code: "EPERM" });

284+

throw error;

285+

}

286+

return actualRenameSync(from, to);

287+

});

288+

const actualFtruncateSync = fs.ftruncateSync.bind(fs);

289+

let forcedFallbackFailure = false;

290+

vi.spyOn(fs, "ftruncateSync").mockImplementation((fd, len) => {

291+

if (!forcedFallbackFailure && len === 0) {

292+

forcedFallbackFailure = true;

293+

actualFtruncateSync(fd, len);

294+

const error = Object.assign(new Error("copy failed after opening destination"), {

295+

code: "ENOSPC",

296+

});

297+

throw error;

298+

}

299+

return actualFtruncateSync(fd, len);

300+

});

301+302+

expect(() =>

303+

saveExecApprovals({ version: 1, defaults: { security: "full" }, agents: {} }),

304+

).toThrow(/copy failed after opening destination/);

305+

expect(fs.readFileSync(approvalsPath, "utf8")).toBe(previousRaw);

306+

expect(fs.statSync(approvalsPath).mode & 0o777).toBe(0o600);

307+

expect(listExecApprovalTempFiles(dir)).toEqual([]);

308+

});

309+310+

it("does not follow a symlink swapped in before fallback copy", () => {

311+

const dir = createHomeDir();

312+

const approvalsPath = approvalsFilePath(dir);

313+

const targetPath = path.join(dir, "elsewhere.json");

314+

fs.mkdirSync(path.dirname(approvalsPath), { recursive: true });

315+

fs.writeFileSync(approvalsPath, '{"version":1,"agents":{}}\n', "utf8");

316+

fs.writeFileSync(targetPath, '{"sentinel":true}\n', "utf8");

317+

const actualRenameSync = fs.renameSync.bind(fs);

318+

vi.spyOn(fs, "renameSync").mockImplementation((from, to) => {

319+

if (String(to) === approvalsPath) {

320+

const error = Object.assign(new Error("locked target"), { code: "EPERM" });

321+

throw error;

322+

}

323+

return actualRenameSync(from, to);

324+

});

325+

const actualStatSync = fs.statSync.bind(fs);

326+

let swappedDestination = false;

327+

vi.spyOn(fs, "statSync").mockImplementation((file, options) => {

328+

const result = actualStatSync(file, options as never);

329+

if (!swappedDestination && String(file) === approvalsPath) {

330+

swappedDestination = true;

331+

fs.rmSync(approvalsPath);

332+

fs.symlinkSync(targetPath, approvalsPath);

333+

}

334+

return result;

335+

});

336+337+

expect(() =>

338+

saveExecApprovals({ version: 1, defaults: { security: "full" }, agents: {} }),

339+

).toThrow(/symlink|ELOOP/);

340+

expect(fs.readFileSync(targetPath, "utf8")).toBe('{"sentinel":true}\n');

341+

expect(listExecApprovalTempFiles(dir)).toEqual([]);

342+

});

343+344+

it("does not use the copy fallback for hard-linked approvals files", () => {

345+

const dir = createHomeDir();

346+

const approvalsPath = approvalsFilePath(dir);

347+

const linkedPath = path.join(dir, "linked.json");

348+

fs.mkdirSync(path.dirname(approvalsPath), { recursive: true });

349+

fs.writeFileSync(linkedPath, '{"sentinel":true}\n', "utf8");

350+

fs.linkSync(linkedPath, approvalsPath);

351+

const actualRenameSync = fs.renameSync.bind(fs);

352+

vi.spyOn(fs, "renameSync").mockImplementation((from, to) => {

353+

if (String(to) === approvalsPath) {

354+

const error = Object.assign(new Error("locked target"), { code: "EPERM" });

355+

throw error;

356+

}

357+

return actualRenameSync(from, to);

358+

});

359+360+

expect(() =>

361+

saveExecApprovals({ version: 1, defaults: { security: "full" }, agents: {} }),

362+

).toThrow(/hard-linked exec approvals file/);

363+

expect(fs.readFileSync(linkedPath, "utf8")).toBe('{"sentinel":true}\n');

364+

expect(listExecApprovalTempFiles(dir)).toEqual([]);

365+

});

366+176367

it("refuses to write approvals through a symlink destination", () => {

177368

const dir = createHomeDir();

178369

const approvalsPath = approvalsFilePath(dir);