fix(ssh): make POSIX relay wrapper survive csh/tcsh login shells (#8709)

Reconstruct remote POSIX commands with bounded printf arguments so non-POSIX SSH login shells can forward them without requiring remote base64. Preserve relay and system-SSH stdin, and centralize login-shell flag selection for csh/tcsh compatibility.\n\nValidated against real csh and tcsh OpenSSH targets with built-in and system SSH, including cold relay deployment, stdin upload, PTY I/O, file mutation, and reconnect.
This commit is contained in:
Haohan Lin
2026-07-15 02:38:40 -07:00
committed by GitHub
parent c12ade54d6
commit 190ed7d4ed
7 changed files with 198 additions and 18 deletions
@@ -272,6 +272,41 @@ describe('resolveRemoteNodePath', () => {
})
})
it('uses -c (not -lc) for a csh login shell, which rejects combined -lc', async () => {
// Why: csh/tcsh reject `-lc` and mis-handle `-l` here ("Bad : modifier",
// issue #8701), so the login-shell probe must drop to plain `-c`.
execCommandMock
.mockResolvedValueOnce('\n') // path probe: empty
.mockResolvedValueOnce('/bin/csh\n') // $SHELL
.mockResolvedValueOnce('/usr/local/bin/node\n')
.mockResolvedValueOnce('v20.0.0\n')
await expect(resolveRemoteNodePath(conn)).resolves.toBe('/usr/local/bin/node')
expect(execCommandMock).toHaveBeenNthCalledWith(3, conn, `'/bin/csh' -c 'command -v node'`, {
wrapCommand: false,
timeoutMs: 8_000
})
})
it('uses -c (not -lc) for a tcsh login shell', async () => {
execCommandMock
.mockResolvedValueOnce('\n') // path probe: empty
.mockResolvedValueOnce('/usr/bin/tcsh\n') // $SHELL
.mockResolvedValueOnce('/usr/local/bin/node\n')
.mockResolvedValueOnce('v20.0.0\n')
await expect(resolveRemoteNodePath(conn)).resolves.toBe('/usr/local/bin/node')
expect(execCommandMock).toHaveBeenNthCalledWith(
3,
conn,
`'/usr/bin/tcsh' -c 'command -v node'`,
{
wrapCommand: false,
timeoutMs: 8_000
}
)
})
// ── Failure ───────────────────────────────────────────────────────────
it('throws when both strategies find no usable node', async () => {