Skip to content

fix(safety): O117 L3 .git/config allow-list (fail-closed) + config.worktree - #117

Merged
QiaolongLi1201 merged 3 commits into
mainfrom
fix/o117-git-config-l3-precise
Oct 12, 2026
Merged

QiaolongLi1201 merged 3 commits into
mainfrom
fix/o117-git-config-l3-precise

Conversation

@QiaolongLi1201

@QiaolongLi1201 QiaolongLi1201 commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

O117 — L3 对 git 配置文件改为放行名单(fail-closed)

Base 1705d9ef(#118)。人工实现。

放行名单全文(GIT_CONFIG_BENIGN_KEYS,只列具体键,无通配、无子节)

user.name
user.email
color.ui
init.defaultBranch
pull.rebase
core.autocrlf

变化全部落在名单内才不报;名单外任何键(含从没见过的 foo.bar)变化 → 「已被修改」,exit 9。

remote / branch(PM 口径,11:03–11:05)

  • 叶子键放行(任意子节名):branch.<名>.merge、remote.<名>.fetch。
  • 按值放行:branch.<名>.remote 只认 .、普通 remote 名([A-Za-z0-9_][A-Za-z0-9._-]*)或下面认可的 URL(它也可直接写 URL,故同样查值)。
  • 按值放行:remote.<名>.url 只认 https://、ssh://、git@host:path(scp 式)。ext::/fd::/任何 <transport>::、file://、git://、http://、本地路径(含 C:\)、以 - 开头、含换行/控制/空白字符 → 报。host/user 以 - 开头报(先 URL 解码,最多 3 层,覆盖 %2D/%252D);port 仅数字;scp 路径以 - 开头报。
  • 同一 remote 下其它叶子 pushurl/uploadpack/receivepack/proxy/vcs/tagOpt/mirror、branch.*.pushRemote 照报。

不放行(规格没列):extensions.*、core.repositoryformatversion、init.templateDir、user.signingKey、color.<slot>.*。

受保护文件

.git/config、.git/config.worktree、.git/worktrees/<name>/config.worktree(新增)。这修掉了 QA 复现的绕过:先设 repositoryformatversion=1 和 extensions.worktreeConfig,再在 config.worktree 里设 hooksPath。事前拦:.git 下的路径已经被 O103 拦住(E4 断言),#115/O103 的代码没改。

fail-closed

删除 →「被删除」;换成软链 →「被换成软链」;换成目录 →「被换成目录」;git 解析失败 →「无法解析」。全部 exit 9。

QA 三条合门

  1. 名单只列具体键,core.*/alias.*/url.*/include*/init.*/user.*/color.* 都不通配(C4 断言名单全文)。section 和变量名不区分大小写,子节按 git 语义保留大小写;带子节的键一律不放行。
  2. 解析:git config --file <临时文件> --no-includes --list -z,cwd 是临时目录,HOME 是临时目录,GIT_CONFIG_NOSYSTEM=1,GIT_CONFIG_GLOBAL=/dev/null。不在被测仓库里跑 git,不跟 include;解析失败按 fail-closed 处理。
  3. 测试:remote.origin.uploadpack(B6)、core.fsmonitor 和 [Core] FSMonitor(B9)都会被报。

文案(UX)

  • zh 末行:未完成:sh x.sh:受保护路径已被修改,.git/config 改了 core.hooksPath(不在安全清单内);卡在:.git/config 改了 core.hooksPath(不在安全清单内)
  • en:.git/config changed core.hooksPath (not on the safe list)
  • 键名保留文件里的原始大小写。超过 3 个时写 a、b、c 等 5 个 / and 2 more。混写时只点名名单外的键。只写键名,不写值。
  • 新增 [moss-o117-protected-path-detail] 标记,把键名和原因从工具结果带到 run-outcome(exec_background 也带)。

测试

  • test/o117-git-config-l3-precise.spec.mjs:A 名单内不报;B 名单外被报(hooksPath、uploadpack、foo.bar、fsmonitor 大小写变体);C fail-closed;D execTool 端到端;E config.worktree 绕过;F 文案;G 进程级 moss -p 跑 git config user.name x → exit 0(zh+en)。
  • A3/A4/A9/G2:git remote add https + 真实 git push -u/设上游 → 不报,进程级 moss -p exit 0;A5/A8/A9/G3:ext::sh -c …、/tmp/evil、ssh://-oProxyCommand=…、%2D/%252D 变体 → 报,-p exit 9;A7:pushurl/uploadpack 等 → 报。
  • 撤修复(git diff 1705d9ef HEAD -- src | git apply -R):40 条变红,含 E1/E2 绕过和 G1 -p。
  • 回归:O101/O103(含 blocked-outcome 进程级)/O108/O94/git-spawn/cli-ui-language/run-completion-o98 全绿;npm run check 绿;npm test 373 个文件全过(Node 22)。

@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 force-pushed the fix/o117-git-config-l3-precise branch from 98a9ee2 to 4daacca Compare October 12, 2026 03:01
@QiaolongLi1201 QiaolongLi1201 changed the title fix(safety): O117 L3 reports .git/config only when dangerous keys change fix(safety): O117 L3 .git/config allow-list (fail-closed) + config.worktree Oct 12, 2026
@QiaolongLi1201
QiaolongLi1201 force-pushed the fix/o117-git-config-l3-precise branch 2 times, most recently from 13577b3 to 6f419e2 Compare October 12, 2026 05:13
@QiaolongLi1201
QiaolongLi1201 force-pushed the fix/o117-git-config-l3-precise branch from 6f419e2 to 218ffba Compare October 12, 2026 06:16
@QiaolongLi1201
QiaolongLi1201 merged commit e056e2b into main Oct 12, 2026
10 of 12 checks passed
QiaolongLi1201 added a commit that referenced this pull request Oct 12, 2026
fix(safety): O123 L3 不再把普通 git commit/checkout/merge 误报为已修改(依赖 #117)
QiaolongLi1201 added a commit that referenced this pull request Oct 12, 2026
…-keys

fix(safety): O127 L3 follows linked-worktree .git file (exec keys no longer missed) [depends #117 #122]
QiaolongLi1201 added a commit that referenced this pull request Oct 12, 2026
@QiaolongLi1201
QiaolongLi1201 deleted the fix/o117-git-config-l3-precise branch October 12, 2026 10:29
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