MCPcopy Create free account
hub / github.com/WJX20/claude-code / hasSuspiciousWindowsPathPattern

Function hasSuspiciousWindowsPathPattern

src/utils/permissions/filesystem.ts:537–602  ·  view source on GitHub ↗

* Detects suspicious Windows path patterns that could bypass security checks. * These patterns include: * - NTFS Alternate Data Streams (e.g., file.txt::$DATA or file.txt:stream) * - 8.3 short names (e.g., GIT~1, CLAUDE~1, SETTIN~1.JSON) * - Long path prefixes (e.g., \\?\C:\..., \\.\C:\..., //?/

(path: string)

Source from the content-addressed store, hash-verified

535 * @returns true if suspicious Windows path patterns are detected
536 */
537function hasSuspiciousWindowsPathPattern(path: string): boolean {
538 // Check for NTFS Alternate Data Streams
539 // Look for ':' after position 2 to skip drive letters (e.g., C:\)
540 // Examples: file.txt::$DATA, .bashrc:hidden, settings.json:stream
541 // Note: ADS colon syntax is only interpreted by the Windows kernel. On WSL,
542 // DrvFs mounts route file operations through the Windows kernel, so colon
543 // syntax is still interpreted as ADS separators. On Linux/macOS (non-WSL),
544 // even when NTFS is mounted, ADS is accessed via xattrs (ntfs-3g) not colon
545 // syntax, and colons are valid filename characters.
546 if (getPlatform() === 'windows' || getPlatform() === 'wsl') {
547 const colonIndex = path.indexOf(':', 2)
548 if (colonIndex !== -1) {
549 return true
550 }
551 }
552
553 // Check for 8.3 short names
554 // Look for '~' followed by a digit
555 // Examples: GIT~1, CLAUDE~1, SETTIN~1.JSON, BASHRC~1
556 if (/~\d/.test(path)) {
557 return true
558 }
559
560 // Check for long path prefixes (both backslash and forward slash variants)
561 // Examples: \\?\C:\Users\..., \\.\C:\..., //?/C:/..., //./C:/...
562 if (
563 path.startsWith('\\\\?\\') ||
564 path.startsWith('\\\\.\\') ||
565 path.startsWith('//?/') ||
566 path.startsWith('//./')
567 ) {
568 return true
569 }
570
571 // Check for trailing dots and spaces that Windows strips during path resolution
572 // Examples: .git., .claude , .bashrc..., settings.json.
573 // This can bypass string matching if ".git" is blocked but ".git." is used
574 if (/[.\s]+$/.test(path)) {
575 return true
576 }
577
578 // Check for DOS device names that Windows treats as special devices
579 // Examples: .git.CON, settings.json.PRN, .bashrc.AUX
580 // Device names: CON, PRN, AUX, NUL, COM1-9, LPT1-9
581 if (/\.(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$/i.test(path)) {
582 return true
583 }
584
585 // Check for three or more consecutive dots (...) when used as a path component
586 // This pattern can be used to bypass security checks or create confusion
587 // Examples: .../file.txt, path/.../file
588 // Only block when dots are preceded AND followed by path separators (/ or \)
589 // This allows legitimate uses like Next.js catch-all routes [...]name]
590 if (/(^|\/|\\)\.{3,}(\/|\\|$)/.test(path)) {
591 return true
592 }
593
594 // Check for UNC paths (on all platforms for defense-in-depth)

Callers 2

Calls 2

getPlatformFunction · 0.85

Tested by

no test coverage detected