From a64ae78bf48d32fb37740a4545de8a34794aa655 Mon Sep 17 00:00:00 2001 From: osm1892 Date: Fri, 25 Sep 2026 04:19:05 +0900 Subject: [PATCH] fix(ssh): prevent port forwarding messages from polluting terminal output (#11664) Co-authored-by: Eugene --- app/src/plugins.ts | 8 ++++- locale/app.pot | 31 ++++++++++++++++--- .../sshPortForwardingModal.component.ts | 26 +++++++++++++--- tabby-ssh/src/components/sshTab.component.ts | 5 ++- tabby-ssh/src/session/ssh.ts | 29 ++++++++++------- 5 files changed, 77 insertions(+), 22 deletions(-) diff --git a/app/src/plugins.ts b/app/src/plugins.ts index 3a082418b..d4a0df3b3 100644 --- a/app/src/plugins.ts +++ b/app/src/plugins.ts @@ -83,7 +83,13 @@ export function initModuleLookup (userPluginsPath: string): void { process.env.TABBY_PLUGINS.split(':').map(x => paths.push(normalizePath(x))) } - process.env.NODE_PATH += path.delimiter + paths.join(path.delimiter) + // An inherited NODE_PATH (e.g. Tabby leaks its own into the shells it spawns, + // so a dev build started from a Tabby terminal would load the installed app's + // builtin plugins instead of the working copy) must never take precedence. + const inheritedNodePath = (process.env.NODE_PATH ?? '') + .split(path.delimiter) + .filter(x => x && x !== 'undefined') + process.env.NODE_PATH = [...paths, ...inheritedNodePath].join(path.delimiter) nodeModule._initPaths() builtinModules.forEach(m => { diff --git a/locale/app.pot b/locale/app.pot index aa67a234f..940e113c7 100644 --- a/locale/app.pot +++ b/locale/app.pot @@ -148,7 +148,7 @@ msgid "Connect to \"%s\"..." msgstr "" #: tabby-serial/src/components/serialTab.component.ts:60 -#: tabby-ssh/src/components/sshTab.component.ts:138 +#: tabby-ssh/src/components/sshTab.component.ts:141 #: tabby-telnet/src/components/telnetTab.component.ts:54 msgid "Connecting" msgstr "" @@ -190,6 +190,10 @@ msgstr "" msgid "Could not decrypt config" msgstr "" +#: tabby-ssh/src/components/sshTab.component.ts:114 +msgid "Could not set up port forward on {host}" +msgstr "" + #: tabby-ssh/src/sftpContextMenu.ts:30 msgid "Create directory" msgstr "" @@ -258,7 +262,7 @@ msgstr "" msgid "Delete vault contents?" msgstr "" -#: tabby-ssh/src/components/sshTab.component.ts:226 +#: tabby-ssh/src/components/sshTab.component.ts:229 #: tabby-telnet/src/components/telnetTab.component.ts:83 #: tabby-terminal/src/api/connectableTerminalTab.component.ts:36 #: tabby-terminal/src/tabContextMenu.ts:106 @@ -270,7 +274,7 @@ msgstr "" msgid "Disconnect current tab (Serial/Telnet/SSH)" msgstr "" -#: tabby-ssh/src/components/sshTab.component.ts:224 +#: tabby-ssh/src/components/sshTab.component.ts:227 #: tabby-telnet/src/components/telnetTab.component.ts:81 msgid "Disconnect from {host}?" msgstr "" @@ -279,7 +283,7 @@ msgstr "" msgid "Do not abort" msgstr "" -#: tabby-ssh/src/components/sshTab.component.ts:227 +#: tabby-ssh/src/components/sshTab.component.ts:230 #: tabby-telnet/src/components/telnetTab.component.ts:84 msgid "Do not close" msgstr "" @@ -346,6 +350,15 @@ msgstr "" msgid "Export to file" msgstr "" +#: tabby-ssh/src/components/sshPortForwardingModal.component.ts:28 +#: tabby-ssh/src/session/ssh.ts:506 +msgid "Failed to forward port {fw}" +msgstr "" + +#: tabby-ssh/src/components/sshPortForwardingModal.component.ts:38 +msgid "Failed to stop forwarding {fw}" +msgstr "" + #: tabby-settings/src/components/vaultSettingsTab.component.ts:103 msgid "File: {description}" msgstr "" @@ -426,6 +439,10 @@ msgstr "" msgid "Force LF" msgstr "" +#: tabby-ssh/src/components/sshPortForwardingModal.component.ts:26 +msgid "Forwarded {fw}" +msgstr "" + #: tabby-core/src/utils.ts:62 msgid "Green" msgstr "" @@ -1066,6 +1083,10 @@ msgstr "" msgid "SSH password for {user}@{host}:{port}" msgstr "" +#: tabby-ssh/src/components/sshPortForwardingModal.component.ts:36 +msgid "Stopped forwarding {fw}" +msgstr "" + #: tabby-terminal/src/components/streamProcessingSettings.component.ts:52 msgid "Strip" msgstr "" @@ -1177,7 +1198,7 @@ msgstr "" msgid "User default" msgstr "" -#: tabby-ssh/src/session/ssh.ts:692 +#: tabby-ssh/src/session/ssh.ts:701 msgid "Using saved password" msgstr "" diff --git a/tabby-ssh/src/components/sshPortForwardingModal.component.ts b/tabby-ssh/src/components/sshPortForwardingModal.component.ts index 3cbe36349..f7a1da4d2 100644 --- a/tabby-ssh/src/components/sshPortForwardingModal.component.ts +++ b/tabby-ssh/src/components/sshPortForwardingModal.component.ts @@ -1,5 +1,7 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker' import { Component, Input } from '@angular/core' +import { NotificationsService, TranslateService } from 'tabby-core' import { ForwardedPort } from '../session/forwards' import { SSHSession } from '../session/ssh' import { ForwardedPortConfig } from '../api' @@ -11,13 +13,29 @@ import { ForwardedPortConfig } from '../api' export class SSHPortForwardingModalComponent { @Input() session: SSHSession - onForwardAdded (fw: ForwardedPortConfig) { + constructor ( + private notifications: NotificationsService, + private translate: TranslateService, + ) { } + + async onForwardAdded (fw: ForwardedPortConfig) { const newForward = new ForwardedPort() Object.assign(newForward, fw) - this.session.addPortForward(newForward) + try { + await this.session.addPortForward(newForward) + this.notifications.info(this.translate.instant(_('Forwarded {fw}'), { fw: newForward.toString() })) + } catch (e) { + this.notifications.error(this.translate.instant(_('Failed to forward port {fw}'), { fw: newForward.toString() }), e.toString()) + } } - onForwardRemoved (fw: ForwardedPortConfig) { - this.session.removePortForward(fw as ForwardedPort) + async onForwardRemoved (fwConfig: ForwardedPortConfig) { + const fw = fwConfig as ForwardedPort + try { + await this.session.removePortForward(fw) + this.notifications.notice(this.translate.instant(_('Stopped forwarding {fw}'), { fw: fw.toString() })) + } catch (e) { + this.notifications.error(this.translate.instant(_('Failed to stop forwarding {fw}'), { fw: fw.toString() }), e.toString()) + } } } diff --git a/tabby-ssh/src/components/sshTab.component.ts b/tabby-ssh/src/components/sshTab.component.ts index 61e9a1eb1..d6cb5e12d 100644 --- a/tabby-ssh/src/components/sshTab.component.ts +++ b/tabby-ssh/src/components/sshTab.component.ts @@ -110,7 +110,10 @@ export class SSHTabComponent extends ConnectableTerminalTabComponent originatorPort: 0, }) } catch (err) { - jumpSession.emitServiceMessage(colors.bgRed.black(' X ') + ` Could not set up port forward on ${jumpConnection.name}`) + this.notifications.error( + this.translate.instant(_('Could not set up port forward on {host}'), { host: jumpConnection.name }), + err.toString(), + ) throw err } } diff --git a/tabby-ssh/src/session/ssh.ts b/tabby-ssh/src/session/ssh.ts index 640d4847c..cce6446b5 100644 --- a/tabby-ssh/src/session/ssh.ts +++ b/tabby-ssh/src/session/ssh.ts @@ -3,6 +3,7 @@ import * as crypto from 'crypto' import colors from 'ansi-colors' import stripAnsi from 'strip-ansi' import * as shellQuote from 'shell-quote' +import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker' import { Injector } from '@angular/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { ConfigService, FileProvidersService, NotificationsService, PromptModalComponent, LogService, Logger, TranslateService, Platform, HostAppService } from 'tabby-core' @@ -498,8 +499,14 @@ export class SSHSession { this.passwordStorage.savePassword(this.profile, this.savedPassword, this.authUsername ?? undefined) } - for (const fw of this.profile.options.forwardedPorts) { - this.addPortForward(Object.assign(new ForwardedPort(), fw)) + for (const fwConfig of this.profile.options.forwardedPorts) { + const fw = Object.assign(new ForwardedPort(), fwConfig) + this.addPortForward(fw).catch(e => { + this.notifications.error( + this.translate.instant(_('Failed to forward port {fw}'), { fw: fw.toString() }), + e.toString(), + ) + }) } this.open = true @@ -524,7 +531,7 @@ export class SSHSession { socket.connect(forward.targetPort, forward.targetAddress) socket.on('error', e => { // eslint-disable-next-line @typescript-eslint/no-base-to-string - this.emitServiceMessage(colors.bgRed.black(' X ') + ` Could not forward the remote connection to ${forward.targetAddress}:${forward.targetPort}: ${e}`) + this.logger.warn(`Could not forward the remote connection to ${forward.targetAddress}:${forward.targetPort}: ${e}`) channel.close() }) @@ -818,7 +825,7 @@ export class SSHSession { originatorAddress: sourceAddress ?? '127.0.0.1', originatorPort: sourcePort ?? 0, }).catch(err => { - this.emitServiceMessage(colors.bgRed.black(' X ') + ` Remote has rejected the forwarded connection to ${targetAddress}:${targetPort} via ${fw}: ${err}`) + this.logger.warn(`Remote has rejected the forwarded connection to ${targetAddress}:${targetPort} via ${fw}: ${err}`) reject() throw err })) @@ -826,10 +833,10 @@ export class SSHSession { this.setupSocketChannelEvents(channel, socket, 'Local forward') }).then(() => { - this.emitServiceMessage(colors.bgGreen.black(' -> ') + ` Forwarded ${fw}`) + this.logger.info(`Forwarded ${fw}`) this.forwardedPorts.push(fw) }).catch(e => { - this.emitServiceMessage(colors.bgRed.black(' X ') + ` Failed to forward port ${fw}: ${e}`) + this.logger.error(`Failed to forward port ${fw}: ${e}`) throw e }) } @@ -841,10 +848,10 @@ export class SSHSession { await this.ssh.forwardTCPPort(fw.host, fw.port) } catch (err) { // eslint-disable-next-line @typescript-eslint/no-base-to-string - this.emitServiceMessage(colors.bgRed.black(' X ') + ` Remote rejected port forwarding for ${fw}: ${err}`) - return + this.logger.error(`Remote rejected port forwarding for ${fw}: ${err}`) + throw err } - this.emitServiceMessage(colors.bgGreen.black(' <- ') + ` Forwarded ${fw}`) + this.logger.info(`Forwarded ${fw}`) this.forwardedPorts.push(fw) } } @@ -858,10 +865,10 @@ export class SSHSession { if (!(this.ssh instanceof russh.AuthenticatedSSHClient)) { throw new Error('Cannot remove remote port forward before auth') } - this.ssh.stopForwardingTCPPort(fw.host, fw.port) + await this.ssh.stopForwardingTCPPort(fw.host, fw.port) this.forwardedPorts = this.forwardedPorts.filter(x => x !== fw) } - this.emitServiceMessage(`Stopped forwarding ${fw}`) + this.logger.info(`Stopped forwarding ${fw}`) } async destroy (): Promise {