Repository navigation
fix: 修复引号内的字符串被误认为危险命令 #349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -232,11 +232,6 @@ def _split_command_line(cmd: str) -> list[str]: | |
| """ | ||
| if not cmd.strip(): | ||
| raise ValueError("skill_run: command is empty") | ||
| for ch in _DISALLOWED_SHELL_META: | ||
| if ch in cmd: | ||
| raise ValueError(f"skill_run: shell meta character {ch!r} is not allowed when " | ||
| "command restrictions are enabled. Provide a single executable " | ||
| "with args only (no redirects/pipes/chaining).") | ||
| args: list[str] = [] | ||
| cur: list[str] = [] | ||
| in_single = False | ||
|
|
@@ -256,6 +251,10 @@ def _split_command_line(cmd: str) -> list[str]: | |
| if not in_single and ch == '"': | ||
| in_double = not in_double | ||
| continue | ||
| if not in_single and not in_double and ch in _DISALLOWED_SHELL_META: | ||
| raise ValueError(f"skill_run: shell meta character {ch!r} is not allowed when " | ||
| "command restrictions are enabled. Provide a single executable " | ||
| "with args only (no redirects/pipes/chaining).") | ||
|
Comment on lines
+254
to
+257
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 将元字符检查从整串预扫描改为仅在未加引号且未转义时拒绝( 触发条件: 启用 实际影响: 限制模式下可在宿主机(本地运行时)或工作区容器(容器/cube)执行任意多语句/管道链命令,视为绕过命令白名单的任意代码执行;同时工具声明与报错文案仍宣称 no shell syntax / no redirects/pipes/chaining,与实现不再一致,误导依赖该保护的调用方。 修正方向: 在
Comment on lines
+254
to
+257
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 新放行的引号/转义输入经分词器得到的 argv 与 POSIX bash 语义不一致,参数往返(round-trip)失真。分词器在双引号内也把反斜杠当转义并剥除,而 bash 在双引号内仅对 触发条件: 限制模式下命令含双引号内转义元字符或续行符,如 实际影响: 本次修复本意是让引号内元字符按字面传给程序,但生成的 argv 与用户期望的 shell 语义不同: 修正方向: 使分词器遵循 POSIX 双引号规则:双引号内仅对
Comment on lines
+254
to
+257
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 触发条件: 模型读取工具声明后基于不存在的限制做决策:要么因惧怕报错而回避合法的引号内元字符参数(如 实际影响: 声明中的安全承诺是部署方评估风险(是否再加运行时隔离)的依据,文案失真会使过于乐观的安全评估;同时既有的放行能力被描述为禁止,降低工具可用性。 修正方向: 将声明与报错文案改为如实描述:元字符在引号内/转义时以字面参数传递,但限制模式下解释器 -c/-e 复合命令仍被禁止(若按第一条修正实现),或明确说明引号不构成命令级隔离、限制仅作用于词法层。 |
||
| if not in_single and not in_double and ch in (" ", "\t"): | ||
| if cur: | ||
| args.append("".join(cur)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
问题: 新增测试仅断言
_split_command_line/_build_command返回的纯 argv 元组,没有任何用例运行或检查它经run_program真正执行后的行为,尤其缺少对引号内多语句载荷(python3 -c 'import os; print(1)'、bash -c 'echo hi; id')以及本地create_subprocess_exec/容器bash -lc/cube 三种运行时的往返覆盖。触发条件: 未来将分词逻辑替换为
shlex.split之类同样放行引号内元字符的实现,或在容器/cube 运行时中参数被重新解析为 shell 语法时,所有新增测试仍保持绿色,安全回归不被发现。实际影响: 本次变更的核心安全边界(引号内元字符经解释器变为可执行代码)完全没有被测试保护,回归会静默合入;同时容器与 cube 运行时下对引号内
;/|的重新解释行为与本地运行时不一致,测试无法暴露此不一致。修正方向: 增加端到端用例:在允许
python3的前提下以-c传含;的表达式,断言被拒绝(或执行结果符合安全预期);对容器运行时路径用真实_shell_quote拼装bash -lc后断言参数以字面量到达目标程序。