Skip to content

Commit 3403e79

Browse files
atscottalxhub
authored andcommitted
fix(vscode-extension): restrict jsdoc markdown trust and harden document opening
Restrict JSDoc hover links to the custom openJSDocLink command and implement document opening using safe workspace APIs.
1 parent 4f4820f commit 3403e79

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
isNotTypescriptOrSupportedDecoratorField,
3232
isNotTypescriptOrSupportedDecoratorRange,
3333
} from './embedded_support';
34+
import {OpenJsDocLinkCommandId} from '../../common/initialize';
3435

3536
interface GetTcbResponse {
3637
uri: vscode.Uri;
@@ -96,7 +97,9 @@ export class AngularLanguageClient implements vscode.Disposable {
9697
revealOutputChannelOn: lsp.RevealOutputChannelOn.Never,
9798
outputChannel: this.outputChannel,
9899
markdown: {
99-
isTrusted: true,
100+
isTrusted: {
101+
enabledCommands: [OpenJsDocLinkCommandId],
102+
},
100103
},
101104
middleware: {
102105
provideCodeActions: async (

‎vscode-ng-language-service/client/src/commands.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,12 @@ function openJsDocLinkCommand(): Command<OpenJsDocLinkCommand_Args> {
189189
id: OpenJsDocLinkCommandId,
190190
isTextEditorCommand: false,
191191
async execute(args) {
192-
return await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(args.file), <
193-
vscode.TextDocumentShowOptions
194-
>{
192+
if (!args?.file) {
193+
return;
194+
}
195+
const uri = vscode.Uri.parse(args.file);
196+
const document = await vscode.workspace.openTextDocument(uri);
197+
return await vscode.window.showTextDocument(document, {
195198
selection: new vscode.Range(
196199
new vscode.Position(args.position?.start.line ?? 0, args.position?.start.character ?? 0),
197200
new vscode.Position(args.position?.end.line ?? 0, args.position?.end.character ?? 0),

0 commit comments

Comments
 (0)