Repository navigation
Conversation
UnixCommandValidator/WindowsCommandValidator 只校验可执行名与
&/|/;分隔符,整串命令随后交给 sh -c / cmd.exe /c——白名单内的
echo 可经 $(...)、反引号、$VAR、重定向执行额外命令或写文件,
全程不经审批回调。
- Unix:新增 containsShellMetacharacters(引号感知):$/反引号在
单引号外即拒绝(双引号不阻断替换),>/<在两种引号外拒绝;
在 containsMultipleCommands 之后对所有白名单激活的命令生效,
命中即 rejected 并给出原因,进入既有审批回调路径
- Windows:新增同款检测(%VAR% 展开、>/< 重定向、^ 转义 smuggle),
cmd.exe 引词语义复杂,从严全量拒绝
- 白名单为空时全放行的既有行为保留:改为与文档声明的
"No whitelist - all commands require approval" 对齐属破坏性
变更,留给维护者决策(PR 描述中提出)
- 测试:plain/单引号字面量仍 ALLOW;$(...)/"$(...)"/反引号/
$VAR/${VAR}/>输入重定向/%VAR%/^ 全部 rejected
Fixes agentscope-ai#3285
|
Spotless violation on my pushed file (the server-side-constructed content skipped the local format pass — the standard step I keep re-learning). Fixed in 2a05779 (formatting only, verified the fix content is intact). Rerun should be green. |
|
Found it — my previous "spotless fix" push for this branch actually re-introduced the broken character literals in |
|
Both prior failures traced to one structural mistake of mine: the first patch inserted the new method between Separately: the 3d4c5a3 run for #3766 failed only in |
Fixes #3285
Problem
The validators checked the executable name and
&/|/;separators, but the whole string then runs undersh -c/cmd.exe /c. A whitelistedechocould execute additional commands or write files via$(...), backticks,$VAR/${...},%VAR%, or>/<redirection — never touching the approval callback.Fix
containsShellMetacharacters—$and backticks are rejected outside single quotes (double quotes do NOT neutralize substitution in sh),>/<outside both quote kinds. Applied after the separator check whenever a whitelist is active; hits arerejectedwith a reason, flowing into the existing approval path.%VAR%,>/<, and^(cmd.exe quote-stripping/escape smuggling). cmd's quoting semantics are notoriously subtle, so the check is intentionally strict.echo '$(safe)') still pass.Tests
CommandValidatorMetacharacterTest— per the issue's repro matrix:echo $(printf marker),echo "$(printf marker)", backticks,$HOME/${HOME},> file,< file,%USERPROFILE%,^all rejected; plain and single-quoted-literal forms allowed.Open question for maintainers (intentionally not changed)
The report also notes both validators allow everything when the whitelist is null/empty, contradicting the tool description "No whitelist configured - all commands require approval." Aligning that would be a breaking change for users relying on allow-all with no approval callback — happy to do it in this PR or a follow-up per your call.