Fix shell injection, AppleScript injection, and symlink escape in skill installer#43
Open
choisel wants to merge 5 commits intolcoutodemos:mainfrom
Open
Fix shell injection, AppleScript injection, and symlink escape in skill installer#43choisel wants to merge 5 commits intolcoutodemos:mainfrom
choisel wants to merge 5 commits intolcoutodemos:mainfrom
Conversation
added 5 commits
March 22, 2026 01:07
The curl|tar command was built as a shell string via execSync(), which passes through /bin/sh -c and allows shell metacharacters in path or tmpDir to be interpreted. Switch to two spawnSync() calls with explicit argument arrays: curl stdout is fed directly as stdin to tar, so no shell is ever involved and special characters cannot escape. Also removes the unused `dirname` import.
Building a shell command string dynamically and embedding it into an AppleScript `do script "..."` created an injection vector: a project path containing double quotes or AppleScript-significant characters could break out of the string context. Instead, write the shell command to a UUID-named temp file (mode 700) and pass only the file path to Terminal via AppleScript. The AppleScript string now contains no user-controlled data — only a /tmp/clui-term-<uuid>.sh path — so there is no injection surface. The temp file is cleaned up 5s after Terminal has had time to read it.
… helper Introduces vitest as test framework and adds two test suites: - shell-utils.test.ts: verifies shellSingleQuote correctly handles double quotes, dollar signs, backticks, backslashes, and the classic AppleScript injection payload without breaking the single-quote escaping invariant. - installer.test.ts: verifies that installGithubSkill passes curl and tar arguments as discrete array elements (not shell strings), that curl stdout is piped directly as tar stdin, and that non-zero exit codes from either binary surface as skill failures. Also extracts shellSingleQuote from the inline IPC handler into src/main/shell-utils.ts so it can be imported and tested independently.
Two-layer protection against malicious tarballs that contain symlinks pointing outside the extraction directory (e.g. to ~/.ssh/id_rsa): Layer 1 — prevention: pass --no-symlinks to tar so symlinks are never created during extraction on supported macOS/BSD tar versions. Layer 2 — detection: assertNoSymlinkEscape() walks the extracted tmpDir after tar completes and throws if any symlink resolves (via realpathSync, following full chains) to a path outside the base directory. This catches cases where --no-symlinks is silently ignored by older tar versions. Extraction fails fast and tmpDir is cleaned up on any escape detection. Adds symlink-escape.test.ts with 6 scenarios including nested symlinks, symlink chains, and path identification in error messages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Security audit identified three vulnerabilities in the skill installer and terminal opener. This PR fixes all three with tests.
Fix 1 — Shell injection in skill installer (
installer.ts)execSync()built acurl | tarcommand as a shell string, meaning special characters intmpDiror the skillpathcould be interpreted by/bin/sh. Replaced with twospawnSync()calls using explicit argument arrays — curl stdout is piped directly as tar stdin, no shell involved.Fix 2 — AppleScript injection in
openInTerminal(index.ts)A project path containing double quotes or AppleScript-significant characters could break out of the
do script "..."string context and execute arbitrary AppleScript. Instead, the shell command is written to a UUID-named temp file (/tmp/clui-term-<uuid>.sh, mode 700) and Terminal receives only the file path — no user-controlled data is ever embedded in the AppleScript string.Fix 3 — Symlink escape attack in tarball extraction (
installer.ts)A malicious GitHub tarball could include symlinks pointing outside the extraction directory (e.g. to
~/.ssh/id_rsa). Two-layer defence:--no-symlinksflag passed to tar, preventing symlink creation at extraction timeassertNoSymlinkEscape()walks the extractedtmpDirafter tar completes and throws if any symlink resolves (viarealpathSync, following full chains) to a path outside the base directoryTest infrastructure
No tests existed before this PR. Added vitest and three test suites (21 tests total):
shell-utils.test.ts— 9 tests forshellSingleQuotecovering double quotes,$, backticks, backslashes, and injection payloadsinstaller.test.ts— 5 tests verifyingspawnSyncargument arrays,--no-symlinkspresence, curl→tar stdin pipe, and error propagationsymlink-escape.test.ts— 7 tests forassertNoSymlinkEscapeusing real filesystem symlinks, including nested symlinks, symlink chains, and path identification in error messagesTest plan
npm install && npm test— all 21 tests pass