Skip to content

Commit 9b33629

Browse files
[3.10] gh-114539: Clarify implicit launching of shells by subprocess (GH-117996) (GH-118004)
(cherry picked from commit a4b44d3) Co-authored-by: Steve Dower <[email protected]>
1 parent 812245e commit 9b33629

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Doc/library/subprocess.rst

+10-2
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,8 @@ Exceptions defined in this module all inherit from :exc:`SubprocessError`.
741741
Security Considerations
742742
-----------------------
743743

744-
Unlike some other popen functions, this implementation will never
745-
implicitly call a system shell. This means that all characters,
744+
Unlike some other popen functions, this library will not
745+
implicitly choose to call a system shell. This means that all characters,
746746
including shell metacharacters, can safely be passed to child processes.
747747
If the shell is invoked explicitly, via ``shell=True``, it is the application's
748748
responsibility to ensure that all whitespace and metacharacters are
@@ -751,6 +751,14 @@ quoted appropriately to avoid
751751
vulnerabilities. On :ref:`some platforms <shlex-quote-warning>`, it is possible
752752
to use :func:`shlex.quote` for this escaping.
753753

754+
On Windows, batch files (:file:`*.bat` or :file:`*.cmd`) may be launched by the
755+
operating system in a system shell regardless of the arguments passed to this
756+
library. This could result in arguments being parsed according to shell rules,
757+
but without any escaping added by Python. If you are intentionally launching a
758+
batch file with arguments from untrusted sources, consider passing
759+
``shell=True`` to allow Python to escape special characters. See :gh:`114539`
760+
for additional discussion.
761+
754762

755763
Popen Objects
756764
-------------

0 commit comments

Comments
 (0)