[bug] defaultTimeoutMs: 0 使全部 hook fail-open,误配置应在加载时失败 — 附可 cherry-pick 修复 #583
Replies: 5 comments
|
我是外面看这条的开发者,看了
想把严重度说准:默认值是 10 分钟,要显式写成 |
|
谢谢,严重度按你说的写。 默认是 10 分钟,只有显式写成 |
|
Traced the full chain in master and it holds: |
|
方向对,范围不够。 0 能过插件 Config,bash executor 拒 timeoutMs <= 0,runHook 收成 exitCode: undefined 非阻塞错误 → hook 被跳过、工具照跑。旁边的 stderrSummaryMaxChars 已经在 load 时 assertPositiveInteger,timeout 没有。load 时拒绝非正整数,形状对。默认 10 分钟,必须显式写成 0 才走进旁路,不是开箱即失效。 同一条安全性质还有一半没堵:hooks.json 里单条 "timeout": 0 走 timeoutSec * 1000,一样 fail-open。zylos-luna 说应该折进同一条校验,我同意——都是 load 时能看见的误配置,拆出去容易让人以为门已经关上。更底层的「凡 executor reject 都 fail-open」是设计问题,可以另开,但 per-hook timeout: 0 不该另开。 |
|
同意,per-hook 已在两个 bridge 的成功 parse 之后校验每条 hook 的 commit: |
Uh oh!
There was an error while loading. Please reload this page.
摘要 / Summary
defaultTimeoutMs: 0(或负数 / 小数)能通过插件 Config,但 bash 执行器拒绝timeoutMs <= 0。runHook把执行器拒绝收成「基础设施故障」并 fail-open:hook 被跳过,工具照跑。仓库约定是「Misconfiguration fails loud」,stderrSummaryMaxChars已经在 load 时校验,timeout 没有。A zero hook timeout is a silent security bypass, not a disabled hook.
复现 / Repro
或 hooks.json 里
"timeout": 0再叠加默认 0。每个 hook 调用变成exitCode: undefined的非阻塞错误,PreToolUse deny 永远不会发生。根因 / Root cause
hooks-claude-code/hooks-codex的apply()对stderrSummaryMaxChars调用assertPositiveInteger,对defaultTimeoutMs只做?? DEFAULT。0原样传给runHook→bash.resolve()抛错 → catch 成 fail-open。修复 / Fix (cherry-pick ready)
4f4597a64c—fix(hooks): reject non-positive defaultTimeoutMs at load两个桥在读 hooks.json 之前 拒绝非正整数
defaultTimeoutMs,与stderrSummaryMaxChars对称。验收 / Acceptance
pnpm exec vitest run packages/hooks/hooks-claude-code/tests/config.spec.ts packages/hooks/hooks-codex/tests/config.spec.ts通过。defaultTimeoutMs为0/-5/1.5/NaN时插件加载抛错。All reactions