Skip to content

claudecode: single-quote hook binary path for shell safety - #1200

Merged
zzet merged 1 commit into
mainfrom
fix/hook-binary-single-quote
Oct 30, 2026
Merged

zzet merged 1 commit into
mainfrom
fix/hook-binary-single-quote

Conversation

@zzet

@zzet zzet commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Problem

ResolveHookCommand bakes shellSafeHookBinary(bin) + " hook" into ~/.claude/settings.json, and Claude Code runs it through its shell (Git Bash on Windows). The path was only backslash-normalized, so a space would word-split the command and a $var/backtick would expand at hook-fire time.

Finding (verified empirically)

Claude Code runs hooks through a shell; the binary path is operator-set by the install location, so this is only reachable if gortex is installed at an attacker-influenced path — but the fix is a one-liner.

Fix

shellSafeHookBinary now single-quotes the path (POSIX quotes, with the standard '\'' escape) whenever it contains a character a shell would interpret, via a safe-token regex ([A-Za-z0-9_./:+]). A normal install
path (/opt/homebrew/bin/gortex) is emitted unchanged; a bare word from the PATH fallback needs no quoting. Two regression cases added.

ResolveHookCommand bakes `shellSafeHookBinary(bin) + " hook"` into
~/.claude/settings.json and Claude Code runs it through its shell. The
path was only backslash-normalized, so a space would word-split the
command and a $var/backtick would expand at hook-fire time. Quote the
path (POSIX single-quotes, with \'\' escaping) whenever it contains a
character a shell would interpret; a normal install path is emitted
unchanged, and the PATH-fallback bare word needs no quoting. Two
regression cases added.

Co-authored-by: security audit
@zzet
zzet merged commit 2038976 into main Oct 30, 2026
38 checks passed
@zzet
zzet deleted the fix/hook-binary-single-quote branch October 31, 2026 12:04
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