Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(auto-review): splatting(@params)按不可证处理,已看见的目标也不再当可信
Chrisf8f6e4ee1310
diff --git a/packages/maker-core/src/agents/shared/auto-review.test.ts b/packages/maker-core/src/agents/shared/auto-review.test.tsindex 5e1e67f1ff..c1e599d661 100644--- a/packages/maker-core/src/agents/shared/auto-review.test.ts+++ b/packages/maker-core/src/agents/shared/auto-review.test.ts@@ -2529,6 +2529,47 @@ describe('参数形式的系统路径写入 / setsid 选项(第三十五批评.toBe('prompt-each-time');});+ it('splatting(@params)把任意具名参数摊进来 → 整次抽取按不可证算', () => {+ // `@变量` 把一个 hashtable / 数组整体摊成实参。它比变量、表达式、通配符更彻底地废掉静态+ // 判定:摊进来的是**任意具名参数,包括 `-Path` 本身**。原先谓词只认数组表达式 `@(…)`,+ // `@p` 既不含 `$` 也不以 `(` 开头,于是被当成普通相对路径拼进工作区(codex 报)。+ const win = ['C:\\repo'];+ for (const c of [+ 'Set-Content @p',+ 'Set-Content @params',+ 'Set-Content @PSBoundParameters',+ 'Remove-Item @p',+ 'Copy-Item @p',+ 'Out-File @p',+ 'Set-ItemProperty @p',+ 'Move-Item @splat',+ 'Rename-Item @p',+ 'New-Item @{Path="C:\\Windows\\x"}', // hashtable 字面量+ 'Set-Content @p owned', // splat + 位置参数混用+ 'Copy-Item C:\\repo\\a @p', // splat 在目标侧+ // **关键**:命令行里已经有一个看得见的安全目标也不能信 —— `@p` 可以再带一个 `-Path`。+ // 所以判据是"整次抽取不可证",不是"忽略这个 token、拿剩下的判"。+ 'Set-Content -Path C:\\repo\\a.txt @p',+ 'Copy-Item -Path C:\\repo\\a -Destination C:\\repo\\b @p',+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt-each-time');+ }++ // 反例一:`@` 出现在 token **中间**是合法文件名的一部分,不是 splat。+ expect(classifyShellCommand('Set-Content "C:\\repo\\[email protected]" hi', win, { platform: 'win32' }))+ .toBe('prompt');+ expect(classifyShellCommand('Set-Content C:\\repo\\a@b\\c.txt hi', win, { platform: 'win32' }))+ .toBe('prompt');+ // 反例二:只读 cmdlet 不在写目标表里,splat 不会把它拖进写通道判定。+ expect(classifyShellCommand('Get-Content @p', win, { platform: 'win32' })).toBe('prompt');+ // 反例三:普通目标判档不变(这条只针对"证明不了")。+ expect(classifyShellCommand('Set-Content C:\\repo\\a.txt hi', win, { platform: 'win32' })).toBe('prompt');+ expect(classifyShellCommand('Set-Content C:\\repo\\build\\* x', win, { platform: 'win32' })).toBe('prompt');+ expect(classifyShellCommand(+ 'Set-Content C:\\Windows\\System32\\drivers\\etc\\hosts owned', win, { platform: 'win32' },+ )).toBe('prompt-each-time');+ });+it('iex 是把 stdin 当程序的执行器:`| iex` 落在外层 shell 也命中下载即执行', () => {// `pwsh -Command 'iwr https://…/a.ps1' | iex`:`| iex` 在**外层**,顶层分段把它切成独立一段。// 于是两段各自都不红 —— payload 那段只有 `iwr`(单纯下载不是红线),`iex` 那段 tokens[0] 不是diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.tsindex aad42c55a6..82daf07f08 100644--- a/packages/maker-core/src/agents/shared/auto-review.ts+++ b/packages/maker-core/src/agents/shared/auto-review.ts@@ -519,6 +519,23 @@ function isPowerShellExpressionToken(token: string): boolean {return opens !== closes || token.includes('::') || /[)\]]$/.test(token);}+/**+ * **splatting**:`Set-Content @params` —— `@变量` 把一个 hashtable / 数组整体摊成实参。+ *+ * 它比前面那些形态更彻底地废掉静态判定:摊进来的是**任意具名参数**,包括 `-Path` 本身。+ * 所以哪怕命令行里已经有一个看得见的安全目标也不能信 ——+ * `Set-Content -Path C:\repo\a.txt @p` 里的 `@p` 可以带上另一个 `-Path`(实测原先落 prompt)。+ * 因此只要出现 splat,整次抽取按不可证算,而不是"忽略这个 token、用剩下的判"。+ *+ * 只认 `@` 紧跟标识符或 `{`(hashtable 字面量);`@(` 是数组子表达式,由+ * `isPowerShellExpressionToken` 管。`@` 出现在 token **中间**的不算 —— `C:\repo\[email protected]`+ * 是个合法文件名(已断言不被误升级)。+ *+ * 已知代价:真有一个字面以 `@` 开头的文件名(`@foo.txt`)会多问一次。PowerShell 里这种名字+ * 本来就得引号包着才不会被当 splat,方向是多问、不放宽。+ */+const POWERSHELL_SPLAT_TOKEN = /^@[A-Za-z_{]/;+/*** PowerShell 写 cmdlet 的写目标。既支持具名参数(`-Path` / `-LiteralPath` / `-Destination` /* `-FilePath`,含唯一前缀缩写如 `-Dest`),也支持位置传参。@@ -540,8 +557,11 @@ function isPowerShellExpressionToken(token: string): boolean {function powerShellWriteTargets(bin: string, args: string[]): string[] | null {const targets = powerShellWriteTargetOperands(bin, args);if (targets === null) return null;- // 表达式参数会让位置模型整体失效(见 isPowerShellExpressionToken)→ 整次抽取按不可证算。- if (args.some(isPowerShellExpressionToken)) return [UNPROVABLE_WRITE_TARGET];+ // 表达式参数会让位置模型整体失效(见 isPowerShellExpressionToken),splatting 更进一步 ——+ // 它能摊出任意具名参数(含 `-Path` 本身),连"已经看见的目标"都不可信。两者都按不可证算。+ if (args.some((t) => isPowerShellExpressionToken(t) || POWERSHELL_SPLAT_TOKEN.test(t))) {+ return [UNPROVABLE_WRITE_TARGET];+ }return targets.map((t) => {// 通配符标记要先去掉再查 `$`:两者可以同时出现(`"$env:windir\*"`),动态优先(更保守)。return POWERSHELL_DYNAMIC_TARGET.test(stripGlobWriteMarker(t)) ? UNPROVABLE_WRITE_TARGET : t;