Affected: kicad-mcp-pro 3.35.1 (PyPI) and main at f25db866f1223fe38fec86a63d955b455f82f0ad (i.e. after the #969 discovery change)
Description
Affected: kicad-mcp-pro 3.35.1 (PyPI) and main at f25db866f1223fe38fec86a63d955b455f82f0ad (i.e. after the #969 discovery change). Verified on KiCad 10.0.6, macOS arm64, Python 3.13, MCP Python SDK over stdio, KICAD_MCP_WORKSPACE_ROOT unset (the default). Both builds behave identically for this issue.
Summary
When the server is started with --project-dir, scan_project_dir / select_canonical_kicad_file (src/kicad_mcp/discovery.py) choose the active .kicad_sch / .kicad_pcb. The chosen path is never checked against the project (or workspace) root, so if the selected file is a symlink pointing outside the project, every file-backed tool follows it — for reads and for writes.
Explicit path arguments are already confined: sch_get_symbols(sheet_file="link.kicad_sch") on an escaping symlink is refused with "The requested path '…' escapes workspace root". Only the auto-selected active file skips that check.
The reliable trigger is a symlink named after the project stem (<project>.kicad_sch). git preserves symlinks, so a cloned repository or unpacked archive can ship one. Note that #969 (merged, "prefer the file matching the .kicad_pro stem") does not fix this and makes the stem-named case the actively selected one: discovery now prefers <stem>.kicad_sch, and if that entry is a symlink, it is chosen. (An extra, merely alphabetically-first symlink alongside the real file is not selected on either build, so the "sorts first" description from the first draft is not a reliable trigger; the stem-named symlink is.)
Impact
Two effects, both with the malicious project opened via --project-dir and KICAD_MCP_WORKSPACE_ROOT unset (the default):
- Write-through, outside the project (the elevating finding). In a write-capable mode, editing the auto-selected schematic modifies the symlink's target outside the project. Verified by sha256 of the outside file before/after each call, with the in-project symlink left intact (the write went through the link, it was not replaced). Reproduced on both 3.35.1 and main, in
expert/experimentaland inbuild/write, forsch_add_symbol,sch_update_propertiesandsch_modify_property(4/4 write calls per build). - Read-through. In the default
readonlyprofile the auto-selected outside schematic is parsed and returned to the MCP client. Confirmed with a canary: a symbol Value placed in an outside schematic surfaced verbatim insch_get_symbols.
Not found: linking a non-KiCad file (a .env-style file with canary tokens) as the active .kicad_sch/.kicad_pcb/.kicad_pro did not leak its bytes — 0 of 36 read responses across both builds contained any line of the file, including error text. So this is not an arbitrary-file-read of non-KiCad content; the disclosure is limited to files KiCad can parse as a design.
Data returned by read tools goes to the victim's own MCP client, so exfiltration needs a second step (for example prompt-injected text in the malicious project, or a report the agent saves back into the project and the user later commits). The write-through effect needs no second step: it changes a file on disk outside the project. In both cases the attacker must name the target path in advance via the symlink.
Suggested severity: High — an incorrect permission boundary that allows out-of-project file writes (and reads of KiCad designs) when a write-capable mode is used on an attacker-supplied project. It is not Critical in the default configuration (default mode is readonly, so only the read-through applies there) and it requires the user to open a crafted project, but the write-through crosses the documented "active project directory is the trusted I/O scope" boundary without consent. Final rating is yours.
Reproduction (write-through, the High finding)
cp -r <kicad>/demos/pic_programmer projand renameproj/pic_programmer.*→proj/board.*.- Put a schematic to be tampered with outside the project:
cp <some>.kicad_sch outside/victim.kicad_sch. - Replace the project's own schematic with a stem-named symlink to it:
rm proj/board.kicad_sch && ln -s ../outside/victim.kicad_sch proj/board.kicad_sch sha256sum outside/victim.kicad_sch(record it).- Start the server on
projin a write mode (e.g.--profile build --mode write),KICAD_MCP_WORKSPACE_ROOTunset, and callsch_add_symbol(orsch_update_properties) with nosheet_fileargument, so it targets the auto-selected active schematic. sha256sum outside/victim.kicad_schagain: it changed,proj/board.kicad_schis still a symlink, and the tool reported success naming…/outside/victim.kicad_schas the target.
Read-through (default profile) is the same setup with the symlink target carrying a recognisable symbol Value; sch_get_symbols returns it.
Workspace-root note
With KICAD_MCP_WORKSPACE_ROOT set to the project, kicad_get_project_info still returned normally in my test (it did not fail closed, and did not leak). I did not exercise a write under a set workspace root, so I cannot say whether the root reliably blocks the write-through. Please do not treat the workspace-root variable as a mitigation for this issue without confirming it; the fix below is independent of it.
Suggested fix (recommended)
In discovery, apply the existing confinement check — assert_within(project_dir or workspace_root, candidate.resolve()) — to every auto-discovered project, schematic and board file, skipping (or refusing) any candidate that resolves outside the root. This is the same check already enforced for explicit path arguments; the gap is only that auto-selected files bypass it. #969's stem preference does not close it, because a stem-named entry can itself be a symlink.