@devries-cameron20 / composio-1 / commits / 9f10adcc8
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(installer): escape the install dir before writing it into shell rc files

install.sh's inline PATH fallback interpolated COMPOSIO_INSTALL_DIR raw into the fish and zsh rc lines, and escaped only " in the bash arm. Since that fallback is exactly what runs when `composio install` rejects a path and exits non-zero, a directory containing $(...) or a backtick was written unescaped into ~/.zshrc or config.fish and became live command substitution at the next shell start. Escape backslash, backtick, $ and " for every arm before the value is embedded, skipping the backtick for fish (which neither substitutes it nor recognizes \` inside double quotes). The $HOME prefix is re-applied after escaping so the intended variable reference survives while a user-supplied $ does not.

jkomyno committed Aug 4, 2026 at 19:15 UTC 9f10adcc8d337f86500b511153c7d2487030271f
2 files changed +53 -7
install.sh
+31 -7
@@ -69,6 +69,24 @@ tildify() {
69 fi
70 }
71
72 +# Escape a value for embedding inside a double-quoted shell rc line, so an
73 +# install directory containing `$(...)`, a backtick, or a quote is written as
74 +# literal text instead of becoming live code the next time the rc is sourced.
75 +# Backslashes must be escaped first. The second argument selects whether
76 +# backticks are escaped: bash and zsh perform backtick substitution inside
77 +# double quotes, fish does not — and fish does not recognize \` there either,
78 +# so escaping it for fish would corrupt the path.
79 +escape_for_double_quotes() {
80 + local value=$1 escape_backticks=${2:-true}
81 + value=${value//\\/\\\\}
82 + if [[ $escape_backticks = true ]]; then
83 + value=${value//\`/\\\`}
84 + fi
85 + value=${value//\$/\\\$}
86 + value=${value//\"/\\\"}
87 + printf '%s' "$value"
88 +}
89 +
90 install_agent=false
91 install_plugins=true
92 version_arg=""
@@ -322,10 +340,16 @@ else
340 info "Setting up shell integration..."
341
342 refresh_command=''
325 - quoted_install_dir=\"${COMPOSIO_INSTALL_DIR//\"/\\\"}\"
343
327 - if [[ $quoted_install_dir = \"$HOME/* ]]; then
328 - quoted_install_dir=${COMPOSIO_INSTALL_DIR/$HOME\//\$HOME/}
344 + # Every rc line below embeds one of these inside double quotes. `$HOME` is
345 + # re-applied after escaping so the intended variable reference survives as
346 + # a literal `$HOME` while any user-supplied `$` stays escaped.
347 + escaped_install_dir=$(escape_for_double_quotes "$COMPOSIO_INSTALL_DIR")
348 + escaped_install_dir_fish=$(escape_for_double_quotes "$COMPOSIO_INSTALL_DIR" false)
349 + home_relative_install_dir=$escaped_install_dir
350 +
351 + if [[ $COMPOSIO_INSTALL_DIR = "$HOME"/* ]]; then
352 + home_relative_install_dir='$HOME/'$(escape_for_double_quotes "${COMPOSIO_INSTALL_DIR#"$HOME"/}")
353 fi
354
355 shell_name=$(basename "${SHELL:-}")
@@ -334,7 +358,7 @@ else
358 case $shell_name in
359 fish)
360 commands=(
337 - "set --export COMPOSIO_INSTALL_DIR \"$COMPOSIO_INSTALL_DIR\""
361 + "set --export COMPOSIO_INSTALL_DIR \"$escaped_install_dir_fish\""
362 "set --export PATH \$COMPOSIO_INSTALL_DIR \$PATH"
363 )
364 fish_config=$HOME/.config/fish/config.fish
@@ -354,7 +378,7 @@ else
378 ;;
379 zsh)
380 commands=(
357 - "export COMPOSIO_INSTALL_DIR=\"$COMPOSIO_INSTALL_DIR\""
381 + "export COMPOSIO_INSTALL_DIR=\"$escaped_install_dir\""
382 "export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
383 )
384 zsh_config=$HOME/.zshrc
@@ -374,7 +398,7 @@ else
398 ;;
399 bash)
400 commands=(
377 - "export COMPOSIO_INSTALL_DIR=$quoted_install_dir"
401 + "export COMPOSIO_INSTALL_DIR=\"$home_relative_install_dir\""
402 "export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
403 )
404 bash_configs=("$HOME/.bashrc" "$HOME/.bash_profile")
@@ -402,7 +426,7 @@ else
426 ;;
427 *)
428 echo 'Manually add the directory to ~/.bashrc (or similar):'
405 - info_bold " export COMPOSIO_INSTALL_DIR=$quoted_install_dir"
429 + info_bold " export COMPOSIO_INSTALL_DIR=\"$home_relative_install_dir\""
430 info_bold " export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
431 ;;
432 esac
test/install-sh-release-resolution.test.sh
+22
@@ -383,6 +383,28 @@ if ! grep -qxF '# Composio CLI' "$failed_probe_home/.bashrc"; then
383 exit 1
384 fi
385
386 +# The inline fallback embeds the install directory in rc lines. A directory
387 +# holding `$(...)` must land there as literal text, not as a command that runs
388 +# at every shell start.
389 +injection_home="$tmpdir/home-injection"
390 +injection_marker="$tmpdir/injection-marker"
391 +injection_install="$tmpdir/inject-\$(touch $injection_marker)"
392 +mkdir -p "$injection_home" "$injection_install"
393 +: > "$injection_home/.bashrc"
394 +: > "$composio_log"
395 +TEST_VERSION_EXIT=126 run_installer "$injection_home" "$injection_install" --no-plugins >/dev/null 2>&1
396 +bash -c 'source "$1"' _ "$injection_home/.bashrc" >/dev/null 2>&1 || true
397 +if [[ -e "$injection_marker" ]]; then
398 + echo 'Expected inline shell integration to escape command substitution in COMPOSIO_INSTALL_DIR.' >&2
399 + cat "$injection_home/.bashrc" >&2
400 + exit 1
401 +fi
402 +if ! grep -qF '\$(touch' "$injection_home/.bashrc"; then
403 + echo 'Expected the escaped install directory to be written to .bashrc.' >&2
404 + cat "$injection_home/.bashrc" >&2
405 + exit 1
406 +fi
407 +
408 no_plugins_home="$tmpdir/home-no-plugins"
409 no_plugins_install="$tmpdir/install-no-plugins"
410 mkdir -p "$no_plugins_home" "$no_plugins_install"