Skip to content

Commit aef8fd7

Browse files
authored
Merge pull request #5568 from modelcontextprotocol/v2/docs/5566-filesystem-windows-swap-limit
docs(filesystem): document the Windows parent-directory swap as a limit of the implementation
2 parents 94b1b56 + 8d932c7 commit aef8fd7

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎src/filesystem/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ The server's directory access control follows this flow:
127127
- Server requires at least ONE allowed directory to operate
128128
- On Windows, a path naming an NTFS alternate data stream (`file.txt:stream`, `file.txt::$DATA`) is refused with "Access denied - NTFS alternate data stream paths are not supported", even inside an allowed directory: a colon is accepted only as a drive letter's (`C:\`, `\\?\C:\`). A stream holds data that no directory listing or diff of the file shows. On macOS and Linux a colon is an ordinary file-name character and is not refused
129129
- On Windows, a path any of whose components is a reserved device name (`CON`, `PRN`, `AUX`, `NUL`, `COM1`-`COM9`, `LPT1`-`LPT9`, in any case and with or without an extension, such as `NUL.txt`) is refused with "Access denied - Windows reserved device names ... are not supported", and one any of whose components ends in a dot or a space (`file.txt.`, `dir \file.txt`) with "Access denied - Windows path components ending in a dot or a space are not supported". Windows opens the device rather than a file in the directory, and strips trailing dots and spaces so the name refers to a different file. `.` and `..` are not affected. On macOS and Linux these are ordinary file names and are not refused
130+
- **Limit on Windows: a parent directory swapped during an operation.** A path is checked and then used, and a directory on it could be replaced in between. On Linux and macOS the server anchors every write, and every read of a file's content or metadata, to the directory it validated, so a directory replaced with a symlink after the check cannot redirect the operation. **On Windows it cannot do that, and the operation is not protected**: a second local process that can already write inside an allowed directory can replace a parent directory with a junction (or a directory symlink) between the server's check and its open, and so redirect a read or a write outside the allowed directories. The server still checks the final component there (a write refuses a symlink or junction at the file's own name, and the file opened must be the one the directory holds at that name afterwards), which narrows the window without closing it
131+
- **What it takes**: a concurrent local process with write access inside an allowed directory, winning a race against the server. No tool of this server creates a junction or a symlink, so it cannot be set up through the server alone
132+
- **Guidance**: on Windows, do not allow a directory that untrusted local processes or users can write to
133+
- **Why it is not fixed**: closing the window needs opens relative to a directory handle, which Node does not expose, so it would take native code, and that is out of scope for a reference server ([#5260](https://github.com/modelcontextprotocol/servers/issues/5260)). It may be revisited when Node ships a stable built-in FFI under this package's `engines` floor
130134
131135
**Note**: The server will only allow operations within directories specified either via `args` or, for a 2025-era client, via Roots.
132136

‎src/filesystem/pinned-directory.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
// against it, so reading it back proves nothing; there the leaf is lstat'd
2727
// relative to the anchor and must be the file the descriptor opened, which
2828
// narrows the race without closing it.
29+
// That gap is a decided limit of the implementation, not pending work:
30+
// closing it needs handle-relative opens, so native code (#5260, closed as
31+
// not planned). The README states it for users, under "Access Control".
2932

3033
import { randomBytes } from "crypto";
3134
import fs from "fs";

0 commit comments

Comments
 (0)