diff --git a/src/filesystem/__tests__/path-validation.test.ts b/src/filesystem/__tests__/path-validation.test.ts index 81ad247ee2..7c93a0915b 100644 --- a/src/filesystem/__tests__/path-validation.test.ts +++ b/src/filesystem/__tests__/path-validation.test.ts @@ -437,6 +437,10 @@ describe('Path Validation', () => { expect(isPathWithinAllowedDirectories('\\\\server\\share\\project\\file', allowed)).toBe(true); expect(isPathWithinAllowedDirectories('\\\\server\\share\\other', allowed)).toBe(false); expect(isPathWithinAllowedDirectories('\\\\other\\share\\project', allowed)).toBe(false); + + const shareRoot = ['\\\\server\\share\\']; + expect(isPathWithinAllowedDirectories('\\\\server\\share\\file.txt', shareRoot)).toBe(true); + expect(isPathWithinAllowedDirectories('\\\\server\\share-other\\file.txt', shareRoot)).toBe(false); } }); }); diff --git a/src/filesystem/path-validation.ts b/src/filesystem/path-validation.ts index 972e9c49d0..2ba947d428 100644 --- a/src/filesystem/path-validation.ts +++ b/src/filesystem/path-validation.ts @@ -81,6 +81,9 @@ export function isPathWithinAllowedDirectories(absolutePath: string, allowedDire return pathDrive === dirDrive && normalizedPath.startsWith(normalizedDir.replace(/\\?$/, '\\')); } - return normalizedPath.startsWith(normalizedDir + path.sep); + const normalizedDirWithSep = normalizedDir.endsWith(path.sep) + ? normalizedDir + : normalizedDir + path.sep; + return normalizedPath.startsWith(normalizedDirWithSep); }); }