@@ -3,7 +3,7 @@ import path from "path";
33import { StringDecoder } from "string_decoder" ;
44import { createTwoFilesPatch } from "diff" ;
55import { minimatch } from "minimatch" ;
6- import { normalizePath , expandHome } from "./path-utils.js" ;
6+ import { normalizePathFormat , expandHome } from "./path-utils.js" ;
77import { isPathWithinAllowedDirectories } from "./path-validation.js" ;
88
99// Type definitions
@@ -75,7 +75,7 @@ function resolveRelativePathAgainstAllowedDirectories(
7575 // Try to resolve relative path against each allowed directory
7676 for ( const allowedDir of allowedDirectories ) {
7777 const candidate = path . resolve ( allowedDir , relativePath ) ;
78- const normalizedCandidate = normalizePath ( candidate ) ;
78+ const normalizedCandidate = normalizePathFormat ( candidate ) ;
7979
8080 // Check if the resulting path lies within any allowed directory
8181 if (
@@ -140,7 +140,9 @@ async function resolveUnicodeEquivalentPath(
140140 const allowedDirectory = [ ...allowedDirectories ]
141141 . sort ( ( left , right ) => right . length - left . length )
142142 . find ( ( directory ) =>
143- isPathWithinAllowedDirectories ( normalizePath ( absolutePath ) , [ directory ] ) ,
143+ isPathWithinAllowedDirectories ( normalizePathFormat ( absolutePath ) , [
144+ directory ,
145+ ] ) ,
144146 ) ;
145147
146148 /* v8 ignore next -- validatePath calls this only after the same allow-list check passed, so a containing directory always exists */
@@ -180,7 +182,7 @@ async function resolveUnicodeEquivalentPath(
180182 ) ;
181183 if (
182184 ! isPathWithinAllowedDirectories (
183- normalizePath ( currentPath ) ,
185+ normalizePathFormat ( currentPath ) ,
184186 allowedDirectories ,
185187 )
186188 ) {
@@ -219,12 +221,15 @@ export async function validatePath(
219221 allowedDirectories ,
220222 ) ;
221223 if (
222- ! isPathWithinAllowedDirectories ( normalizePath ( absolute ) , allowedDirectories )
224+ ! isPathWithinAllowedDirectories (
225+ normalizePathFormat ( absolute ) ,
226+ allowedDirectories ,
227+ )
223228 ) {
224229 absolute = respellAllowedDirectoryPrefix ( absolute , allowedDirectories ) ;
225230 }
226231
227- const normalizedRequested = normalizePath ( absolute ) ;
232+ const normalizedRequested = normalizePathFormat ( absolute ) ;
228233
229234 // Security: Check if path is within allowed directories before any file operations
230235 const isAllowed = isPathWithinAllowedDirectories (
@@ -243,7 +248,7 @@ export async function validatePath(
243248 // This prevents attackers from creating symlinks that point outside allowed directories
244249 try {
245250 const realPath = await fs . realpath ( absolute ) ;
246- const normalizedReal = normalizePath ( realPath ) ;
251+ const normalizedReal = normalizePathFormat ( realPath ) ;
247252 if ( ! isPathWithinAllowedDirectories ( normalizedReal , allowedDirectories ) ) {
248253 throw new Error (
249254 `Access denied - symlink target outside allowed directories: ${ realPath } not in ${ allowedDirectories . join ( ", " ) } ` ,
0 commit comments