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
9 changes: 5 additions & 4 deletions src/filesystem/path-validation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path';
import { normalizePath } from './path-utils.js';

/**
* Checks if an absolute path is within any of the allowed directories.
Expand All @@ -24,10 +25,10 @@ export function isPathWithinAllowedDirectories(absolutePath: string, allowedDire
return false;
}

// Normalize the input path
// Normalize the input path using normalizePath to correctly handle UNC paths
let normalizedPath: string;
try {
normalizedPath = path.resolve(path.normalize(absolutePath));
normalizedPath = normalizePath(path.resolve(normalizePath(absolutePath)));
} catch {
return false;
}
Expand All @@ -48,10 +49,10 @@ export function isPathWithinAllowedDirectories(absolutePath: string, allowedDire
return false;
}

// Normalize the allowed directory
// Normalize the allowed directory using normalizePath to correctly handle UNC paths
let normalizedDir: string;
try {
normalizedDir = path.resolve(path.normalize(dir));
normalizedDir = normalizePath(path.resolve(normalizePath(dir)));
} catch {
return false;
}
Expand Down
Loading