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);
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
}
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) {
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.');