The vulnerability is a path traversal issue in the n8n SSH node, which allows an unauthenticated attacker to write files to arbitrary locations on a remote system. The root cause is the failure to sanitize user-provided filenames before using them in file transfer operations.
The analysis of the security patches (commits 528ad6b982d0519ec170e172f57b7fdbbe175230 and e0baf48c6a54808f6dbca8cb352bfa306092c223) pinpoints the exact code locations that were fixed.
-
Ssh.execute: This is the primary vulnerable function. Located in packages/nodes-base/nodes/Ssh/Ssh.node.ts, this method's 'upload' operation constructed a remote file path by concatenating a base directory with the raw filename from the input data. An attacker could craft a filename like ../../../tmp/pwned.txt to break out of the intended directory. The fix involves using a new sanitizeFilename function to strip all directory components from the filename before it is used by the ssh.putFile method.
-
copyBinaryFile: This utility function, found in packages/core/src/execution-engine/node-execution-context/utils/binary-helper-functions.ts, was also patched. It was identified that this function also handled filenames insecurely by assigning them without sanitization. While not the direct entry point for the SSH node exploit, fixing it provides defense-in-depth and prevents similar vulnerabilities in other nodes or workflows that might rely on this function.
The mitigation strategy was to introduce a sanitizeFilename utility that leverages path.basename to ensure only the filename part of a path is ever used, effectively neutralizing the path traversal threat.