Skip to content

Commit 17e46e2

Browse files
authored
move dynamic security settings contrib to after restore (microsoft#203947) (microsoft#204111)
1 parent 9f0b82e commit 17e46e2

File tree

3 files changed

+56
-38
lines changed

3 files changed

+56
-38
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import { Registry } from 'vs/platform/registry/common/platform';
77
import { localize } from 'vs/nls';
88
import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
99
import { isMacintosh, isWindows, isLinux, isWeb, isNative } from 'vs/base/common/platform';
10-
import { ConfigurationMigrationWorkbenchContribution, DynamicWorkbenchConfigurationWorkbenchContribution, IConfigurationMigrationRegistry, workbenchConfigurationNodeBase, Extensions, ConfigurationKeyValuePairs, problemsConfigurationNodeBase } from 'vs/workbench/common/configuration';
10+
import { ConfigurationMigrationWorkbenchContribution, DynamicWorkbenchSecurityConfiguration, IConfigurationMigrationRegistry, workbenchConfigurationNodeBase, Extensions, ConfigurationKeyValuePairs, problemsConfigurationNodeBase } from 'vs/workbench/common/configuration';
1111
import { isStandalone } from 'vs/base/browser/browser';
12-
import { IWorkbenchContributionsRegistry, WorkbenchContributionInstantiation, Extensions as WorkbenchExtensions, registerWorkbenchContribution2 } from 'vs/workbench/common/contributions';
13-
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
12+
import { WorkbenchContributionInstantiation, registerWorkbenchContribution2 } from 'vs/workbench/common/contributions';
1413
import { ActivityBarPosition, EditorActionsLocation, EditorTabsMode, LayoutSettings } from 'vs/workbench/services/layout/browser/layoutService';
1514

1615
const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
@@ -19,10 +18,10 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
1918
(function registerConfiguration(): void {
2019

2120
// Migration support
22-
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(ConfigurationMigrationWorkbenchContribution, LifecyclePhase.Eventually);
21+
registerWorkbenchContribution2(ConfigurationMigrationWorkbenchContribution.ID, ConfigurationMigrationWorkbenchContribution, WorkbenchContributionInstantiation.Eventually);
2322

2423
// Dynamic Configuration
25-
registerWorkbenchContribution2(DynamicWorkbenchConfigurationWorkbenchContribution.ID, DynamicWorkbenchConfigurationWorkbenchContribution, WorkbenchContributionInstantiation.BlockRestore);
24+
registerWorkbenchContribution2(DynamicWorkbenchSecurityConfiguration.ID, DynamicWorkbenchSecurityConfiguration, WorkbenchContributionInstantiation.AfterRestored);
2625

2726
// Workbench
2827
registry.registerConfiguration({

src/vs/workbench/common/configuration.ts

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteA
1515
import { OperatingSystem, isWindows } from 'vs/base/common/platform';
1616
import { URI } from 'vs/base/common/uri';
1717
import { equals } from 'vs/base/common/objects';
18+
import { DeferredPromise } from 'vs/base/common/async';
1819

1920
export const applicationConfigurationNodeBase = Object.freeze<IConfigurationNode>({
2021
'id': 'application',
@@ -76,6 +77,8 @@ Registry.add(Extensions.ConfigurationMigration, configurationMigrationRegistry);
7677

7778
export class ConfigurationMigrationWorkbenchContribution extends Disposable implements IWorkbenchContribution {
7879

80+
static readonly ID = 'workbench.contrib.configurationMigration';
81+
7982
constructor(
8083
@IConfigurationService private readonly configurationService: IConfigurationService,
8184
@IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService,
@@ -165,47 +168,60 @@ export class ConfigurationMigrationWorkbenchContribution extends Disposable impl
165168
}
166169
}
167170

168-
export class DynamicWorkbenchConfigurationWorkbenchContribution extends Disposable implements IWorkbenchContribution {
171+
export class DynamicWorkbenchSecurityConfiguration extends Disposable implements IWorkbenchContribution {
172+
173+
static readonly ID = 'workbench.contrib.dynamicWorkbenchSecurityConfiguration';
169174

170-
static readonly ID = 'workbench.contrib.dynamicWorkbenchConfiguration';
175+
private readonly _ready = new DeferredPromise<void>();
176+
readonly ready = this._ready.p;
171177

172178
constructor(
173-
@IRemoteAgentService remoteAgentService: IRemoteAgentService
179+
@IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService
174180
) {
175181
super();
176182

177-
(async () => {
178-
if (!isWindows) {
179-
const remoteEnvironment = await remoteAgentService.getEnvironment();
180-
if (remoteEnvironment?.os !== OperatingSystem.Windows) {
181-
return;
182-
}
183+
this.create();
184+
}
185+
186+
private async create(): Promise<void> {
187+
try {
188+
await this.doCreate();
189+
} finally {
190+
this._ready.complete();
191+
}
192+
}
193+
194+
private async doCreate(): Promise<void> {
195+
if (!isWindows) {
196+
const remoteEnvironment = await this.remoteAgentService.getEnvironment();
197+
if (remoteEnvironment?.os !== OperatingSystem.Windows) {
198+
return;
183199
}
200+
}
184201

185-
// Windows: UNC allow list security configuration
186-
const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
187-
registry.registerConfiguration({
188-
...securityConfigurationNodeBase,
189-
'properties': {
190-
'security.allowedUNCHosts': {
191-
'type': 'array',
192-
'items': {
193-
'type': 'string',
194-
'pattern': '^[^\\\\]+$',
195-
'patternErrorMessage': localize('security.allowedUNCHosts.patternErrorMessage', 'UNC host names must not contain backslashes.')
196-
},
197-
'default': [],
198-
'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.'),
199-
'scope': ConfigurationScope.MACHINE
202+
// Windows: UNC allow list security configuration
203+
const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
204+
registry.registerConfiguration({
205+
...securityConfigurationNodeBase,
206+
'properties': {
207+
'security.allowedUNCHosts': {
208+
'type': 'array',
209+
'items': {
210+
'type': 'string',
211+
'pattern': '^[^\\\\]+$',
212+
'patternErrorMessage': localize('security.allowedUNCHosts.patternErrorMessage', 'UNC host names must not contain backslashes.')
200213
},
201-
'security.restrictUNCAccess': {
202-
'type': 'boolean',
203-
'default': true,
204-
'markdownDescription': localize('security.restrictUNCAccess', 'If enabled, only allows 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.'),
205-
'scope': ConfigurationScope.MACHINE
206-
}
214+
'default': [],
215+
'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.'),
216+
'scope': ConfigurationScope.MACHINE
217+
},
218+
'security.restrictUNCAccess': {
219+
'type': 'boolean',
220+
'default': true,
221+
'markdownDescription': localize('security.restrictUNCAccess', 'If enabled, only allows 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.'),
222+
'scope': ConfigurationScope.MACHINE
207223
}
208-
});
209-
})();
224+
}
225+
});
210226
}
211227
}

src/vs/workbench/electron-sandbox/window.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ import { IHostService } from 'vs/workbench/services/host/browser/host';
7777
import { IStatusbarService, ShowTooltipCommand, StatusbarAlignment } from 'vs/workbench/services/statusbar/browser/statusbar';
7878
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
7979
import { ThemeIcon } from 'vs/base/common/themables';
80+
import { getWorkbenchContribution } from 'vs/workbench/common/contributions';
81+
import { DynamicWorkbenchSecurityConfiguration } from 'vs/workbench/common/configuration';
8082

8183
export class NativeWindow extends BaseWindow {
8284

@@ -301,7 +303,7 @@ export class NativeWindow extends BaseWindow {
301303
});
302304

303305
// Allow to update security settings around allowed UNC Host
304-
ipcRenderer.on('vscode:configureAllowedUNCHost', (event: unknown, host: string) => {
306+
ipcRenderer.on('vscode:configureAllowedUNCHost', async (event: unknown, host: string) => {
305307
if (!isWindows) {
306308
return; // only supported on Windows
307309
}
@@ -320,6 +322,7 @@ export class NativeWindow extends BaseWindow {
320322
if (!allowedUncHosts.has(host)) {
321323
allowedUncHosts.add(host);
322324

325+
await getWorkbenchContribution<DynamicWorkbenchSecurityConfiguration>(DynamicWorkbenchSecurityConfiguration.ID).ready; // ensure this setting is registered
323326
this.configurationService.updateValue('security.allowedUNCHosts', [...allowedUncHosts.values()], ConfigurationTarget.USER);
324327
}
325328
});

0 commit comments

Comments
 (0)