The vulnerability exists in the zx command-line tool when the --prefer-local=<path> option is used. This feature is meant to create a temporary node_modules symlink in the current directory, pointing to an external node_modules directory specified by <path>, and then remove the symlink after execution.
The core issue is an "Incorrectly-Resolved Name or Reference" vulnerability. The linkNodeModules function in src/cli.ts was responsible for creating the symlink but incorrectly returned the path to the original directory (target) instead of the path to the symlink itself (alias).
The runScript function then took this incorrect path and passed it to the rmrf cleanup function. The rmrf function, in its vulnerable form, would recursively delete any path it was given without checking if it was a symlink. Consequently, instead of removing the temporary symlink, zx would delete the user's original external node_modules directory.
The patches address this by first making rmrf safer (by checking for symlinks) and then fixing the root cause in linkNodeModules to return the correct path of the symlink, preventing the original directory from ever being targeted for deletion.