Skip to content

fix: prevent fork bomb in TypeScript CLI when installed via npm - #239

Merged
timesler merged 3 commits into
mainfrom
copilot/fix-fork-bomb-linux-installation
Jul 14, 2026
Merged

fix: prevent fork bomb in TypeScript CLI when installed via npm#239
timesler merged 3 commits into
mainfrom
copilot/fix-fork-bomb-linux-installation

Conversation

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

When @atlassian/mcp-compressor is installed globally via npm, the mcp-compressor bin entry points back to dist/cli.js. The old candidateCoreBinaries() included the bare string "mcp-compressor" with a special-case that bypassed the existsSync guard, so the shim would spawn itself indefinitely.

Changes

  • resolveFromPath(name) — resolves a bare binary name to an absolute path via PATH directories (with X_OK check); returns null if not found.
  • isNativeExecutable(filePath) — reads the first 4 bytes and matches native magic numbers (ELF \x7fELF, PE MZ, Mach-O variants). A JS shim starting with #! returns false.
  • candidateCoreBinaries() — replaces the bare "mcp-compressor" push with a resolveFromPath + isNativeExecutable guard; only the resolved absolute path is added when confirmed native.
  • runRustCoreCli() — drops the binary !== "mcp-compressor" special-case; existsSync is now applied uniformly to all candidates.
// Before: always attempted, bypassing existsSync — spawns itself → fork bomb
candidates.push("mcp-compressor");
if (binary !== "mcp-compressor" && !existsSync(binary)) continue;

// After: only included when PATH resolves to an actual native binary
const resolved = resolveFromPath("mcp-compressor");
if (resolved !== null && isNativeExecutable(resolved)) candidates.push(resolved);
if (!existsSync(binary)) continue; // uniform for all candidates

@atlassian-cla-bot

Copy link
Copy Markdown

Thank you for your submission! Like many open source projects, we ask that you sign our CLA (Contributor License Agreement) before we can accept your contribution.
If your email is listed below, please ensure that you sign the CLA with the same email address.

The following users still need to sign our CLA:
❌Copilot

Already signed the CLA? To re-check, try refreshing the page.

Copilot AI linked an issue Jul 14, 2026 that may be closed by this pull request
- Add resolveFromPath() to resolve a bare binary name from PATH env var
- Add isNativeExecutable() to read magic bytes (ELF/Mach-O/PE) and
  reject JS shims that start with a shebang or other non-native header
- Update candidateCoreBinaries() to resolve 'mcp-compressor' from PATH
  and only include it when the resolved file is a native binary
- Remove the binary !== 'mcp-compressor' special-case in runRustCoreCli()
  and use existsSync uniformly for all candidates

Closes #238
Copilot AI changed the title [WIP] Fix fork bomb issue on Linux when installed via npm fix: prevent fork bomb in TypeScript CLI when installed via npm Jul 14, 2026
Copilot AI requested a review from timesler July 14, 2026 09:26
@timesler
timesler marked this pull request as ready for review July 14, 2026 15:52
Copilot AI temporarily deployed to atlassian-mcp-integration July 14, 2026 15:52 Inactive
@timesler
timesler temporarily deployed to atlassian-mcp-integration July 14, 2026 15:52 — with GitHub Actions Inactive
Inline the ternary expression for `exts` to satisfy oxfmt format check.
Copilot AI requested a review from timesler July 14, 2026 16:00
Copilot AI temporarily deployed to atlassian-mcp-integration July 14, 2026 16:31 Inactive
@timesler
timesler merged commit 245bf1d into main Jul 14, 2026
17 of 18 checks passed
@timesler
timesler deleted the copilot/fix-fork-bomb-linux-installation branch July 14, 2026 19:48
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.

Fork bomb on Linux when installed via npm

2 participants