Skip to content

Commit 545d0ce

Browse files
committed
Fix
1 parent 4ad2453 commit 545d0ce

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/utils/security.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,10 @@ function pathIsAbsolute(p: string): boolean {
227227
* @returns true if the path uses UNC extended-length syntax
228228
*/
229229
export function isWindowsUncExtendedPath(p: string): boolean {
230-
if (process.platform !== 'win32') {
231-
return false;
232-
}
230+
// Check for Windows UNC extended-length paths on all platforms
231+
// This is defense-in-depth - reject dangerous path patterns regardless of server OS
233232
// Match \\?\ or \\.\ prefixes (extended-length path prefixes)
234-
// Character class [?.] matches literal ? or . characters
233+
// In regex: \\\\ matches \\, [?.] matches ? or ., \\ matches \
235234
return /^\\\\[?.]\\/.test(p);
236235
}
237236

tests/unit/security.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,11 @@ describe('Security Utilities', () => {
209209
expect(isWindowsUncExtendedPath('\\\\server\\share')).toBe(false);
210210
});
211211

212-
it('should return false on non-Windows platforms', () => {
212+
it('should detect UNC paths on all platforms (defense-in-depth)', () => {
213213
Object.defineProperty(process, 'platform', { value: 'linux' });
214-
expect(isWindowsUncExtendedPath('\\\\?\\C:\\Windows')).toBe(false);
214+
// UNC extended paths should be detected regardless of platform
215+
expect(isWindowsUncExtendedPath('\\\\?\\C:\\Windows')).toBe(true);
216+
// Regular Unix paths should not match
215217
expect(isWindowsUncExtendedPath('/usr/bin')).toBe(false);
216218
});
217219
});

0 commit comments

Comments
 (0)