# GHSA-R998-943J-X5RG: vcs\_init\_git Bypasses KICAD\_MCP\_WORKSPACE\_ROOT Confinement via Unvalidated project\_dir and Ancestor Git Root

- Database: GitHub
- Severity: CVSS 5.2 (Medium)
- Published: 2026-11-23
- Modified: 2026-11-23

## Affected versions

- kicad-mcp-pro (PyPI): through 4.21.6
- kicad-mcp-pro (npm): through 4.21.6

## Description

## Remediation and supported versions

**Upgrade to kicad-mcp-pro 4.22.0 or later.** The patched Python MCP server is available on PyPI, and the matching npm launcher is available on npm. The npm launcher normally invokes the Python server version matching the launcher; if you have set KICAD_MCP_PRO_PYPI_VERSION, change that override to a patched version too. Restart the MCP server after upgrading.

The vulnerable code could perform Git checkpoint operations outside the explicitly configured KICAD_MCP_WORKSPACE_ROOT when version-control tools were available in a write-capable profile. The fix confines project paths, detected Git repositories, and Git metadata to the configured workspace. The report does not itself establish a remotely exploitable Cloud compromise.

Fix: https://github.com/oaslananka/kicad-mcp-pro/pull/1882

Python release: https://github.com/oaslananka/kicad-mcp-pro/releases/tag/mcp-server-v4.22.0

npm release: https://github.com/oaslananka/kicad-mcp-pro/releases/tag/mcp-npm-v4.22.0

---

### Summary

In `oaslananka/kicad-mcp-pro` (`<= 4.21.6`, originally reproduced at commit `690b4ad`), `vcs_init_git(project_dir)` in `src/kicad_mcp/tools/version_control.py` does not enforce `KICAD_MCP_WORKSPACE_ROOT` confinement (`assert_within`). Even when `KICAD_MCP_WORKSPACE_ROOT` is configured and `kicad_set_project` locks the active project inside the workspace, an MCP client can pass an arbitrary `project_dir` to `vcs_init_git` to create `.git/` and `.gitignore` outside the workspace, or mutate an ancestor `.git/config` outside `KICAD_MCP_WORKSPACE_ROOT`.

### Details

Unlike `ProjectCreationService` (`project/creation.py:63-64`) and `Config._validate_workspace_membership` (`config.py:569-580`), `_resolve_project_dir` and `_git_repo_root` (`src/kicad_mcp/tools/version_control.py:41-54, 86-90`) do not check `cfg.workspace_root`:

```python
# Unpatched HEAD (690b4ad) — src/kicad_mcp/tools/version_control.py:41-54, 86-90
def _resolve_project_dir(project_dir: str | None = None) -> Path:
    if project_dir:
        path = Path(project_dir).expanduser().resolve()  # no workspace_root check
    else:
        cfg = get_config()
        if cfg.project_dir is None:
            raise ValueError(...)
        path = cfg.project_dir.resolve()
    if not path.exists():
        raise FileNotFoundError(f"Project directory '{path}' does not exist.")
    return path

def _git_repo_root(project_dir: Path) -> Path | None:
    result = _run_git(project_dir, "rev-parse", "--show-toplevel", check=False)
    if result.returncode != 0:
        return None
    return Path(result.stdout.strip()).resolve()  # ancestor .git can sit outside workspace_root
```

`vcs_init_git` (`version_control.py:225-249`) initializes `.git/`, calls `_ensure_git_identity(repo_root)`, and updates `.gitignore`. In addition, the remaining five `vcs_*` tools (`vcs_commit_checkpoint`, `vcs_list_checkpoints`, `vcs_restore_checkpoint`, `vcs_diff_with_checkpoint`, `vcs_tag_release`) also call `_git_repo_root`, so an ancestor `.git/` above `KICAD_MCP_WORKSPACE_ROOT` exposes them to out-of-workspace repository operations. `version_control` is exposed in authoring profiles (`schematic_authoring`, `pcb_layout`, `builder`, `release_manager`, `full`, etc.; `tools/router.py:623-633, 740-823`) whenever operating mode permits write tools (`operating_modes.py:89`).

### PoC / Reproduction Steps

Reproduced against unpatched `HEAD` (`690b4ad`) using the real `FastMCP` server (`build_server("schematic_authoring")`) and system `git` with `KICAD_MCP_WORKSPACE_ROOT` set:

```python
import asyncio, os, tempfile
from pathlib import Path
from kicad_mcp.config import reset_config
from kicad_mcp.server import build_server

with tempfile.TemporaryDirectory() as td:
    tmp = Path(td)
    ws = tmp / "workspace"; proj = ws / "board1"; outside = tmp / "outside_victim"
    proj.mkdir(parents=True); outside.mkdir()
    (proj / "board1.kicad_pro").write_text("{}")
    (proj / "board1.kicad_pcb").write_text("(kicad_pcb)\n")
    os.environ["KICAD_MCP_WORKSPACE_ROOT"] = str(ws)
    os.environ["KICAD_MCP_OPERATING_MODE"] = "write"
    reset_config()
    server = build_server("schematic_authoring")
    asyncio.run(server.call_tool("kicad_set_project", {"project_dir": str(proj)}))
    asyncio.run(server.call_tool("vcs_init_git", {"project_dir": str(outside)}))
    assert (outside / ".git" / "config").exists() and (outside / ".gitignore").exists()
```

### Impact

- **Preconditions:** Local server invocation with `KICAD_MCP_WORKSPACE_ROOT` configured and an operating mode allowing write tools (`write` or `experimental`) on a profile containing `version_control` (no `kicad-cli` or KiCad IPC required).
- **Integrity (Low):** Initializes `.git/` repositories, writes `.gitignore`, or modifies ancestor `.git/config` (`user.name`/`user.email`) outside `KICAD_MCP_WORKSPACE_ROOT`.
- **Confidentiality (Low):** Distinguishes existing vs missing host directories outside `KICAD_MCP_WORKSPACE_ROOT` via `FileNotFoundError`.
- **Availability (None):** No server availability impact.

### Recommended Fix

Call `reject_foreign_windows_path` and enforce `assert_within(cfg.workspace, ...)` in `_resolve_project_dir` and `_git_repo_root` when `cfg.workspace_root` is set.

**Verification:** Applied to detached worktree at `690b4ad`; `pytest tests/unit/test_version_control_helpers.py tests/unit/test_path_safety.py tests/unit/test_security_controls.py tests/unit/test_project_creation_security.py tests/integration/test_version_control_tools.py` -> **58 passed in 4.36s**, and outside-workspace `vcs_init_git` calls raise `UnsafePathError`.

```diff
--- a/src/kicad_mcp/tools/version_control.py
+++ b/src/kicad_mcp/tools/version_control.py
@@ -10,6 +10,7 @@ from pathlib import Path
 from mcp.server.mcpserver import MCPServer as FastMCP
 
 from ..config import get_config
+from ..path_safety import assert_within, reject_foreign_windows_path
 from .gates import _combined_status
 from .metadata import headless_compatible
 from .validation import _entries, _evaluate_project_gate, _run_drc_report
@@ -39,16 +40,19 @@ def _git_executable() -> str:
 
 
 def _resolve_project_dir(project_dir: str | None = None) -> Path:
+    cfg = get_config()
     if project_dir:
+        reject_foreign_windows_path(project_dir)
         path = Path(project_dir).expanduser().resolve()
     else:
-        cfg = get_config()
         if cfg.project_dir is None:
             raise ValueError(
                 "No active project directory is configured. Call kicad_set_project() or "
                 "pass project_dir explicitly."
             )
         path = cfg.project_dir.resolve()
+    if getattr(cfg, "workspace_root", None) is not None:
+        assert_within(cfg.workspace, path)
     if not path.exists():
         raise FileNotFoundError(f"Project directory '{path}' does not exist.")
     return path
@@ -87,7 +91,11 @@ def _git_repo_root(project_dir: Path) -> Path | None:
     result = _run_git(project_dir, "rev-parse", "--show-toplevel", check=False)
     if result.returncode != 0:
         return None
-    return Path(result.stdout.strip()).resolve()
+    repo_root = Path(result.stdout.strip()).resolve()
+    cfg = get_config()
+    if getattr(cfg, "workspace_root", None) is not None:
+        assert_within(cfg.workspace, repo_root)
+    return repo_root
```

## References

- https://github.com/oaslananka/kicad-mcp-pro/security/advisories/GHSA-r998-943j-x5rg

Page: https://cve.now/GHSA-R998-943J-X5RG

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