diff --git a/extensions/json-language-features/client/src/jsonClient.ts b/extensions/json-language-features/client/src/jsonClient.ts index 44d13c211f1..35fbb3da59d 100644 --- a/extensions/json-language-features/client/src/jsonClient.ts +++ b/extensions/json-language-features/client/src/jsonClient.ts @@ -392,7 +392,7 @@ async function startClientWithParticipants(_context: ExtensionContext, languageP } catch (e) { throw new ResponseError(2, e.toString(), e); } - } else if (schemaDownloadEnabled) { + } else if (schemaDownloadEnabled && workspace.isTrusted) { if (runtime.telemetry && uri.authority === 'schema.management.azure.com') { /* __GDPR__ "json.schema" : { @@ -409,6 +409,9 @@ async function startClientWithParticipants(_context: ExtensionContext, languageP throw new ResponseError(4, e.toString()); } } else { + if (!workspace.isTrusted) { + throw new ResponseError(1, l10n.t('Downloading schemas is disabled in untrusted workspaces')); + } throw new ResponseError(1, l10n.t('Downloading schemas is disabled through setting \'{0}\'', SettingIds.enableSchemaDownload)); } }); @@ -533,6 +536,7 @@ async function startClientWithParticipants(_context: ExtensionContext, languageP client.sendNotification(DidChangeConfigurationNotification.type, { settings: getSettings() }); } })); + toDispose.push(workspace.onDidGrantWorkspaceTrust(updateSchemaDownloadSetting)); toDispose.push(createLanguageStatusItem(documentSelector, (uri: string) => client.sendRequest(LanguageStatusRequest.type, uri))); @@ -569,6 +573,11 @@ async function startClientWithParticipants(_context: ExtensionContext, languageP } function updateSchemaDownloadSetting() { + if (!workspace.isTrusted) { + schemaResolutionErrorStatusBarItem.tooltip = l10n.t('Unable to download schemas in untrusted workspaces.'); + schemaResolutionErrorStatusBarItem.command = 'workbench.trust.manage'; + return; + } schemaDownloadEnabled = workspace.getConfiguration().get(SettingIds.enableSchemaDownload) !== false; if (schemaDownloadEnabled) { schemaResolutionErrorStatusBarItem.tooltip = l10n.t('Unable to resolve schema. Click to retry.'); diff --git a/extensions/json-language-features/package.json b/extensions/json-language-features/package.json index 6e6b43a2b53..322e508b93e 100644 --- a/extensions/json-language-features/package.json +++ b/extensions/json-language-features/package.json @@ -24,7 +24,8 @@ "capabilities": { "virtualWorkspaces": true, "untrustedWorkspaces": { - "supported": true + "supported": "limited", + "description": "%json.workspaceTrust%" } }, "scripts": { diff --git a/extensions/json-language-features/package.nls.json b/extensions/json-language-features/package.nls.json index af6c9d87773..abc07c993dc 100644 --- a/extensions/json-language-features/package.nls.json +++ b/extensions/json-language-features/package.nls.json @@ -18,5 +18,7 @@ "json.maxItemsExceededInformation.desc": "Show notification when exceeding the maximum number of outline symbols and folding regions.", "json.enableSchemaDownload.desc": "When enabled, JSON schemas can be fetched from http and https locations.", "json.command.clearCache": "Clear Schema Cache", - "json.command.sort": "Sort Document" + "json.command.sort": "Sort Document", + "json.workspaceTrust": "The extension requires workspace trust to load schemas from http and https." + }