Skip to content

feat(safety): O101 间接写受保护路径三层检测(inline/script/post-run) - #101

Merged
QiaolongLi1201 merged 2 commits into
mainfrom
fix/o101-indirect-writes
Oct 11, 2026
Merged

QiaolongLi1201 merged 2 commits into
mainfrom
fix/o101-indirect-writes

Conversation

@QiaolongLi1201

@QiaolongLi1201 QiaolongLi1201 commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary(中文)

实现 O101(间接写受保护路径),规格见仓库外 /workspace/specs/O101.md(本 PR 按该规格验收)。

在 O94/O97 之上补三层(尽力拦截,不是沙箱;无自动还原;无项目/环境/模型可关闭或缩小检测的开关):

  1. 内联代码:python -c / node -e / bash -c 中字面受保护路径 → 走 O94 确认(-p 拒绝);提示带脚本名与行号。
  2. 工作区脚本:执行前只读扫描被调用的脚本(realpath,工作区外/过大/二进制按「拿不准」);npm test / pytest / node --test 等不展开。
  3. 事后检测:命令结束后对比 ~/.ssh、.env*、.git/{config,HEAD,refs,hooks} 的 mtime/size/hash(内容与完整哈希不进日志/outcome/工具结果)。命中后文案用「已被修改」而非「已拦截」;接 O98 run-outcome → 未完成 + 非 0;不自动还原。

受保护路径定义复用 O94/O97,不另起一份。

相对 Grok 草稿的适配

开销(验收 F)

真 API:takeProtectedPathSnapshot + After + diffProtectedPathSnapshots(head 9f07daf1),15 条受保护路径,n=100(warmup 5)。

环境 mean p50 p95 max
RDK 板(aarch64 PREEMPT_RT,Node v22.22.2) 1.40 ms 1.38 1.87 2.29
共享电脑(同脚本对照,Node v20.19.2 x86_64) 0.57 ms 0.52 0.94 1.90

此前 PR 里 ~0.38 ms 是更松的 box 口径;上表为同 fixture 对照。DeepSeek 首装 5 次中位数 / 长任务 ≤5% 增量仍待 UX/QA(无 key 可不挡)。

已知局限(文档已写)

  • shell 层尽力拦截,不是 OS 沙箱(系统沙箱另开 O102)。
  • 后台延后写入(& / nohup)可能躲过事后对比。
  • 第三层只检测、不阻止、不还原。

Summary (English)

Implements O101 (indirect writes to protected paths) per /workspace/specs/O101.md.

Three layers on O94/O97 (best-effort, not a sandbox; no auto-restore; no kill-switch projects/env/model can disable or shrink):

  1. Inline python -c / node -e / bash -c literals → O94 confirm (-p denies); prompt names script + line.
  2. Pre-run read-only scan of workspace scripts (realpath; outside/too-large/binary = uncertain); skip expanding npm test / pytest / node --test.
  3. Post-run metadata snapshot of ~/.ssh, .env*, .git/{config,HEAD,refs,hooks} (mtime/size/hash only — never contents / full hashes in logs/outcome/tool results). Notices say 「已被修改」/ “modified”, not intercepted. Wires to O98 run-outcome → incomplete + non-zero. No auto-restore.

Protected-path definitions are reused from O94/O97 only.

Adapted from Grok draft

Test plan

  • node test/o101-indirect-writes.spec.mjs — 26/26 pass
  • Related: o94-protected-paths 73/73, o97-followup 19/19, run-completion-o98 ok, shell-write-detect 36/36, shell-write-sandbox 57/57
  • npm run check — format/lint/typecheck 0
  • Revert-red: strip O101 L1–2 merge + L3 outcome wiring → A1–A3 (source), B-scripts, B-ux, C3 go red (8 failures); restore → 26/26 green again
  • QA manual A–E + base64-obfuscated bash on final head
  • UX per O101.md
  • RDK board overhead (mean 1.40 ms/pair @ Node 22.22.2 aarch64)
  • DeepSeek install median (no key → non-blocking per PM)

Spec pointers

  • Acceptance A–H, UX 1–6, QA 1–7 in /workspace/specs/O101.md
  • Research: /workspace/research/o101-indirect-writes.md

Moss Grok and others added 2 commits October 12, 2026 04:09
…post-run)

Three layers on top of O94/O97:
1) Inline python -c / node -e / bash -c with protected-path literals
2) Pre-run scan of workspace scripts (skip npm test/pytest/node --test)
3) Post-run metadata snapshot (mtime/size/hash only) → O98 incomplete

Best-effort interception, not a sandbox. No auto-restore; notices say
「已被修改」not「已拦截」. Delayed background writes are a known limit.
- Attach layer-3 notice on signal-kill and non-zero exit paths too
  (command already ran; detect after any exit).
- A1–A3 assert O101 inline source metadata (revert-red for O101 path;
  -p deny itself still covered by O97 mentions).
- D4 asserts filterExpectedGitMetadataChanges empties git porcelain.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@QiaolongLi1201
QiaolongLi1201 merged commit 25ce04c into main Oct 11, 2026
6 of 12 checks passed
@QiaolongLi1201
QiaolongLi1201 deleted the fix/o101-indirect-writes branch October 11, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant