Summary
The move_file handler validates both its source and destination. For a same-device move, however, only the destination parent is pinned: renameIntoDirectory passes the source to fs.renameSync as an absolute string, which the kernel resolves at rename time — after validation. A local process that swaps a parent component of the source path for an outside-pointing symlink in that window causes the rename to move the outside file into the pinned destination inside the allowed directories, after which every read tool returns its contents: an out-of-bounds read achieved through move.
This is also an internal inconsistency in the component: the same operation's cross-device fallback (moveFileAcrossDevices) and copy_file both open the source through openSourceInDirectory — anchored at the source's own parent, lstat-checked, opened with O_NOFOLLOW, and identity-verified. Only the same-device rename leaves the source unpinned.
Details
Affected product / versions:
- Product: @modelcontextprotocol/server-filesystem (modelcontextprotocol/servers,
src/filesystem)
- Confirmed version: v2.2.0, monorepo commit
36380287ed3b15d115b55f546617d723072b1296
- Other versions: not verified. No claim is made about other versions.
Severity:
- Reporter's estimate (based on local reproduction against the real code, not a CNA assignment): CVSS v3.1 5.3 (Medium)
- Vector:
CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:L/A:N
- CWE (proposed): CWE-367 (Time-of-check Time-of-use (TOCTOU) Race Condition) — the source path is validated and then handed to
fs.renameSync as a string, which the kernel resolves at rename time; a component swapped in the window redirects the move. (The resulting escape from the restricted directory is of the CWE-22 class; the defect itself is the check-to-use race on the source, as in the read-path issue.)
- Justification: as with the read-path race in the same component, exploitation requires a cooperating local process with write access inside an allowed directory, winning the window between validation and the rename — hence local vector and high complexity. A successful swap moves an arbitrary outside file into the allowed set (confidentiality High once it is read back; integrity Low because the file is removed from its original location).
Details:
src/filesystem/pinned-directory.ts:325-336 (renameIntoDirectory), called from lib.ts:690-700 (moveFile); the handler validates the source at server.ts:909 and the destination at server.ts:913:
/**
* Rename `sourcePath` (absolute, outside this fix's scope) to the final
* component of `destinationPath`, relative to its anchored directory.
*/
export function renameIntoDirectory(
sourcePath: string,
destinationPath: string,
): void {
inDirectory(path.dirname(destinationPath), () =>
fs.renameSync(sourcePath, path.basename(destinationPath)),
);
}
- On the doc comment's "outside this fix's scope": we read that as a scoping note about the earlier pinning change, not as a security acceptance of this gap — the same operation's other two paths (cross-device move, copy) pin the source, which indicates the source side is within the component's own security model, and the comment predates any analysis of the rename resolving a swapped source. We raise it so the maintainers can judge; if the scope note was intended as acceptance, the inconsistency with the sibling paths is still worth recording.
- Mechanism: (1) both arguments validate; the source's realpath is inside the allowed set at that moment; (2)
moveFile requires the destination to be absent and calls renameIntoDirectory; (3) the destination parent is anchored via inDirectory, but the source string is resolved by the kernel at rename time; (4) a swapped source parent redirects the resolution outside; (5) the outside file lands inside the allowed set and becomes readable by all read tools. On POSIX the destination pin means the file always lands inside (import, not export). On Windows the destination anchor itself is the subject of a separate, statically-supported observation (write-path pinning is weakened there); any export form of this issue depends on that observation and is not claimed here.
Honest limitations:
- Reporter confidence in the underlying records is Low-to-Medium: the mechanism is code-certain and harness-reproduced, but exploitation needs the local-racer precondition and a won race window.
- The Windows export variant depends on a separate statically-supported observation about Windows write-path pinning that has not been dynamically verified on a Windows host; this report claims only the POSIX import form.
- No testing was performed against any third-party or production deployment.
Remediation direction:
Pin the source for the rename path as the sibling paths already do: open/anchor the source through openSourceInDirectory-equivalent machinery (anchored at the source's parent, identity-checked), or perform the rename relative to pinned directory handles for both ends (e.g. renameat-style with verified descriptors where the platform allows).
Reporter credit: Tomoki Murota, CISSP
Proof of concept
Reproduction was performed locally against the real server code with the same harness family used for the read-path race (mc1_filesystem/verify/): the source's parent component was swapped for an outside-pointing symlink in the window between the handler's validation and the rename, and the outside file was moved into the allowed directory and subsequently read through the server (evidence: mc1_filesystem/FINDINGS_A.md Candidate 4; the finding survived an independent adversarial review, which examined and rejected the "out of scope by design" reading on the grounds above).
Illustrative trigger: move_file {source: "/allowed/sub/important.conf", destination: "/allowed/stolen.conf"} with /allowed/sub swapped for a symlink to /etc in the window: /etc/important.conf is moved into the allowed set and becomes readable.
Impact
A file outside the allowed directories can be moved inside them and read in full (POSIX form). The operation also deletes the file from its original location. The client's own tools cannot set up the swap; the cooperating-local-process precondition is the same one the component's write-path pinning already assumes.
Summary
The
move_filehandler validates both its source and destination. For a same-device move, however, only the destination parent is pinned:renameIntoDirectorypasses the source tofs.renameSyncas an absolute string, which the kernel resolves at rename time — after validation. A local process that swaps a parent component of the source path for an outside-pointing symlink in that window causes the rename to move the outside file into the pinned destination inside the allowed directories, after which every read tool returns its contents: an out-of-bounds read achieved through move.This is also an internal inconsistency in the component: the same operation's cross-device fallback (
moveFileAcrossDevices) andcopy_fileboth open the source throughopenSourceInDirectory— anchored at the source's own parent, lstat-checked, opened withO_NOFOLLOW, and identity-verified. Only the same-device rename leaves the source unpinned.Details
Affected product / versions:
src/filesystem)36380287ed3b15d115b55f546617d723072b1296Severity:
CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:L/A:Nfs.renameSyncas a string, which the kernel resolves at rename time; a component swapped in the window redirects the move. (The resulting escape from the restricted directory is of the CWE-22 class; the defect itself is the check-to-use race on the source, as in the read-path issue.)Details:
src/filesystem/pinned-directory.ts:325-336(renameIntoDirectory), called fromlib.ts:690-700(moveFile); the handler validates the source atserver.ts:909and the destination atserver.ts:913:moveFilerequires the destination to be absent and callsrenameIntoDirectory; (3) the destination parent is anchored viainDirectory, but the source string is resolved by the kernel at rename time; (4) a swapped source parent redirects the resolution outside; (5) the outside file lands inside the allowed set and becomes readable by all read tools. On POSIX the destination pin means the file always lands inside (import, not export). On Windows the destination anchor itself is the subject of a separate, statically-supported observation (write-path pinning is weakened there); any export form of this issue depends on that observation and is not claimed here.Honest limitations:
Remediation direction:
Pin the source for the rename path as the sibling paths already do: open/anchor the source through
openSourceInDirectory-equivalent machinery (anchored at the source's parent, identity-checked), or perform the rename relative to pinned directory handles for both ends (e.g.renameat-style with verified descriptors where the platform allows).Reporter credit: Tomoki Murota, CISSP
Proof of concept
Reproduction was performed locally against the real server code with the same harness family used for the read-path race (
mc1_filesystem/verify/): the source's parent component was swapped for an outside-pointing symlink in the window between the handler's validation and the rename, and the outside file was moved into the allowed directory and subsequently read through the server (evidence:mc1_filesystem/FINDINGS_A.mdCandidate 4; the finding survived an independent adversarial review, which examined and rejected the "out of scope by design" reading on the grounds above).Illustrative trigger:
move_file {source: "/allowed/sub/important.conf", destination: "/allowed/stolen.conf"}with/allowed/subswapped for a symlink to/etcin the window:/etc/important.confis moved into the allowed set and becomes readable.Impact
A file outside the allowed directories can be moved inside them and read in full (POSIX form). The operation also deletes the file from its original location. The client's own tools cannot set up the swap; the cooperating-local-process precondition is the same one the component's write-path pinning already assumes.