diff --git a/docker/coolify-terminal/terminal-server.js b/docker/coolify-terminal/terminal-server.js index 068c449a909..e67fa262b42 100755 --- a/docker/coolify-terminal/terminal-server.js +++ b/docker/coolify-terminal/terminal-server.js @@ -448,7 +448,14 @@ async function handleCommand(ws, command, userId, terminalSessionId, reportEnd) commandTimeout, terminalSessionTimeout, }); - const ptyProcess = pty.spawn('ssh', sanitizedSshArgs.concat([hereDocContent]), options); + // The remote shell runs as `bash -se`/`sh -se`, which reads its script from stdin. Feed the + // here-doc body on stdin instead of as an extra ssh argument, so user-controlled command data + // never reaches the spawned process argument string (OS command/argument injection, CWE-78). + const ptyProcess = pty.spawn('ssh', sanitizedSshArgs, options); + + if (hereDocContent) { + ptyProcess.write(hereDocContent.endsWith('\n') ? hereDocContent : `${hereDocContent}\n`); + } userSession.ptyProcess = ptyProcess; userSession.isActive = true;