Dockerfile Injection in Toolhive’s Protocol-Scheme Builds (CVE-2026-103003)

EXECUTIVE SUMMARY

  • We identified a command injection vulnerability in Toolhive and reported it to Stacklok. It is tracked as GHSA-2grq-6q89-rhxx (CVE-2026-103003).
  • Any caller who can control the package name after npx://, uvx://, or go:// can cause Toolhive’s generated Dockerfile to execute arbitrary shell commands during the image build.
  • Toolhive’s audit log records MCP protocol operations, not workload-creation requests or image references. Retrospective detection of this injection path depends on external logging (API gateway, CI, or Kubernetes audit logs).
  • Actions: upgrade to 0.45.0 or later; treat workload-creation permission as privileged; inventory secrets and network reachability available to the build environment.

 

How we found it

We traced caller-controlled input from the API and CLI into the image-build path. The npx://, uvx://, and go:// schemes accept a package name as a string. Toolhive renders that string into a Dockerfile and runs docker build.

Along that path, ParseProtocolScheme() extracts the package name and passes it, together with two other caller-influenced fields (BuildArgs and AdditionalPackages), into createTemplateData().

Validation is inconsistent across those fields:

  • BuildArgs is checked by validateBuildArgs() (rejects single quotes).
  • AdditionalPackages is constrained by an allowlist regex in runtime_config.go.
  • The package name — the primary input for this feature — is assigned to TemplateData.MCPPackage with no validation, then interpolated into three Dockerfile templates.

Secondary fields were treated as potentially hostile. The package name was treated as a trusted identifier. Validation should track where data flows into execution, not which field looks more important.

We confirmed the defect by invoking Toolhive’s BuildFromProtocolSchemeWithName() with dryRun: true, which returns the Dockerfile content Toolhive would pass to docker build. The injected statements below are produced by Toolhive’s own code path, not by an external template simulation.

What Toolhive is

MCP (Model Context Protocol) is the protocol AI assistants use to access external tools and data sources. MCP servers are commonly distributed as packages on npm, PyPI, or as Go modules.

Toolhive is Stacklok’s open-source platform for running and managing MCP servers. It executes each server in an isolated container and layers permissions, network controls, and secrets management on top. It is available as a desktop UI, a CLI (thv), and a Kubernetes Operator. Toolhive’s architecture documentation describes the Kubernetes deployment mode as “Best For: Production, multi-tenant.”

A pre-built image is not required:

 
thv run npx://@modelcontextprotocol/server-filesystem

Toolhive parses the scheme, generates a Dockerfile from the package name, builds the image, and starts the container. The vulnerability is in that generation step.

 

Attack path

 

The highlighted nodes are the defect: MCPPackage is the only one of the three inputs without validation; once the injected command runs, the relevant assets are credentials and network access inside the build container.

Consider an internal service that lets developers request an MCP server through an API, with Toolhive building and running it on the backend. A caller with permission only to create workloads submits an image reference whose package-name portion contains a shell separator and a follow-on command, and that command executes during the build. The initial privilege is workload creation; the impact surface is the build environment—which is why workload-creation authorization should be treated as a privileged operation.

Both entry points converge on the same code. CLI thv run npx://<package> reaches HandleProtocolScheme() → BuildFromProtocolSchemeWithName(). The REST workload-creation path checks the image field with IsImageProtocolScheme(), then reaches the same function via retriever.handleProtocolScheme().

How the three transports fail

ParseProtocolScheme() strips the scheme with strings.TrimPrefix() and returns the remainder as the package name without sanitization. That value is stored in TemplateData.MCPPackage and rendered into three templates.

npx.tmpl interpolates the value unquoted:

 
RUN npm install --save {{.MCPPackage}}

uvx.tmpl uses double quotes:

 
RUN package="{{.MCPPackage}}"; \
    package_spec=$(echo "$package" | sed 's/@/==/'); \
    uv tool install ... "$package_spec" && \

Double quotes do not prevent command substitution ($(...), backticks) or an embedded " that terminates the string early. go.tmpl follows the same pattern in two places (lines 49 and 58).

We rendered all three transports on Toolhive v0.43.0 (last vulnerable release) via GetDockerfileTemplate(). Injected text becomes a standalone shell statement, not a package-name argument:

 
=== npx ===
RUN npm install --save pkgname; echo build-marker-1 > /tmp/marker1; #
ENTRYPOINT ["npx", "pkgname; echo build-marker-1 > /tmp/marker1; #"]

=== uvx ===
RUN package="pkgname"; echo build-marker-2 > /tmp/marker2; echo ""; \
ENTRYPOINT ["sh", "-c", "exec 'pkgname"; echo build-marker-2 > /tmp/marker2; echo "' "$@"", "--"]

=== go ===
RUN package="pkgname; echo build-marker-3 > /tmp/marker3; #"; \

In the uvx case, the injected " also corrupts the ENTRYPOINT JSON array, confirming the value was not escaped for any destination context.

Relevant weaknesses: CWE-78 (OS Command Injection), CWE-116 (Improper Encoding or Escaping of Output).

What 0.45.0 fixes

The fix is in commit 68dc1ba5c.

  1. validatePackageName() in protocol.go requires package names to match ^[A-Za-z0-9@/:._+=~\[\]-]+$. The set covers legitimate npm scopes, Go module paths, and PyPI version/extras syntax, and excludes shell metacharacters. The check runs in createTemplateData() before the value enters TemplateData.

  2. Previously unquoted RUN lines in npx.tmpl and go.tmpl are single-quoted:

 
- RUN npm install --save {{.MCPPackage}}
+ RUN npm install --save '{{.MCPPackage}}'

Re-testing the same payloads against v0.45.0 shows rejection before template rendering:

 
=== npx | input: pkgname; echo build-marker-1 > /tmp/marker1; # ===
REJECTED by validatePackageName: invalid package name "pkgname; echo build-marker-1 > /tmp/marker1; #": only letters, digits and the characters @/:._+=~[]- are allowed

Legitimate names still pass, with single-quote protection:

 
=== npx (legit) | input: @modelcontextprotocol/server-filesystem ===
RUN npm install --save '@modelcontextprotocol/server-filesystem'

The patch adds both input validation and shell-context hardening.

Why the build environment matters

RUN executes inside the build container, not on the host. Attacker reach is limited to what that container holds and can contact: .npmrc / .netrc written by writeAuthFiles(), build arguments, and the container’s network path (including cloud metadata endpoints when reachable).

Build environments are often more sensitive than runtime containers. They pull private packages and push images, so registry and package-source credentials are common. If the build identity is bound to a privileged cloud role, impact can extend from one container to the broader account.

Container isolation and network policy on the running MCP server do not reach this path: the injection happens during the image build, before the workload—and its runtime controls—exist.

A recurring pattern

An identifier-like string, left unvalidated and passed into a shell or build pipeline, recurs across MCP tooling and CI systems:

ProjectField at faultContext reachedCVSSStatus
Toolhive (this case)Package name in npx:// / uvx:// / go://Dockerfile RUN6.6 Fixed in 0.45.0
Smithery.aidockerBuildPath in smithery.yamlDocker build context pathUnscored (3,000+ hosted servers in scope)Fixed June 2025
mcp-remote (CVE-2025-6514)authorization_endpoint from a remote MCP serverLocal command execution on the client9.6Fixed in 0.1.16
FastMCP (CVE-2025-62801)server_name in the Cursor installerSubprocess with shell=True on Windows5.4Fixed in 2.13.0
tj-actions/branch-names (CVE-2025-54416)Git branch or tag nameShell in downstream GitHub Actions9.1Fixed in 9.0.0
GitLab Runner (CVE-2022-2251)Git branch nameRunner execution environmentUnscoredFixed in 15.3.5 / 15.4.4 / 15.5.2

Non-MCP cases (tj-actions, GitLab Runner) are included deliberately: the defect class is not limited to a young MCP ecosystem. Any automation that folds metadata into a shell or generated config is exposed to the same failure mode. GitLab Runner (2022) and tj-actions (2025) show the pattern reappearing years apart.

Impact concentrates in two environments:

  • Build / CI (Toolhive, Smithery, tj-actions, GitLab Runner): credentials and execution rights in the pipeline.
  • Client host (mcp-remote, FastMCP): direct execution on the end-user machine.

In every case, an unvalidated string reaches an executable context. Severity depends on whose environment is reached.

Is your environment affected?

  1. Version. Run thv version. Versions ≤ 0.44.0 are affected.
  2. Dynamic builds. Environments that only run pre-built registry images and never use npx://, uvx://, or go:// do not hit this path.
  3. Package-name provenance. Treat names from users, PRs, external APIs, marketplaces, or AI-generated instructions as untrusted.
  4. Logging gap. Toolhive audit logs cover MCP protocol operations (mcp_tool_call, mcp_resources_list, etc.), not workload-creation requests or image references. Historical checks for malicious npx:// inputs require external records (API gateway, CI parameters, Kubernetes API audit logs). Verify those sources are enabled and retained before an incident, not after.
  5. If exploitation is suspected. Rotate registry and package-source credentials used by the build environment.

Risk by deployment model

Internal developer tooling. Package names often come from an internal catalog or engineers. Risk is not fully external, but a compromised account or workstation can still reach build credentials. Restrict workload creation to roles that require it.

Multi-tenant MCP hosting. Each customer who can create workloads is a potential adversary. This is the highest-risk deployment model, and it’s what actually happened in the Smithery incident, where one tenant’s malicious build configuration threatened shared hosting infrastructure. Isolate the build pipeline; avoid persistent, broadly scoped credentials on shared builders.

AI agent or marketplace-driven installs. Package names may be LLM-generated or pulled from third-party catalogs without human review of every character. Validate before the name enters the build pipeline; do not assume an upstream layer already did.

Compliance-scoped environments (e.g. SOC 2, ISO 27001). Absence of workload-creation and image-reference records in Toolhive is an auditability gap. If change management or access logging is in scope, cover it with an outer control plane — do not assume Toolhive retains that trail.

Platform / CI teams not using Toolhive. The same template applies wherever branch names, tags, package names, or filenames are interpolated into shell or generated configs.

Remediation

Fix: Upgrade to 0.45.0 or later (validatePackageName(); single-quoting in npx.tmpl and go.tmpl).

Until you can upgrade:

  • Restrict workload-creation permission; treat it as privileged.
  • For untrusted image references, allowlist package names before they reach Toolhive (the 0.45.0 character set is a practical baseline).
  • Limit build-environment credentials to what each build requires; avoid long-lived, broad tokens.
  • Restrict outbound network access from builders; block cloud metadata endpoints where not required.
  • Run builders under least-privilege cloud identities.
  • Confirm external logging of workload-creation requests for later investigation.

Timeline

DateEvent
2026-08-18v0.44.0 released (affected; prior versions also affected)
2026-08-25Fix commit merged to main
2026-08-26v0.45.0 released with the fix
2026-08-28GHSA-2grq-6q89-rhxx published

Report submission and vendor acknowledgment dates are not public. The table lists only events verifiable from public commit history and the advisory publication date.

Closing

Upgrading Toolhive remediates this defect. The durable lesson is structural: MCP platforms turn a short string into a generated Dockerfile executed in a build environment. Every field that reaches that pipeline — from users, plugins, marketplaces, or AI workflows — must be validated as untrusted input before interpolation.

Build-environment credentials and network reach are often higher-value than the eventual runtime container, and native product logs may not record the triggering request. Treat the build path as a privileged asset, not only as a convenience feature.

References