The vulnerability lies in the hardenApprovedExecutionPaths function within src/node-host/invoke-system-run-plan.ts. This function incorrectly rewrote the argv (argument vector) of commands that used wrappers like env or sh -c. Specifically, it would resolve the main executable (e.g., sh) to its full path (e.g., /bin/sh) and prepend it to the argument list, while keeping the original arguments. For a command like ['env', 'sh', '-c', 'echo SAFE'], this would transform it into ['/bin/sh', 'sh', '-c', 'echo SAFE']. When executed, the shell (/bin/sh) would interpret its second argument (sh) as a local script file to run, instead of as its own name (argv[0]). This allowed an attacker who could place a file named sh in the working directory to execute arbitrary code, even if the operator approved a seemingly safe command.
The patch addresses this by adding checks within hardenApprovedExecutionPaths to detect if the command is a shell command or involves a wrapper. If so, it skips the argv rewriting, preserving the original command's semantics and preventing the vulnerability. The functions buildSystemRunApprovalPlan and evaluateSystemRunPolicyPhase were also updated to pass the necessary shellCommand information to hardenApprovedExecutionPaths, making the fix effective in the broader execution flow.