Skip to content

Commit df68a96

Browse files
atscottalxhub
authored andcommitted
fix(vscode-extension): disable language server in untrusted workspaces
Restrict untrusted workspace support to limited mode. Skip launching the language client and registering commands in restricted mode, and only start them once workspace trust has been explicitly granted.
1 parent d8c871e commit df68a96

2 files changed

Lines changed: 32 additions & 18 deletions

File tree

vscode-ng-language-service/client/src/extension.ts

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,35 @@ import {shouldRestartOnConfigurationChange} from './config_change';
1414

1515
export function activate(context: vscode.ExtensionContext) {
1616
const client = new AngularLanguageClient(context);
17+
context.subscriptions.push(client);
1718

18-
// Push the disposable to the context's subscriptions so that the
19-
// client can be deactivated on extension deactivation
20-
registerCommands(client, context);
21-
22-
// Restart the server on configuration changes that affect startup/session state.
23-
const disposable = vscode.workspace.onDidChangeConfiguration(
24-
async (e: vscode.ConfigurationChangeEvent) => {
25-
if (!shouldRestartOnConfigurationChange(e)) {
26-
return;
27-
}
28-
await client.stop();
29-
await client.start();
30-
},
31-
);
32-
context.subscriptions.push(client, disposable);
33-
34-
client.start();
19+
const startServer = async () => {
20+
registerCommands(client, context);
21+
22+
// Restart the server on configuration changes that affect startup/session state.
23+
const disposable = vscode.workspace.onDidChangeConfiguration(
24+
async (e: vscode.ConfigurationChangeEvent) => {
25+
if (!shouldRestartOnConfigurationChange(e)) {
26+
return;
27+
}
28+
await client.stop();
29+
await client.start();
30+
},
31+
);
32+
context.subscriptions.push(disposable);
33+
34+
await client.start();
35+
};
36+
37+
// If the workspace is untrusted, operate in limited mode:
38+
// Do NOT start the language server or register commands.
39+
if (!vscode.workspace.isTrusted) {
40+
const trustDisposable = vscode.workspace.onDidGrantWorkspaceTrust(async () => {
41+
await startServer();
42+
});
43+
context.subscriptions.push(trustDisposable);
44+
return;
45+
}
46+
47+
startServer();
3548
}

vscode-ng-language-service/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
},
1717
"capabilities": {
1818
"untrustedWorkspaces": {
19-
"supported": true
19+
"supported": "limited",
20+
"description": "Angular language features are disabled in untrusted workspaces to prevent execution of untrusted local code."
2021
},
2122
"virtualWorkspaces": {
2223
"supported": "limited",

0 commit comments

Comments
 (0)