51
return Array.from(allowedUNCHosts);
52
}
54
>
export function getUNCHost(maybeUNCPath: string | undefined | null): string | undefined {
55
>
if (typeof maybeUNCPath !== 'string') {
56
>
return undefined; // require a valid string
57
>
}
58
>
59
>
const uncRoots = [
60
>
'\\\\.\\UNC\\', // DOS Device paths (https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats)
61
>
'\\\\?\\UNC\\',
62
>
'\\\\' // standard UNC path
63
>
];
64
>
65
>
let host = undefined;
66
>
67
>
for (const uncRoot of uncRoots) {
68
>
const indexOfUNCRoot = maybeUNCPath.indexOf(uncRoot);
69
>
if (indexOfUNCRoot !== 0) {
70
>
continue; // not matching any of our expected UNC roots
71
>
}
72
>
73
>
const indexOfUNCPath = maybeUNCPath.indexOf('\\', uncRoot.length);
74
>
if (indexOfUNCPath === -1) {
75
>
continue; // no path component found
76
>
}
77
>
78
>
const hostCandidate = maybeUNCPath.substring(uncRoot.length, indexOfUNCPath);
79
>
if (hostCandidate) {
80
>
host = hostCandidate;
81
>
break;
82
>
}
83
>
}
84
>
85
>
return host;
86
>
}
87
>
88
>
export function disableUNCAccessRestrictions(): void {
89
if (process.platform !== 'win32') {
90
return;