File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -173,6 +173,13 @@ describe('Lib Functions', () => {
173173
174174 describe ( 'Security & Validation Functions' , ( ) => {
175175 describe ( 'validatePath' , ( ) => {
176+ it ( 'rejects Windows drive paths on POSIX hosts' , async ( ) => {
177+ if ( process . platform === 'win32' ) return ;
178+
179+ await expect ( validatePath ( 'C:\\Users\\me\\notes\\file.md' ) )
180+ . rejects . toThrow ( 'Windows-style path received on a POSIX host' ) ;
181+ } ) ;
182+
176183 // Use Windows-compatible paths for testing
177184 const allowedDirs = process . platform === 'win32' ? [ 'C:\\Users\\test' , 'C:\\temp' ] : [ '/home/user' , '/tmp' ] ;
178185
Original file line number Diff line number Diff line change @@ -139,6 +139,12 @@ async function resolveUnicodeEquivalentPath(absolutePath: string): Promise<strin
139139
140140export async function validatePath ( requestedPath : string ) : Promise < string > {
141141 const expandedPath = expandHome ( requestedPath ) ;
142+ // Do not silently reinterpret a Windows drive path as a relative POSIX path.
143+ // This would create a literal filename such as `C:\\Users\\...` inside the
144+ // allowed root and report success for the wrong location.
145+ if ( process . platform !== 'win32' && / ^ (?: [ A - Z a - z ] : ) (?: [ \\ / ] | $ ) / . test ( expandedPath ) ) {
146+ throw new Error ( `Access denied - Windows-style path received on a POSIX host: ${ requestedPath } ` ) ;
147+ }
142148 const absolute = path . isAbsolute ( expandedPath )
143149 ? path . resolve ( expandedPath )
144150 : resolveRelativePathAgainstAllowedDirectories ( expandedPath ) ;
You can’t perform that action at this time.
0 commit comments