diff --git a/tabby-linkifier/src/decorator.ts b/tabby-linkifier/src/decorator.ts index 50ae8a57a..3a414d13e 100644 --- a/tabby-linkifier/src/decorator.ts +++ b/tabby-linkifier/src/decorator.ts @@ -4,6 +4,14 @@ import { TerminalDecorator, BaseTerminalTabComponent, XTermFrontend } from 'tabb import { WebLinksAddon } from '@xterm/addon-web-links' import { LinkHandler } from './api' +function parseURL (uri: string): URL|null { + try { + return new URL(uri) + } catch { + return null + } +} + @Injectable() export class LinkHighlighterDecorator extends TerminalDecorator { constructor ( @@ -21,11 +29,22 @@ export class LinkHighlighterDecorator extends TerminalDecorator { } tab.frontend.xterm.options.linkHandler = { + allowNonHttpProtocols: true, activate: (event, uri) => { if (!this.willHandleEvent(event)) { return } - this.platform.openExternal(uri) + const url = parseURL(uri) + if (!url) { + return + } + // A file: URL with a host is a UNC path - opening it would reach out + // over SMB to a server the remote side chose. Only allow local files. + const isLocalFile = url.protocol === 'file:' && !url.host + if (!['http:', 'https:'].includes(url.protocol) && !isLocalFile) { + return + } + this.platform.openExternal(url.href) }, } @@ -38,6 +57,7 @@ export class LinkHighlighterDecorator extends TerminalDecorator { continue } handler.handle(await handler.convert(uri, tab), tab) + return } } diff --git a/tabby-linkifier/src/handlers.ts b/tabby-linkifier/src/handlers.ts index 17f2b524b..bb0db7027 100644 --- a/tabby-linkifier/src/handlers.ts +++ b/tabby-linkifier/src/handlers.ts @@ -93,7 +93,7 @@ export class UnixFileHandler extends BaseFileHandler { @Injectable() export class WindowsFileHandler extends BaseFileHandler { - regex = /(([a-zA-Z]:|\\|~)\\[\w\-()\\\.]{1,1024}|"([a-zA-Z]:|\\)\\[\w\s\-()\\\.]{1,1024}")/ + regex = /(([a-zA-Z]:|\\|~)[\\/][\w\-()\\/.]{1,1024}|"([a-zA-Z]:|\\)[\\/][\w\s\-()\\/.]{1,1024}")/ constructor ( protected toastr: ToastrService,