Fix paste ownership, input bounds, and IPC validation

Supersedes #5745, #5746, and #5747.
This commit is contained in:
Jinwoo Hong
2026-06-19 17:14:55 -07:00
committed by GitHub
parent a5920b2183
commit 972078f2c4
592 changed files with 33303 additions and 3737 deletions
+7
View File
@@ -109,6 +109,7 @@ export class SshRelaySession {
private _onReady: ((targetId: string) => void) | null = null
private portScanner: PortScanner | null = null
private currentConnection: SshConnection | null = null
private hostPlatform: RemoteHostPlatform | null = null
private remoteCliBridgeEnv: RemoteCliBridgeEnv | null = null
constructor(
@@ -174,6 +175,10 @@ export class SshRelaySession {
return this.mux
}
getHostPlatform(): RemoteHostPlatform | null {
return this.remoteCliBridgeEnv?.hostPlatform ?? this.hostPlatform
}
getPortScanner(): PortScanner | null {
return this.portScanner
}
@@ -199,6 +204,7 @@ export class SshRelaySession {
try {
const { transport, remoteHome, remoteRelayDir, nodePath, sockPath, hostPlatform } =
await deployAndLaunchRelay(conn, undefined, graceTimeSeconds, this.targetId)
this.hostPlatform = hostPlatform ?? null
this.remoteCliBridgeEnv =
remoteHome && remoteRelayDir && nodePath && sockPath && hostPlatform
? {
@@ -325,6 +331,7 @@ export class SshRelaySession {
try {
const { transport, remoteHome, remoteRelayDir, nodePath, sockPath, hostPlatform } =
await deployAndLaunchRelay(conn, undefined, graceTimeSeconds, this.targetId)
this.hostPlatform = hostPlatform ?? null
this.remoteCliBridgeEnv =
remoteHome && remoteRelayDir && nodePath && sockPath && hostPlatform
? {
@@ -0,0 +1,70 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { SshConnection } from './ssh-connection'
const execCommandMock = vi.hoisted(() => vi.fn())
vi.mock('./ssh-relay-deploy-helpers', () => ({
execCommand: execCommandMock
}))
const { detectRemoteHostPlatform } = await import('./ssh-remote-platform-detection')
const conn = {} as SshConnection
describe('detectRemoteHostPlatform', () => {
beforeEach(() => {
execCommandMock.mockReset()
})
it('detects POSIX hosts from uname output', async () => {
execCommandMock.mockResolvedValueOnce('Linux x86_64\n')
await expect(detectRemoteHostPlatform(conn)).resolves.toMatchObject({
relayPlatform: 'linux-x64',
os: 'linux',
arch: 'x64',
pathFlavor: 'posix'
})
expect(execCommandMock).toHaveBeenCalledWith(conn, 'uname -sm')
})
it('falls back to PowerShell detection for Windows remotes', async () => {
execCommandMock
.mockRejectedValueOnce(new Error('uname unavailable'))
.mockResolvedValueOnce('Windows AMD64\r\n')
await expect(detectRemoteHostPlatform(conn)).resolves.toMatchObject({
relayPlatform: 'win32-x64',
os: 'win32',
arch: 'x64',
pathFlavor: 'windows'
})
expect(execCommandMock).toHaveBeenNthCalledWith(
2,
conn,
expect.stringContaining('powershell.exe'),
{ wrapCommand: false }
)
})
it('returns null when neither probe yields a supported platform', async () => {
execCommandMock.mockResolvedValueOnce('Linux').mockResolvedValueOnce('FreeBSD x86_64')
await expect(detectRemoteHostPlatform(conn)).resolves.toBeNull()
})
it('does not use whitespace regex splitting for remote platform output', async () => {
const splitSpy = vi.spyOn(String.prototype, 'split')
execCommandMock.mockResolvedValueOnce('Darwin arm64 extra')
await expect(detectRemoteHostPlatform(conn)).resolves.toMatchObject({
relayPlatform: 'darwin-arm64'
})
const usedWhitespaceFieldSplit = splitSpy.mock.calls.some(
([separator]) => separator instanceof RegExp && separator.source.includes('\\s+')
)
splitSpy.mockRestore()
expect(usedWhitespaceFieldSplit).toBe(false)
})
})
@@ -1,4 +1,5 @@
import type { SshConnection } from './ssh-connection'
import { getProcessOutputFields } from '../../shared/process-output-field-scanner'
import { parseUnameToRelayPlatform, type RelayPlatform } from './relay-protocol'
import { execCommand } from './ssh-relay-deploy-helpers'
import { getRemoteHostPlatform, type RemoteHostPlatform } from './ssh-remote-platform'
@@ -18,7 +19,7 @@ export async function detectRemoteHostPlatform(
async function detectUnamePlatform(conn: SshConnection): Promise<RelayPlatform | null> {
try {
const output = await execCommand(conn, 'uname -sm')
const parts = output.trim().split(/\s+/)
const parts = getProcessOutputFields(output, 2)
if (parts.length < 2) {
return null
}
@@ -37,7 +38,7 @@ async function detectWindowsPlatform(conn: SshConnection): Promise<RelayPlatform
'Write-Output ("Windows " + $arch)'
].join('; ')
const output = await execCommand(conn, powerShellCommand(script), { wrapCommand: false })
const parts = output.trim().split(/\s+/)
const parts = getProcessOutputFields(output, 2)
if (parts.length < 2 || parts[0].toLowerCase() !== 'windows') {
return null
}