The vulnerability lies in the npm/install.js script, which is executed during the npm install -g electerm process. The script fetches release information from GitHub, including filenames, and uses these filenames to construct shell commands for different operating systems (runLinux, runWin, runMac).
The core of the vulnerability is the lack of input sanitization on the filenames received from the remote server. An attacker who can control the release metadata on the project's update server (or intercept the traffic) can craft a malicious filename containing shell metacharacters. When this filename is used in the exec calls within the runLinux, runWin, or runMac functions, it leads to arbitrary command execution on the user's machine.
The patch addresses this by completely rewriting the installation logic. It introduces sanitizeFilename and sanitizeVersion functions to validate the data fetched from the remote server. It also replaces the vulnerable exec calls with safer alternatives like execFile and ensures that any path passed to a shell command is properly quoted or sanitized. The vulnerable functions runLinux, runWin, and runMac were removed and replaced with a more secure implementation.