Skip to content

bug(workspace-cleanup-guard): 路径段以 rm 结尾(如 storm)时只读命令被当删除拦截 #433

Closed

Description

@L1nq0

在 @tt-a1i/openpi 0.6.1(npm 最新发布版,作为 pi 扩展运行)下观察到。下文代码取自 extensions/workspace-cleanup-guard/workspace-provenance.ts,该文件与当前 main 分支逐字节一致(今日拉取比对)。

观察到的现象

workspace-cleanup-guard 会在命令参数里出现以 rm 结尾的路径段(例如 storm)、且命令同时含有管道、重定向、括号或换行时,把只读命令当作删除操作拦截。

复现

guard 生效的 pi 会话里,下面这条纯读取命令被拦:

curl -s https://api.github.com/repos/apache/storm/issues/9077 | head -c 5500

拦截信息:

Blocked cleanup: OpenPI recognized a source-visible deletion outside its supported direct rm command grammar. Use a direct rm command with literal workspace-relative paths so OpenPI can determine whether each target is session-created scratch or a pre-existing path requiring confirmation.

同形状命令换一个路径段不以 rm 结尾的地址即正常通过:

curl -s https://api.github.com/repos/alibaba/fastjson2/issues/7857 | head -c 4000

在目录名以 rm 结尾的 checkout 里(例如 apache/storm 的 storm/)日常命令同样被拦:cat storm/README.md | head -20 被拦,而单独的 cat storm/README.md(无管道等元字符)能通过。这与下面的根因一致。

根因

workspace-provenance.ts 的 containsRmReference:

/(^|[^A-Za-z0-9_.-])(?:\/[A-Za-z0-9_.-]+)*\/?rm(?=$|[^A-Za-z0-9_.-])/u

重复的路径段匹配组可以把一个不完整的段消费到恰好停在 rm 前:对 apache/storm/issues,它匹配前缀字符 e、一个段 /sto、空的可选斜杠,然后 rm,lookahead 是 /。于是 storm 被计为 rm 引用。

随后 containsExecutableRmReference 调用 standaloneShellTokens,只要命令含 ; & | < > ( ) { } $ 反引号 * ? [ ] # 或换行就返回 undefined,走

if (!tokens) return true;

被判为 opaque destructive command 并整条拦截。

fail-closed 本身是 #201 引入的设计,本票不针对这个选择;问题在引用检测器给它喂了假阳性。#201 的说明里也写了要在普通参数中保留可识别的非执行 rm 文本——恰好以 rm 结尾的路径段正是这种情形,只是正则没有把它识别出来。

修复建议

要求 rm 紧邻之前是段边界:rm 前一个字符要么是串首、要么是非词字符、要么是斜杠。同一表达式的最小改法:

/(^|[^A-Za-z0-9_.-])(?:\/[A-Za-z0-9_.-]+\/)*rm(?=$|[^A-Za-z0-9_.-])/u

每个重复单元以自己消费的斜杠结尾。storm 不再匹配(/sto 缺尾斜杠无法被消费),而 rm -rf x、/bin/rm、xargs rm 一类引用照旧匹配。

可加的测试(与现有套件并行):

allowed:  curl -s https://api.github.com/repos/apache/storm/issues/1 | head -c 10
allowed:  cat storm/README.md | head -20
blocked:  echo temp/ | xargs rm
blocked:  /bin/rm -rf build

Activity

  1. L1nq0 commented on Sep 7, 2026

    @L1nq0
    ContributorAuthor

    更正正文一处。

    「cat storm/README.md | head -20 被拦」不成立:复验后,裸单段(storm/ 前没有完整 /段)在旧正则下不会命中,该命令实测通过。实际会误命中的形态是非词字符紧邻完整段链、链上最后一段回溯到 rm 收尾,例如:

    //api.github.com/repos/apache/storm
    =/repos/apache/storm/foo.c
    

    第一行即主复现里 URL 的命中方式(首个斜杠充当前缀锚点)。主复现(curl 拉 storm issue 被拦)、根因定位与修复建议均不受影响;修复 PR 的判别用例会覆盖这两类形态。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions