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

Function containsVulnerableUncPath

src/utils/shell/readOnlyCommandValidation.ts:1562–1638  ·  view source on GitHub ↗
(pathOrCommand: string)

Source from the content-addressed store, hash-verified

1560 * @returns true if the path/command contains potentially vulnerable UNC paths
1561 */
1562export function containsVulnerableUncPath(pathOrCommand: string): boolean {
1563 // Only check on Windows platform
1564 if (getPlatform() !== 'windows') {
1565 return false
1566 }
1567
1568 // 1. Check for general UNC paths with backslashes
1569 // Pattern matches: \\server, \\server\share, \\server/share, \\server@port\share
1570 // Uses [^\s\\/]+ for hostname to catch Unicode homoglyphs and other non-ASCII chars
1571 // Trailing accepts both \ and / since Windows treats both as path separators
1572 const backslashUncPattern = /\\\\[^\s\\/]+(?:@(?:\d+|ssl))?(?:[\\/]|$|\s)/i
1573 if (backslashUncPattern.test(pathOrCommand)) {
1574 return true
1575 }
1576
1577 // 2. Check for forward-slash UNC paths
1578 // Pattern matches: //server, //server/share, //server\share, //192.168.1.1/share
1579 // Uses negative lookbehind (?<!:) to exclude URLs (https://, http://, ftp://)
1580 // while catching // preceded by quotes, =, or any other non-colon character.
1581 // Trailing accepts both / and \ since Windows treats both as path separators
1582 const forwardSlashUncPattern =
1583 // eslint-disable-next-line custom-rules/no-lookbehind-regex -- .test() on short command strings
1584 /(?<!:)\/\/[^\s\\/]+(?:@(?:\d+|ssl))?(?:[\\/]|$|\s)/i
1585 if (forwardSlashUncPattern.test(pathOrCommand)) {
1586 return true
1587 }
1588
1589 // 3. Check for mixed-separator UNC paths (forward slash + backslashes)
1590 // On Windows/Cygwin, /\ is equivalent to // since both are path separators.
1591 // In bash, /\\server becomes /\server after escape processing, which is a UNC path.
1592 // Requires 2+ backslashes after / because a single backslash just escapes the next char
1593 // (e.g., /\a → /a after bash processing, which is NOT a UNC path).
1594 const mixedSlashUncPattern = /\/\\{2,}[^\s\\/]/
1595 if (mixedSlashUncPattern.test(pathOrCommand)) {
1596 return true
1597 }
1598
1599 // 4. Check for mixed-separator UNC paths (backslashes + forward slash)
1600 // \\/server in bash becomes \/server after escape processing, which is a UNC path
1601 // on Windows since both \ and / are path separators.
1602 const reverseMixedSlashUncPattern = /\\{2,}\/[^\s\\/]/
1603 if (reverseMixedSlashUncPattern.test(pathOrCommand)) {
1604 return true
1605 }
1606
1607 // 5. Check for WebDAV SSL/port patterns
1608 // Examples: \\server@SSL@8443\path, \\server@8443@SSL\path
1609 if (/@SSL@\d+/i.test(pathOrCommand) || /@\d+@SSL/i.test(pathOrCommand)) {
1610 return true
1611 }
1612
1613 // 6. Check for DavWWWRoot marker (Windows WebDAV redirector)
1614 // Example: \\server\DavWWWRoot\path
1615 if (/DavWWWRoot/i.test(pathOrCommand)) {
1616 return true
1617 }
1618
1619 // 7. Check for UNC paths with IPv4 addresses (explicit check for defense-in-depth)

Callers 6

isCommandReadOnlyFunction · 0.85
checkReadOnlyConstraintsFunction · 0.85
validatePathFunction · 0.85

Calls 1

getPlatformFunction · 0.85

Tested by

no test coverage detected