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

推荐订阅源

MyScale Blog
MyScale Blog
F
Fortinet All Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
V
Visual Studio Blog
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
L
LangChain Blog
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
IT之家
IT之家
P
Proofpoint News Feed
博客园_首页
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Check Point Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure 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: validate literal tilde exec scripts · openclaw/openc...
shakkernerd · 2026-05-12 · via Recent Commits to openclaw:main

@@ -1,3 +1,5 @@

1+

import { constants as fsConstants } from "node:fs";

2+

import fs from "node:fs/promises";

13

import path from "node:path";

24

import type { AgentToolResult } from "@earendil-works/pi-agent-core";

35

import { buildCommandPayloadCandidates } from "../infra/command-analysis/risks.js";

@@ -113,6 +115,12 @@ const SKIPPABLE_SCRIPT_PREFLIGHT_FS_ERROR_CODES = new Set([

113115

"ENOTDIR",

114116

"EPERM",

115117

]);

118+

const SCRIPT_PREFLIGHT_MAX_BYTES = 512 * 1024;

119+

const FS_CONSTANTS_WITH_OPTIONAL_NONBLOCK = fsConstants as typeof fsConstants & {

120+

O_NONBLOCK?: number;

121+

};

122+

const SCRIPT_PREFLIGHT_OPEN_FLAGS =

123+

fsConstants.O_RDONLY | (FS_CONSTANTS_WITH_OPTIONAL_NONBLOCK.O_NONBLOCK ?? 0);

116124117125

function getNodeErrorCode(error: unknown): string | undefined {

118126

if (typeof error !== "object" || error === null || !("code" in error)) {

@@ -149,9 +157,46 @@ function resolvePreflightRelativePath(params: { rootDir: string; absPath: string

149157

if (/^\.\.(?:[\\/]|$)/u.test(relative) || path.isAbsolute(relative)) {

150158

return null;

151159

}

152-

// Preserve literal "~" path segments under the workdir. Root reads

153-

// expand home prefixes for relative paths, so normalize `~/...` to `./~/...`.

154-

return /^~(?:$|[\\/])/u.test(relative) ? `.${path.sep}${relative}` : relative;

160+

return relative;

161+

}

162+163+

function hasLeadingTildePathSegment(relativePath: string): boolean {

164+

return /^~(?:$|[\\/])/u.test(relativePath);

165+

}

166+167+

async function readLiteralTildePreflightScript(params: {

168+

absPath: string;

169+

fsSafe: FsSafeModule;

170+

workspaceRoot: Awaited<ReturnType<FsSafeModule["root"]>>;

171+

}): Promise<string> {

172+

let handle: fs.FileHandle | undefined;

173+

try {

174+

handle = await fs.open(params.absPath, SCRIPT_PREFLIGHT_OPEN_FLAGS);

175+

const stat = await handle.stat();

176+

if (!stat.isFile()) {

177+

throw new params.fsSafe.FsSafeError("not-file", "not a file");

178+

}

179+

if (stat.size > SCRIPT_PREFLIGHT_MAX_BYTES) {

180+

throw new params.fsSafe.FsSafeError(

181+

"too-large",

182+

`file exceeds limit of ${SCRIPT_PREFLIGHT_MAX_BYTES} bytes (got ${stat.size})`,

183+

);

184+

}

185+

const realPath = await params.fsSafe.resolveOpenedFileRealPathForHandle(handle, params.absPath);

186+

if (!params.fsSafe.isPathInside(params.workspaceRoot.rootReal, realPath)) {

187+

throw new params.fsSafe.FsSafeError("outside-workspace", "file is outside workspace root");

188+

}

189+

const buffer = await handle.readFile();

190+

if (buffer.byteLength > SCRIPT_PREFLIGHT_MAX_BYTES) {

191+

throw new params.fsSafe.FsSafeError(

192+

"too-large",

193+

`file exceeds limit of ${SCRIPT_PREFLIGHT_MAX_BYTES} bytes (got ${buffer.byteLength})`,

194+

);

195+

}

196+

return buffer.toString("utf-8");

197+

} finally {

198+

await handle?.close().catch(() => undefined);

199+

}

155200

}

156201157202

function isShellEnvAssignmentToken(token: string): boolean {

@@ -967,7 +1012,8 @@ async function validateScriptFileForShellBleed(params: {

9671012

return;

9681013

}

9691014970-

const { FsSafeError, root: fsRoot } = await loadFsSafeModule();

1015+

const fsSafe = await loadFsSafeModule();

1016+

const { FsSafeError, root: fsRoot } = fsSafe;

9711017

const workspaceRoot = await fsRoot(params.workdir);

9721018

for (const relOrAbsPath of target.relOrAbsPaths) {

9731019

const absPath = path.isAbsolute(relOrAbsPath)

@@ -987,12 +1033,19 @@ async function validateScriptFileForShellBleed(params: {

9871033

// Use non-blocking open to avoid stalls if a path is swapped to a FIFO.

9881034

let content: string;

9891035

try {

990-

const safeRead = await workspaceRoot.read(relativePath, {

991-

nonBlockingRead: true,

992-

symlinks: "follow-within-root",

993-

maxBytes: 512 * 1024,

994-

});

995-

content = safeRead.buffer.toString("utf-8");

1036+

content = hasLeadingTildePathSegment(relativePath)

1037+

? await readLiteralTildePreflightScript({

1038+

absPath,

1039+

fsSafe,

1040+

workspaceRoot,

1041+

})

1042+

: (

1043+

await workspaceRoot.read(relativePath, {

1044+

nonBlockingRead: true,

1045+

symlinks: "follow-within-root",

1046+

maxBytes: SCRIPT_PREFLIGHT_MAX_BYTES,

1047+

})

1048+

).buffer.toString("utf-8");

9961049

} catch (error) {

9971050

if (shouldSkipScriptPreflightPathError(error, FsSafeError)) {

9981051

// Preflight validation is best-effort: skip path/read failures and