New GitHub issue #101283 from mauricelambert:<br>

<hr>

<pre>
# Bug report - Undocumented risky behaviour in subprocess module

When using `subprocess.Popen` with `shell=True` on Windows and without a `COMSPEC` environment variable, a `cmd.exe` is launched. The problem is the `cmd.exe` full path is not written, Windows will search the executable in the current directory and in the PATH. If an arbitrary executable file is written to the current directory or to a directory in the PATH, it can be run instead of the real cmd.exe.

See the code [here](https://github.com/python/cpython/blob/38cc24f119346e2947e316478b58e58f0dde307c/Lib/subprocess.py#L1480) and a POC [here](https://github.com/mauricelambert/PythonSubprocessVulnerabilityPOC).

 - This risky behaviour can be patched by replacing `cmd.exe` string by `C:\WINDOWS\system32\cmd.exe`.
 - If the behavior was chosen by python developers, it should be documented.

</pre>

<hr>

<a href="https://github.com/python/cpython/issues/101283">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>