|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | import * as path from 'path'; |
4 | | -import { window, Uri, workspace, WorkspaceConfiguration, commands, ConfigurationTarget, env, ExtensionContext, TextEditor, Range, Disposable } from 'vscode'; |
| 4 | +import { window, Uri, workspace, WorkspaceConfiguration, commands, ConfigurationTarget, env, ExtensionContext, TextEditor, Range, Disposable, WorkspaceFolder } from 'vscode'; |
5 | 5 | import { Commands } from './commands'; |
6 | 6 | import { getJavaConfiguration } from './utils'; |
7 | 7 |
|
@@ -141,11 +141,12 @@ export async function checkJavaPreferences(context: ExtensionContext) { |
141 | 141 | } |
142 | 142 | const vmargs = workspace.getConfiguration().inspect('java.jdt.ls.vmargs').workspaceValue; |
143 | 143 | if (vmargs !== undefined) { |
| 144 | + const isWorkspaceTrusted = (workspace as any).isTrusted; // keep compatibility for old engines < 1.56.0 |
144 | 145 | const agentFlag = getJavaagentFlag(vmargs); |
145 | | - if (agentFlag !== null) { |
| 146 | + if (agentFlag !== null && (isWorkspaceTrusted === undefined || !isWorkspaceTrusted)) { |
146 | 147 | const keyVmargs = getKey(IS_WORKSPACE_VMARGS_ALLOWED, context.storagePath, vmargs); |
147 | 148 | const vmargsVerified = globalState.get(keyVmargs); |
148 | | - if (vmargsVerified === undefined || vmargsVerified === null) { |
| 149 | + if ((vmargsVerified === undefined || vmargsVerified === null) && (workspace.workspaceFolders && isInWorkspaceFolder(agentFlag, workspace.workspaceFolders))) { |
149 | 150 | await window.showErrorMessage(`Security Warning! The java.jdt.ls.vmargs variable defined in ${env.appName} settings includes the (${agentFlag}) javagent preference. Do you allow it to be used?`, disallow, allow).then(async selection => { |
150 | 151 | if (selection === allow) { |
151 | 152 | globalState.update(keyVmargs, true); |
@@ -187,6 +188,10 @@ export function getJavaagentFlag(vmargs) { |
187 | 188 | return agentFlag; |
188 | 189 | } |
189 | 190 |
|
| 191 | +export function isInWorkspaceFolder(loc: string, workspaceFolders: readonly WorkspaceFolder[]) { |
| 192 | + return !path.isAbsolute(loc) || workspaceFolders.some(dir => loc.startsWith(dir.uri.fsPath)); |
| 193 | +} |
| 194 | + |
190 | 195 | export enum ServerMode { |
191 | 196 | STANDARD = 'Standard', |
192 | 197 | LIGHTWEIGHT = 'LightWeight', |
|
0 commit comments