diff --git a/src/vs/platform/terminal/common/terminal.ts b/src/vs/platform/terminal/common/terminal.ts index db1052de0e013..fd8e698e99111 100644 --- a/src/vs/platform/terminal/common/terminal.ts +++ b/src/vs/platform/terminal/common/terminal.ts @@ -95,6 +95,7 @@ export const enum TerminalSettingId { WindowsEnableConpty = 'terminal.integrated.windowsEnableConpty', WordSeparators = 'terminal.integrated.wordSeparators', EnableFileLinks = 'terminal.integrated.enableFileLinks', + AllowedLinkSchemes = 'terminal.integrated.allowedLinkSchemes', UnicodeVersion = 'terminal.integrated.unicodeVersion', LocalEchoLatencyThreshold = 'terminal.integrated.localEchoLatencyThreshold', LocalEchoEnabled = 'terminal.integrated.localEchoEnabled', diff --git a/src/vs/workbench/contrib/terminal/common/terminal.ts b/src/vs/workbench/contrib/terminal/common/terminal.ts index 328e43673216d..a2c8e2a804ed1 100644 --- a/src/vs/workbench/contrib/terminal/common/terminal.ts +++ b/src/vs/workbench/contrib/terminal/common/terminal.ts @@ -176,6 +176,7 @@ export interface ITerminalConfiguration { windowsEnableConpty: boolean; wordSeparators: string; enableFileLinks: 'off' | 'on' | 'notRemote'; + allowedLinkSchemes: string[]; unicodeVersion: '6' | '11'; localEchoLatencyThreshold: number; localEchoExcludePrograms: ReadonlyArray; diff --git a/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts b/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts index 630cc865a1a10..c325d2fb8360b 100644 --- a/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts +++ b/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts @@ -489,6 +489,21 @@ const terminalConfiguration: IConfigurationNode = { ], default: 'on' }, + [TerminalSettingId.AllowedLinkSchemes]: { + description: localize('terminal.integrated.allowedLinkSchemes', "An array of strings containing the URI schemes that the terminal is allowed to open links for. By default, only a small subset of possible schemes are allowed for security reasons."), + type: 'array', + items: { + type: 'string' + }, + default: [ + 'file', + 'http', + 'https', + 'mailto', + 'vscode', + 'vscode-insiders', + ] + }, [TerminalSettingId.UnicodeVersion]: { type: 'string', enum: ['6', '11'], diff --git a/src/vs/workbench/contrib/terminalContrib/links/browser/terminalLinkManager.ts b/src/vs/workbench/contrib/terminalContrib/links/browser/terminalLinkManager.ts index 5d8f803de511d..6936d959fde35 100644 --- a/src/vs/workbench/contrib/terminalContrib/links/browser/terminalLinkManager.ts +++ b/src/vs/workbench/contrib/terminalContrib/links/browser/terminalLinkManager.ts @@ -20,7 +20,7 @@ import { TerminalLocalFileLinkOpener, TerminalLocalFolderInWorkspaceLinkOpener, import { TerminalLocalLinkDetector } from 'vs/workbench/contrib/terminalContrib/links/browser/terminalLocalLinkDetector'; import { TerminalUriLinkDetector } from 'vs/workbench/contrib/terminalContrib/links/browser/terminalUriLinkDetector'; import { TerminalWordLinkDetector } from 'vs/workbench/contrib/terminalContrib/links/browser/terminalWordLinkDetector'; -import { ITerminalExternalLinkProvider, TerminalLinkQuickPickEvent } from 'vs/workbench/contrib/terminal/browser/terminal'; +import { ITerminalConfigurationService, ITerminalExternalLinkProvider, TerminalLinkQuickPickEvent } from 'vs/workbench/contrib/terminal/browser/terminal'; import { ILinkHoverTargetOptions, TerminalHover } from 'vs/workbench/contrib/terminal/browser/widgets/terminalHoverWidget'; import { TerminalWidgetManager } from 'vs/workbench/contrib/terminal/browser/widgets/widgetManager'; import { IXtermCore } from 'vs/workbench/contrib/terminal/browser/xterm-private'; @@ -53,6 +53,7 @@ export class TerminalLinkManager extends DisposableStore { capabilities: ITerminalCapabilityStore, private readonly _linkResolver: ITerminalLinkResolver, @IConfigurationService private readonly _configurationService: IConfigurationService, + @ITerminalConfigurationService private readonly _termninalConfigurationService: ITerminalConfigurationService, @IInstantiationService private readonly _instantiationService: IInstantiationService, @ITerminalLogService private readonly _logService: ITerminalLogService, @ITunnelService private readonly _tunnelService: ITunnelService @@ -99,7 +100,21 @@ export class TerminalLinkManager extends DisposableStore { activeTooltipScheduler?.dispose(); })); this._xterm.options.linkHandler = { - activate: (_, text) => { + allowNonHttpProtocols: true, + activate: (event, text) => { + if (!this._isLinkActivationModifierDown(event)) { + return; + } + // TODO: Support arbitrary schemes + const colonIndex = text.indexOf(':'); + if (colonIndex === -1) { + throw new Error(`Could not find scheme in link "${text}"`); + } + const scheme = text.substring(0, colonIndex); + if (this._termninalConfigurationService.config.allowedLinkSchemes.indexOf(scheme) === -1) { + // TODO: Notification with config + throw new Error('Scheme not allowed'); + } this._openers.get(TerminalBuiltinLinkType.Url)?.open({ type: TerminalBuiltinLinkType.Url, text,