{"slug": "a-folder-named-allow-dir-evil-passed-the-check-how-the-filesystem-mcp-server-got", "title": "A folder named allow_dir_evil passed the check. How the Filesystem MCP server got out of its allowed directory", "summary": "Cymulate researcher Elad Beber found two path-traversal flaws in Anthropic's reference Filesystem MCP server that let an agent escape its allowed directory without a memory bug: a startsWith() prefix check that accepted sibling folders like allow_dir_evil (CVE-2025-53110), and a catch block that swallowed the symlink-escape error and returned the link's own path (CVE-2025-53109). Both were fixed on 1 July 2025 in version 2025.7.1, which compares against the directory plus a separator, catches only ENOENT, and writes files with the wx flag plus a temp-file rename so symlinks are replaced rather than followed. Cymulate chained the two to read /etc/sudoers and, on macOS, write a LaunchAgents plist for code execution at next login.", "body_md": "The Filesystem MCP server is usually the first one people add. You give it a folder, and the agent can read and write inside that folder and nowhere else. In a web3 dev setup it matters more than most, because it runs as your user, and your user can read `~/.foundry/keystores` and `~/.ssh`.\n\nIn March 2025 Elad Beber at Cymulate found two ways out of that folder in Anthropic's reference server, the one in the `modelcontextprotocol/servers` repo. Both were fixed on 1 July 2025 in version 2025.7.1 and published as CVE-2025-53110 and CVE-2025-53109, which Cymulate calls EscapeRoute ([Cymulate's write-up](https://cymulate.com/blog/cve-2025-53109-53110-escaperoute-anthropic/)). Neither needed a memory bug. One was a `startsWith()`, the other a `catch` block.\n\nThis was the containment check before the fix:\n\n``` js\nconst isAllowed = allowedDirectories.some(dir => normalizedRequested.startsWith(dir));\n```\n\nWith `/private/tmp/allow_dir` allowed, `/private/tmp/allow_dir_evil` starts with the same string, so it passes. So does any sibling whose name extends the allowed one: `project-old` next to `project`, `app.bak` next to `app`. That's CVE-2025-53110.\n\n`../` doesn't get you out here. The server runs `path.resolve` on the request before the check, so `allow_dir/../../etc/passwd` becomes `/etc/passwd` and fails. The way out is a sibling with a longer name. The fix compares against the directory plus a separator, so the request has to start with `/private/tmp/allow_dir/` or be the directory itself ([commit d00c60d](https://github.com/modelcontextprotocol/servers/commit/d00c60df9d74dba8a3bb13113f8904407cda594f)).\n\nThe server did resolve symlinks. After the prefix check it ran `fs.realpath` and checked the real path too. The problem was the error handling around it (trimmed):\n\n``` js\ntry {\n  const realPath = await fs.realpath(absolute);\n  if (!allowedDirectories.some(dir => normalizePath(realPath).startsWith(dir))) {\n    throw new Error(\"Access denied - symlink target outside allowed directories\");\n  }\n  return realPath;\n} catch (error) {\n  // For new files that don't exist yet, verify parent directory\n  const parentDir = path.dirname(absolute);\n  // ...realpath(parentDir) passes the prefix check...\n  return absolute;\n}\n```\n\nThe `catch` was meant for files that don't exist yet. It caught every error, including the \"symlink target outside\" one thrown a few lines up. Then it checked the symlink's parent, which sits inside the allowed folder, and returned the symlink's own path. The tool then read or wrote through the link to wherever it pointed. That's CVE-2025-53109.\n\nCymulate chained the two: create `allow_dir_evil` (passes the prefix check), put `test -> /etc/sudoers` inside it, and ask the agent to read it. For code execution on macOS they pointed a symlink at a plist in `~/Library/LaunchAgents` and had the server write it, so their command ran at the next login.\n\nThe July 2025 fix catches only `ENOENT` and rethrows anything else. `write_file` started creating files with the `wx` flag, which fails if anything, a symlink included, already sits at that name, and otherwise wrote a temp file and renamed it over the name. A rename replaces the link instead of following it.\n\nThe server has no tool that creates a symlink. In Cymulate's demo a second local user made it in `/private/tmp`. On a developer machine the likelier source is whatever else writes into the folder you shared. Git checks out symlinks as real symlinks by default on macOS and Linux, and archives can carry them too. So on a version before 2025.7.1, if the allowed folder was a repo you cloned, the repo's author had a say in where the agent could reach. I wrote more about cloned repos in [Your repo is not trusted context](https://dev.to/bloqarl/your-repo-is-not-trusted-context-what-i-changed-after-giving-coding-agents-real-repositories-2ken).\n\nGitHub's advisories rate both CVEs 7.3 on CVSS 4.0, and Cymulate scored the symlink one 8.4. The number matters less than who the server runs as. It runs as you, so once the boundary fails it reaches what you can.\n\nIn October and November 2026 the same server got seven more [advisories](https://github.com/modelcontextprotocol/servers/security/advisories). Two repeat the 2025 mistake, a check run on one string and the operation on another:\n\n`/allowed/proj'`, a sibling of `/allowed/proj`, passed. Fixed in 2.0.1.` realpath`, and new files went through the link to outside the folder. Fixed in 2.0.1.\nFour are races. The server checked the resolved path and then used the path again by name, so a directory swapped for a symlink in between redirected the call. They hit the new-file fallback above ([GHSA-53mr-w429-c597](https://github.com/modelcontextprotocol/servers/security/advisories/GHSA-53mr-w429-c597), writes, fixed in 2.0.1), the source of `move_file` ([GHSA-7m4x-rv66-mxhh](https://github.com/modelcontextprotocol/servers/security/advisories/GHSA-7m4x-rv66-mxhh), fixed in 2.3.0), `read_text_file` ([GHSA-p9cv-8g75-4xcg](https://github.com/modelcontextprotocol/servers/security/advisories/GHSA-p9cv-8g75-4xcg), fixed in 2.3.0) and the listing tools ([GHSA-rq2p-q7c4-6g27](https://github.com/modelcontextprotocol/servers/security/advisories/GHSA-rq2p-q7c4-6g27), fixed in 2.4.0). Each needs a local process that can rename things inside the allowed folder while the server runs.\n\nThe last one needs less. `list_directory_with_sizes` ran `stat` on every entry, which follows symlinks, so a symlink already in the folder, like one that came with a cloned repo, leaked the size of a file outside it ([GHSA-hhwq-wxfx-cj7g](https://github.com/modelcontextprotocol/servers/security/advisories/GHSA-hhwq-wxfx-cj7g), fixed in 2.0.1).\n\nSince 2.4.0, on Linux and macOS, the server anchors reads, writes and listings to the directory it validated. Its README says it can't do that on Windows, where a process that can write in the folder can still win the race on a parent directory.\n\nThe package used date versions up to 2026.8.31 and then moved to plain version numbers. The 2026 advisories list no fix for the date line. And 2.4.1 is a lower version number than 2026.8.31, so a lockfile, an exact date pin or a `^2026.8.31` range never moves to it, and `npm update` won't either. If your client config or lockfile has a date version, change it by hand and pin the new one:\n\n```\n\"args\": [\"-y\", \"@modelcontextprotocol/server-filesystem@2.4.1\", \"/Users/me/code/my-project\"]\n```\n\n`--confine-roots` (2.2.0 and later). The server logs the effective directories to stderr at startup and on every change, so read that line once.`/tmp` and a repo you just cloned both have other writers. A folder only you and the agent write to removes the setup every one of these bugs needed.`node_modules` from its store. `get_file_info` reports a `hardLinks` count, and more than 1 means the file has other names.`--read-only` drops every write tool, and `--read-only-dir <path>` makes one folder read-only while the others stay writable.`openat2` with `RESOLVE_BENEATH` makes the kernel refuse a path that leaves a directory (Linux 5.6+), but Node's `fs` doesn't expose it, so for this server the boundary you can add sits outside it. The Docker image runs as the unprivileged `node` user and only sees the folders you mount under `/projects`, with `ro` on a mount for read-only. Mount the project folder, not your home directory.\n*Adapted from a piece our team published on [zealynx.io](https://www.zealynx.io/research/adversarial-security/escaperoute-anthropic-filesystem-mcp?utm_source=devto&utm_medium=article&utm_campaign=filesystem-mcp-escaperoute). This version corrects how both bypasses worked (`../` was resolved before the prefix check, and the symlink's real path was checked but the refusal was swallowed by the catch block), adds what the fix changed, the 2026 advisories, the version-line switch and the server's current options, and drops the OWASP mapping.*\n\n*I wrote this with help from AI for drafting and editing. The opinions and the audit experience are mine.*", "url": "https://wpnews.pro/news/a-folder-named-allow-dir-evil-passed-the-check-how-the-filesystem-mcp-server-got", "canonical_source": "https://dev.to/bloqarl/a-folder-named-allowdirevil-passed-the-check-how-the-filesystem-mcp-server-got-out-of-its-3a5e", "published_at": "2026-12-04 13:41:15+00:00", "updated_at": "2026-12-04 13:44:03.388918+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "ai-safety", "ai-tools"], "entities": ["Anthropic", "Cymulate", "Elad Beber", "Filesystem MCP server", "modelcontextprotocol/servers", "CVE-2025-53110", "CVE-2025-53109", "GitHub"], "also_reported_by": [], "takeaway": "Prefix checks on allowed directories must compare against the directory plus a path separator, and symlink-resolution error handlers must catch only ENOENT and rethrow everything else, or sibling folders like allow_dir_evil and symlinks to /etc/sudoers slip past containment.", "recommendation": {"advice": "Upgrade the Filesystem MCP server to 2025.7.1 or later, and audit any path-containment check to compare against the directory plus a separator and rethrow non-ENOENT errors from realpath.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/a-folder-named-allow-dir-evil-passed-the-check-how-the-filesystem-mcp-server-got", "markdown": "https://wpnews.pro/news/a-folder-named-allow-dir-evil-passed-the-check-how-the-filesystem-mcp-server-got.md", "text": "https://wpnews.pro/news/a-folder-named-allow-dir-evil-passed-the-check-how-the-filesystem-mcp-server-got.txt", "jsonld": "https://wpnews.pro/news/a-folder-named-allow-dir-evil-passed-the-check-how-the-filesystem-mcp-server-got.jsonld"}}