fix(ssh): prevent port forwarding messages from polluting terminal output (#11664)

Co-authored-by: Eugene <inbox@null.page>
This commit is contained in:
osm1892andEugene authored and GitHub committed 2026-09-24 21:19:05 +02:00
1 parent 6193527bae
commit a64ae78bf4
5 files changed
+77 -22

No files matched your search

+7 -1
View File
@@ -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 => {
+26 -5
View File
@@ -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 ""
@@ -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())
}
}
}
+4 -1
View File
@@ -110,7 +110,10 @@ export class SSHTabComponent extends ConnectableTerminalTabComponent<SSHProfile>
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
}
}
+18 -11
View File
@@ -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<void> {