Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/filesystem/path-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ export function isPathWithinAllowedDirectories(absolutePath: string, allowedDire
return false;
}

// Reject Windows Alternate Data Streams (ADS) to prevent path validation bypasses
if (process.platform === 'win32' || path.sep === '\\') {
const firstColonIndex = normalizedPath.indexOf(':');
if (firstColonIndex !== -1) {
const hasMoreThanOneColon = normalizedPath.indexOf(':', firstColonIndex + 1) !== -1;
const isValidDriveColon = firstColonIndex === 1 && /^[A-Za-z]$/.test(normalizedPath[0]);
if (hasMoreThanOneColon || !isValidDriveColon) {
return false;
}
}
}

// Verify it's absolute after normalization
if (!path.isAbsolute(normalizedPath)) {
throw new Error('Path must be absolute after normalization');
Expand Down
Loading