[bug] Claude hook matcher 大小写敏感,Bash 选不中 bash,安全 hook 静默失效 — 附可 cherry-pick 修复 #582
Replies: 4 comments
|
我是外面看这条的开发者,看了 Claude 侧 hooks 常用 字面量改成大小写不敏感的精确匹配、正则保持敏感、 我不会把它说成默认安全洞:matcher 本来就写 |
|
谢谢,严重度按你说的写。 字面量 load 时对「配置了却零命中」给诊断,另开,不塞进这一条。 |
|
Reproduced the reasoning from master: the Claude literal path is a case-sensitive |
|
Claude 的 hooks.json 写 Bash/Read,这边注册 bash/read。字面量走 split('|').includes(query),对不上就 continue,从 Claude 拷来的 PreToolUse 静默不开火。字面量改成大小写不敏感的精确匹配、Bash 仍不配 BashOutput/dash、正则保持敏感,这个边界合理。 两处没修、而且不该假装修了: ^Bash$ 仍走正则、仍大小写敏感,迁过来的正则 matcher 照样零命中。 |
Uh oh!
There was an error while loading. Please reload this page.
摘要 / Summary
Claude Code 的
hooks.json用 PascalCase 工具名(Bash、Read)。DeepSeek Harness 注册的是小写(bash、read)。Claude 字面量 matcher 做精确大小写匹配,对不上就 静默跳过,不报错。从 Claude 拷来的PreToolUse安全 hook 永远不会开火,工具照跑。Migrating a Claude Code
matcher: "Bash"hook to this harness silently disables it.复现 / Repro
hooks-claude-code,hooks.json里PreToolUse写"matcher": "Bash",hook 返回 deny。bash工具。Bash选中bash,deny 生效。根因 / Root cause
packages/hooks/hook-protocol/src/matcher.ts:query是exec.name(bash),pattern 是Bash。includes大小写敏感。不匹配时只continue,没有诊断。这和「allowlist glob 写错 → 工具集静默变空」是同一类坑:配置看起来生效,运行时零命中。
修复 / Fix (cherry-pick ready)
27791eb90d—fix(hook-protocol): match Claude literal tool names case-insensitivelyClaude 字面量改为大小写不敏感的精确匹配(
Bash→bash)。Bash仍不匹配BashOutput。正则路径(^Bash$)保持大小写敏感。验收 / Acceptance
pnpm exec vitest run packages/hooks/hook-protocol/tests/matcher.spec.ts通过。matchesMatcher('Bash', 'bash', 'claude-code') === true,且仍不匹配BashOutput/dash。All reactions