Case-folding in normalizePath can bypass allowedDirectories on case-sensitive filesystems
Summary
allowedDirectories path checks currently lowercase paths on every platform:
function normalizePath(p: string): string {
return path.normalize(expandHome(p)).toLowerCase();
}On case-sensitive filesystems (e.g. typical Linux filesystems, or case-sensitive macOS volumes), two distinct directories can therefore compare as the same path. This can make a path outside an allowed directory pass isPathAllowed().
I understand that allowedDirectories is documented as a guardrail rather than a full sandbox, and terminal commands are intentionally outside that boundary. This report is specifically about the filesystem tools' own allowlist behaving incorrectly on case-sensitive filesystems.
Example
Suppose both of these directories exist on Linux:
/tmp/DC-Allow
/tmp/dc-allowand the config contains:
{
"allowedDirectories": ["/tmp/DC-Allow"]
}A request for:
/tmp/dc-allow/secret.txtis first resolved with realpath(), but the subsequent allowlist comparison lowercases both values:
/tmp/DC-Allow -> /tmp/dc-allow
/tmp/dc-allow/secret.txt -> /tmp/dc-allow/secret.txtso this check becomes true:
normalizedPathToCheck.startsWith(normalizedAllowedDir + path.sep)even though /tmp/DC-Allow and /tmp/dc-allow are different directories on a case-sensitive filesystem.
Relevant code
src/tools/filesystem.ts:
function normalizePath(p: string): string {
return path.normalize(expandHome(p)).toLowerCase();
}and later:
const subdirCheck = normalizedPathToCheck.startsWith(
normalizedAllowedDir + path.sep
);The current realpath() / symlink handling does not prevent this, because case folding happens after canonicalization during the allowlist comparison.
Impact
Filesystem tools using validatePath() may read/write/list a different same-spelling-but-different-case directory that was not actually included in allowedDirectories.
This is separate from the documented fact that terminal/interpreter execution can bypass filesystem guardrails.
Suggested fix
Only perform case folding on platforms/filesystems where path comparison is known to be case-insensitive. At minimum, avoid unconditional .toLowerCase() on POSIX.
For example, a simple platform-level improvement would be conceptually:
function normalizePath(p: string): string {
const normalized = path.normalize(expandHome(p));
return process.platform === 'win32'
? normalized.toLowerCase()
: normalized;
}A filesystem-aware solution would be even more accurate for case-sensitive Windows directories or case-sensitive macOS volumes.
Regression test
On a case-sensitive filesystem:
- Create
/tmp/DC-Allowand/tmp/dc-allow. - Allow only
/tmp/DC-Allow. - Verify that
validatePath("/tmp/DC-Allow/file")is allowed. - Verify that
validatePath("/tmp/dc-allow/file")is rejected.
Source: wonderwhy-er/DesktopCommanderMCP