Skip to content

Commit b094865

Browse files
authored
Clarify that simple browser only supports http and https uris (#571)
Fixes microsoft/vscode#261082
1 parent 40230ab commit b094865

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@
703703
"properties": {
704704
"url": {
705705
"type": "string",
706-
"description": "The website URL to preview or open in the Simple Browser inside the editor."
706+
"description": "The website URL to preview or open in the Simple Browser inside the editor. Must be either an http or https URL"
707707
}
708708
},
709709
"required": [

src/extension/tools/node/simpleBrowserTool.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as l10n from '@vscode/l10n';
77
import type * as vscode from 'vscode';
88
import { IRunCommandExecutionService } from '../../../platform/commands/common/runCommandExecutionService';
99
import { ResourceSet } from '../../../util/vs/base/common/map';
10+
import { Schemas } from '../../../util/vs/base/common/network';
1011
import { URI } from '../../../util/vs/base/common/uri';
1112
import { LanguageModelTextPart, LanguageModelToolResult, MarkdownString } from '../../../vscodeTypes';
1213
import { IBuildPromptContext } from '../../prompt/common/intents';
@@ -27,7 +28,8 @@ export class SimpleBrowserTool implements ICopilotTool<ISimpleBrowserParams> {
2728
) { }
2829

2930
async invoke(options: vscode.LanguageModelToolInvocationOptions<ISimpleBrowserParams>, token: vscode.CancellationToken) {
30-
this._alreadyApprovedDomains.add(URI.parse(options.input.url));
31+
const uri = URI.parse(options.input.url);
32+
this._alreadyApprovedDomains.add(uri);
3133
this.commandService.executeCommand('simpleBrowser.show', options.input.url);
3234
return new LanguageModelToolResult([
3335
new LanguageModelTextPart(
@@ -41,7 +43,12 @@ export class SimpleBrowserTool implements ICopilotTool<ISimpleBrowserParams> {
4143
}
4244

4345
prepareInvocation(options: vscode.LanguageModelToolInvocationPrepareOptions<ISimpleBrowserParams>, token: vscode.CancellationToken): vscode.ProviderResult<vscode.PreparedToolInvocation> {
44-
const urlsNeedingConfirmation = !this._alreadyApprovedDomains.has(URI.parse(options.input.url));
46+
const uri = URI.parse(options.input.url);
47+
if (uri.scheme !== Schemas.http && uri.scheme !== Schemas.https) {
48+
throw new Error(l10n.t('Invalid URL scheme. Only HTTP and HTTPS are supported.'));
49+
}
50+
51+
const urlsNeedingConfirmation = !this._alreadyApprovedDomains.has(uri);
4552
let confirmationMessages: vscode.LanguageModelToolConfirmationMessages | undefined;
4653
if (urlsNeedingConfirmation) {
4754
confirmationMessages = { title: l10n.t`Open untrusted web page?`, message: new MarkdownString(l10n.t`${options.input.url}`) };

0 commit comments

Comments
 (0)