Skip to content

Fix shell injection, AppleScript injection, and symlink escape in skill installer#43

Open
choisel wants to merge 5 commits intolcoutodemos:mainfrom
choisel:main
Open

Fix shell injection, AppleScript injection, and symlink escape in skill installer#43
choisel wants to merge 5 commits intolcoutodemos:mainfrom
choisel:main

Conversation

@choisel
Copy link
Copy Markdown

@choisel choisel commented Mar 22, 2026

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 a curl | tar command as a shell string, meaning special characters in tmpDir or the skill path could be interpreted by /bin/sh. Replaced with two spawnSync() 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:

  • Layer 1: --no-symlinks flag passed to tar, preventing symlink creation at extraction time
  • Layer 2: 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

Test infrastructure

No tests existed before this PR. Added vitest and three test suites (21 tests total):

  • shell-utils.test.ts — 9 tests for shellSingleQuote covering double quotes, $, backticks, backslashes, and injection payloads
  • installer.test.ts — 5 tests verifying spawnSync argument arrays, --no-symlinks presence, curl→tar stdin pipe, and error propagation
  • symlink-escape.test.ts — 7 tests for assertNoSymlinkEscape using real filesystem symlinks, including nested symlinks, symlink chains, and path identification in error messages

Test plan

  • npm install && npm test — all 21 tests pass
  • Open a project with special characters in its path (e.g. spaces, apostrophes) — Terminal opens correctly
  • App starts up normally and skills install without error

Choisel 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant