T09 · Insecure Skill Coding Practices
Error
- Location
- index.js:179
- Finding
- Project Path Injection Enables Arbitrary Command Execution During Launch<![CDATA[ ## Vulnerability Details **File Location**: `index.js:179-194` **Vulnerability Type**: Shell and AppleScript injection **Risk Level**: High ### Vulnerable Code ```javascript async function launch(projectPath, options = {}) { const sessionId = ++sessionCounter; const normalizedPath = path.resolve(projectPath); if (!fs.existsSync(normalizedPath)) { throw new Error(`Project path does not exist: ${normalizedPath}`); } console.log(`[CC-${sessionId}] 🚀 Opening Terminal.app with Claude Code at ${normalizedPath}`); // Open a new Terminal.app window and run claude code runAppleScriptMulti([ 'tell application "Terminal"', ' activate', ` do script "cd '${normalizedPath}' && claude code"`, 'end tell', ]); ``` ### Technical Analysis The resolved project path is inserted directly into both an AppleScript string literal and a shell command executed by Terminal.app. `path.resolve()` normalizes a path but does not make it safe for either AppleScript or shell interpolation. The only validation confirms that the path exists. A directory name containing a single quote can terminate the shell-quoted path, while double quotes, backslashes, or line breaks can alter the generated AppleScript. Because Terminal executes the generated `do script` command, a crafted existing path can introduce additional shell commands. The operation runs under the current user's account and benefits from the Accessibility permissions required by the package. ### Attack Path 1. An attacker influences the `projectPath` supplied to `launch()`. 2. The attacker creates or identifies an existing directory whose name contains shell or AppleScript metacharacters. 3. `path.resolve()` preserves the dangerous characters. 4. The path is interpolated into `do script "cd '${normalizedPath}' && claude code"`. 5. Terminal.app interprets the injected shell syntax. 6. Arbitrary local commands execute with the invoking user's privileges. ### Impact Assessment S ...[truncated 363 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Do not construct AppleScript source or shell commands by interpolating the project path. - Pass the path to AppleScript through `osascript` arguments and access it through `on run argv`. - Inside AppleScript, use a safely quoted shell argument rather than concatenating untrusted text. - Prefer launching a fixed executable with `spawn()` or `execFile()` and an explicit `cwd`. - Verify that the resolved target is a directory and, where feasible, restrict it to approved workspace roots. - Add regression tests covering quotes, backslashes, line breaks, command substitutions, and Unicode characters in directory names. ]]>
