Skip to content

Commit b4a2a00

Browse files
authored
Allow to disable UNC access restrictions (fix microsoft#182055) (microsoft#182755)
1 parent 578c3f0 commit b4a2a00

File tree

7 files changed

+48
-9
lines changed

7 files changed

+48
-9
lines changed

src/vs/base/node/unc.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ export function getUNCHostAllowlist(): string[];
1717
* Adds one to many UNC host(s) to the allowed list in node.js.
1818
*/
1919
export function addUNCHostToAllowlist(allowedHost: string | string[]): void;
20+
21+
/**
22+
* Disables UNC Host allow list in node.js and thus disables UNC
23+
* path validation.
24+
*/
25+
export function disableUNCAccessRestrictions(): void;

src/vs/base/node/unc.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,19 @@
109109
return host;
110110
}
111111

112+
function disableUNCAccessRestrictions() {
113+
if (process.platform !== 'win32') {
114+
return;
115+
}
116+
117+
process.enableUNCAccessChecks = false;
118+
}
119+
112120
return {
113121
getUNCHostAllowlist,
114122
addUNCHostToAllowlist,
115-
getUNCHost
123+
getUNCHost,
124+
disableUNCAccessRestrictions
116125
};
117126
}
118127

src/vs/code/electron-main/app.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { app, BrowserWindow, dialog, protocol, session, Session, systemPreferences, WebFrameMain } from 'electron';
7-
import { addUNCHostToAllowlist } from 'vs/base/node/unc';
7+
import { addUNCHostToAllowlist, disableUNCAccessRestrictions } from 'vs/base/node/unc';
88
import { validatedIpcMain } from 'vs/base/parts/ipc/electron-main/ipcMain';
99
import { hostname, release } from 'os';
1010
import { VSBuffer } from 'vs/base/common/buffer';
@@ -320,7 +320,11 @@ export class CodeApplication extends Disposable {
320320
//#region UNC Host Allowlist (Windows)
321321

322322
if (isWindows) {
323-
addUNCHostToAllowlist(this.configurationService.getValue('security.allowedUNCHosts'));
323+
if (this.configurationService.getValue('security.restrictUNCAccess') === false) {
324+
disableUNCAccessRestrictions();
325+
} else {
326+
addUNCHostToAllowlist(this.configurationService.getValue('security.allowedUNCHosts'));
327+
}
324328
}
325329

326330
//#endregion

src/vs/server/node/remoteExtensionHostAgentCli.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { ExtensionsProfileScannerService } from 'vs/platform/extensionManagement
4949
import { LogService } from 'vs/platform/log/common/logService';
5050
import { LoggerService } from 'vs/platform/log/node/loggerService';
5151
import { localize } from 'vs/nls';
52-
import { addUNCHostToAllowlist } from 'vs/base/node/unc';
52+
import { addUNCHostToAllowlist, disableUNCAccessRestrictions } from 'vs/base/node/unc';
5353

5454
class CliMain extends Disposable {
5555

@@ -72,7 +72,11 @@ class CliMain extends Disposable {
7272

7373
// On Windows, configure the UNC allow list based on settings
7474
if (isWindows) {
75-
addUNCHostToAllowlist(configurationService.getValue('security.allowedUNCHosts'));
75+
if (configurationService.getValue('security.restrictUNCAccess') === false) {
76+
disableUNCAccessRestrictions();
77+
} else {
78+
addUNCHostToAllowlist(configurationService.getValue('security.allowedUNCHosts'));
79+
}
7680
}
7781

7882
try {

src/vs/server/node/remoteExtensionHostAgentServer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { createRegExp, escapeRegExpCharacters } from 'vs/base/common/strings';
2323
import { URI } from 'vs/base/common/uri';
2424
import { generateUuid } from 'vs/base/common/uuid';
2525
import { findFreePort } from 'vs/base/node/ports';
26-
import { addUNCHostToAllowlist } from 'vs/base/node/unc';
26+
import { addUNCHostToAllowlist, disableUNCAccessRestrictions } from 'vs/base/node/unc';
2727
import { PersistentProtocol } from 'vs/base/parts/ipc/common/ipc.net';
2828
import { NodeSocket, WebSocketNodeSocket } from 'vs/base/parts/ipc/node/ipc.net';
2929
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -719,7 +719,11 @@ export async function createServer(address: string | net.AddressInfo | null, arg
719719
const configurationService = accessor.get(IConfigurationService);
720720

721721
if (platform.isWindows) {
722-
addUNCHostToAllowlist(configurationService.getValue('security.allowedUNCHosts'));
722+
if (configurationService.getValue('security.restrictUNCAccess') === false) {
723+
disableUNCAccessRestrictions();
724+
} else {
725+
addUNCHostToAllowlist(configurationService.getValue('security.allowedUNCHosts'));
726+
}
723727
}
724728
});
725729

src/vs/workbench/browser/workbench.contribution.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,13 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
704704
'markdownDescription': localize('security.allowedUNCHosts', 'A set of UNC host names (without leading or trailing backslash, for example `192.168.0.1` or `my-server`) to allow without user confirmation. If a UNC host is being accessed that is not allowed via this setting or has not been acknowledged via user confirmation, an error will occur and the operation stopped. A restart is required when changing this setting. Find out more about this setting at https://aka.ms/vscode-windows-unc.'),
705705
'included': isWeb ? true /* web maybe connected to a windows machine */ : isWindows,
706706
'scope': ConfigurationScope.MACHINE
707+
},
708+
'security.restrictUNCAccess': {
709+
'type': 'boolean',
710+
'default': true,
711+
'markdownDescription': localize('security.restrictUNCAccess', 'If enabled, only allowes access to UNC host names that are allowed by the `#security.allowedUNCHosts#` setting or after user confirmation. Find out more about this setting at https://aka.ms/vscode-windows-unc.'),
712+
'included': isWeb ? true /* web maybe connected to a windows machine */ : isWindows,
713+
'scope': ConfigurationScope.MACHINE
707714
}
708715
}
709716
});

src/vs/workbench/contrib/relauncher/browser/relauncher.contribution.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface IConfiguration extends IWindowsConfiguration {
2525
update?: { mode?: string };
2626
debug?: { console?: { wordWrap?: boolean } };
2727
editor?: { accessibilitySupport?: 'on' | 'off' | 'auto' };
28-
security?: { workspace?: { trust?: { enabled?: boolean } } };
28+
security?: { workspace?: { trust?: { enabled?: boolean } }; restrictUNCAccess?: boolean };
2929
window: IWindowSettings & { experimental?: { windowControlsOverlay?: { enabled?: boolean } } };
3030
workbench?: { enableExperiments?: boolean };
3131
_extensionsGallery?: { enablePPE?: boolean };
@@ -43,7 +43,8 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
4343
'editor.accessibilitySupport',
4444
'security.workspace.trust.enabled',
4545
'workbench.enableExperiments',
46-
'_extensionsGallery.enablePPE'
46+
'_extensionsGallery.enablePPE',
47+
'security.restrictUNCAccess'
4748
];
4849

4950
private readonly titleBarStyle = new ChangeObserver<'native' | 'custom'>('string');
@@ -56,6 +57,7 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
5657
private readonly workspaceTrustEnabled = new ChangeObserver('boolean');
5758
private readonly experimentsEnabled = new ChangeObserver('boolean');
5859
private readonly enablePPEExtensionsGallery = new ChangeObserver('boolean');
60+
private readonly restrictUNCAccess = new ChangeObserver('boolean');
5961

6062
constructor(
6163
@IHostService private readonly hostService: IHostService,
@@ -112,6 +114,9 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
112114

113115
// Workspace trust
114116
processChanged(this.workspaceTrustEnabled.handleChange(config?.security?.workspace?.trust?.enabled));
117+
118+
// UNC host access restrictions
119+
processChanged(this.restrictUNCAccess.handleChange(config?.security?.restrictUNCAccess));
115120
}
116121

117122
// Experiments

0 commit comments

Comments
 (0)