Skip to content

Commit 41b346b

Browse files
committed
fix: validate completion output first line before writing
Reject completion output whose first line does not start with a known-valid prefix (_,#,if,function for bash/zsh; complete,# for fish), so auth error messages like "Not logged in" can no longer be written into system completion files.
1 parent 087492b commit 41b346b

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/claude-code/install.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,10 @@ setup_completions() {
549549
sed "s/${esc}\[[0-9;]*[a-zA-Z]//g" |
550550
sed '/^(node:[0-9]/d; /^Use .* --trace-warnings/d' |
551551
sed -n '/[^ ]/,$p')
552-
if [[ -n "${bash_comp_output}" ]]; then
552+
local bash_comp_first=""
553+
bash_comp_first=$(printf '%s' "${bash_comp_output}" | head -n1)
554+
if [[ "${bash_comp_first}" == _* ]] || [[ "${bash_comp_first}" == "#"* ]] ||
555+
[[ "${bash_comp_first}" == "if "* ]] || [[ "${bash_comp_first}" == "function "* ]]; then
553556
printf '%s\n' "${bash_comp_output}" >"${bash_comp_dir}/claude"
554557
elif [[ -n "${bash_comp_raw}" ]]; then
555558
log_warn "Skipping bash completions: output does not look like a valid completion script."
@@ -570,7 +573,10 @@ setup_completions() {
570573
sed "s/${esc}\[[0-9;]*[a-zA-Z]//g" |
571574
sed '/^(node:[0-9]/d; /^Use .* --trace-warnings/d' |
572575
sed -n '/[^ ]/,$p')
573-
if [[ -n "${zsh_comp_output}" ]]; then
576+
local zsh_comp_first=""
577+
zsh_comp_first=$(printf '%s' "${zsh_comp_output}" | head -n1)
578+
if [[ "${zsh_comp_first}" == _* ]] || [[ "${zsh_comp_first}" == "#"* ]] ||
579+
[[ "${zsh_comp_first}" == "if "* ]] || [[ "${zsh_comp_first}" == "function "* ]]; then
574580
printf '%s\n' "${zsh_comp_output}" >/usr/share/zsh/site-functions/_claude
575581
elif [[ -n "${zsh_comp_raw}" ]]; then
576582
log_warn "Skipping zsh completions: output does not look like a valid completion script."
@@ -597,7 +603,9 @@ setup_completions() {
597603
sed "s/${esc}\[[0-9;]*[a-zA-Z]//g" |
598604
sed '/^(node:[0-9]/d; /^Use .* --trace-warnings/d' |
599605
sed -n '/[^ ]/,$p')
600-
if [[ -n "${fish_comp_output}" ]]; then
606+
local fish_comp_first=""
607+
fish_comp_first=$(printf '%s' "${fish_comp_output}" | head -n1)
608+
if [[ "${fish_comp_first}" == "complete"* ]] || [[ "${fish_comp_first}" == "#"* ]]; then
601609
printf '%s\n' "${fish_comp_output}" >"${fish_comp_dir}/claude.fish"
602610
elif [[ -n "${fish_comp_raw}" ]]; then
603611
log_warn "Skipping fish completions: output does not look like a valid completion script."

0 commit comments

Comments
 (0)