patchbay audit
·6 min read

The scanner got scanned: command injection in our own MCP server, fixed and disclosed

patchbay scans public MCP servers for OAuth, header and tool-manifest security issues. On 2026-11-20 we had the exact species of bug we build patchbay to find in other people's code: shell-injection in our own call to git clone. Pietro Procaccini sent us a private disclosure with a working proof of concept and a one-line fix. Twelve hours later, both affected packages were patched on npm, a GitHub Security Advisory was published, and the regression that would stop the pattern being reintroduced was running in our CI.

This is how it happened and how it was caught.

What the bug was

The scan_repo tool exposed by @patchbay-nebius/mcp lets an MCP client (typically an LLM agent) point at a GitHub URL and have patchbay shallow-clone it for offline analysis. The same functionality is exposed on the command line as patchbay scan <url>. The implementation looked like this:

if (/^https?:\/\/github\.com\//i.test(path)) {
  const target = join(tmpdir(), `patchbay-mcp-scan-${Date.now()}`)
  execSync(`git clone --depth=1 "${path}" "${target}"`, { stdio: 'pipe' })
  // ...
}

The regex looked like a validation. It was not. It pinned the prefix of the URL. Nothing more. The rest of the string, up to the end, went straight into the double-quoted shell template. In POSIX shells, $(…) command substitution expands inside double quotes.

Pietro's proof of concept:

https://github.com/octocat/Hello-World$(touch /tmp/pwned)

That URL passes the prefix check. When the template is handed to execSync, the shell parses it: $(touch /tmp/pwned) is evaluated first, /tmp/pwned is created with the permissions of the process, and only then does git clone get invoked (with a mangled argument that it promptly rejects). The crash on the git side gives no warning that code already ran. Backticks and ; / && payloads behave the same way.

CWE-78: OS command injection. CVSS 8.8 base (high), with an argument for higher in agentic deployments. Any LLM that can be prompted into calling scan_repo with an attacker-supplied URL executes commands on the MCP server's host. The user running the agent does not need to type the URL; prompt-injection on the agent is enough.

The fix

Pietro sent the fix in the same mail that reported the bug:

execFileSync('git', ['clone', '--depth=1', '--', path, target], { stdio: 'pipe' })

Two differences from the original matter:

  • execFileSync with an argv array does not invoke a shell at all. The path argument is passed to git as a literal string. If it contains $(…), backticks, ;, newlines, git sees those characters, git rejects them (or git tries to clone a URL that makes no sense), but nothing else runs.
  • The -- separator tells git clone to stop parsing options at that point. If the URL ever starts with a -, it cannot be interpreted as a flag. The prefix regex blocks that today, but regex-only validation rots. Defence in depth.

We applied the fix verbatim to both call sites: packages/mcp/src/server.ts:158 and packages/agent/src/cli.ts:98. Pietro had flagged only the first one in his report. The second one was the same pattern in a different package, and we found it on an audit grep for execSync across the monorepo. Both packages are included in the GHSA.

The fix commit is 04ea42f.

How it got there, how we missed it

This is the honest part.

The regex-prefix check looked like validation. It was there to stop a user asking the scanner to clone a non-GitHub URL. It was defence against one kind of mistake (point the scanner elsewhere) and we silently extended it in our heads to defence against another kind (shell injection). Those are different problems with different fixes. A prefix regex does not constrain what comes after the prefix.

We had the safe pattern in the same repo. scripts/crawl-dual.ts:119 already used spawn('git', ['clone', '--depth=1', '--single-branch', '--quiet', repoUrl, dst]). The argv-array form Pietro suggested. Two code sites away from the two we broke. We did not pattern-match from one to the other. In review, nobody stopped and said wait, scan_repo does not do it the way crawl-dual.ts does. We did not have a check that would have stopped us.

Our tests covered acceptance and rejection, not side effects. The scanner has tests for what URLs it accepts and what URLs it rejects. It did not have a test for what happens when a URL is rejected by git but the rejection path has already caused a side effect. The PoC URL passes the prefix check, the git clone call eventually fails with a lookup error, the error handler runs cleanly, and by that time the shell has already done the attacker's bidding.

audit-core has dozens of checks for other servers' shell-injection patterns. It had none for its own sibling packages. That is the gap that let this through. Writing checks that catch bugs in other people's MCP servers while not running those same checks against our own source is exactly the imbalance a security tool should not have.

What we are doing beyond the fix

Concrete follow-ups. Not vibes.

CI regression guard (PR #8, merged 2026-11-20). scripts/validate-process-001.ts walks production source trees and fails CI on any (exec|execSync)(…) template-literal with ${…} interpolation. A meta-test (validate-process-001.test.ts) plants the pre-fix shape in a fixture and asserts the validator rejects it, so the gate cannot silently rot. We also refactored two in-repo execSync calls in scripts/build-fixture.ts that were safe-by-construction but would have taught the wrong lesson if allowlisted.

Private vulnerability reporting enabled on GodSmasher/patchbay and GodSmasher/patchbay-audit. Pietro had to route through the /cve page email we published on the site. That address now coexists with GitHub's first-class private reporting channel.

Publish-workflow audit. The release pipeline was publishing @patchbay-nebius/audit-core and @patchbay-nebius/agent automatically on tag push, but @patchbay-nebius/mcp was hand-published. That meant we had no idempotent, provenance-signed release path for the package that was most exposed by this bug. We added mcp to the workflow and configured npm Trusted Publisher as part of the SEC-001 ship. The 0.7.1 release is the first signed-with-provenance mcp release, and every future one picks the same path.

What we are not promising:

  • We are not claiming no one was affected. We cannot prove it, and the responsible version is to publish the disclosure and let dependents upgrade. If you ran @patchbay-nebius/mcp or @patchbay-nebius/agent on an older version and are concerned, the GHSA has the CVSS vector and the exact pre-fix call sites for your own audit.
  • We are not claiming the regression guard is exhaustive. It catches the direct pattern, where the template literal is written at the exec call site itself. It does not catch indirect patterns (build the string into a local variable first, pass the variable). Those are harder to grep for without an AST pass. If they show up we will extend the gate.
  • We are not promising this is the last time we will ship a bug. We are promising to be the first to tell you when we do.

Credits

Thanks to Pietro Procaccini (@pl4ka7) for responsibly disclosing SEC-001 and for sending the exact fix we shipped. If you run security research on MCP infrastructure or the npm supply chain, our private vulnerability reporting is now enabled at github.com/GodSmasher/patchbay/security/advisories/new. We read every report ourselves.

Links