From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Fri, 9 Aug 2024 13:57:50 +0000 (+0200) Subject: [3.11] gh-114539: Clarify implicit launching of shells by subprocess (GH-117996)... X-Git-Tag: v3.11.10~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b39636047bfaa0c88c9bc743e2a452cf7b97b56c;p=thirdparty%2FPython%2Fcpython.git [3.11] gh-114539: Clarify implicit launching of shells by subprocess (GH-117996) (#118003) Co-authored-by: Steve Dower --- diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst index f2d0f83bb68b..c0ae9e5d7aae 100644 --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -756,8 +756,8 @@ Exceptions defined in this module all inherit from :exc:`SubprocessError`. Security Considerations ----------------------- -Unlike some other popen functions, this implementation will never -implicitly call a system shell. This means that all characters, +Unlike some other popen functions, this library will not +implicitly choose to call a system shell. This means that all characters, including shell metacharacters, can safely be passed to child processes. If the shell is invoked explicitly, via ``shell=True``, it is the application's responsibility to ensure that all whitespace and metacharacters are @@ -766,6 +766,14 @@ quoted appropriately to avoid vulnerabilities. On :ref:`some platforms `, it is possible to use :func:`shlex.quote` for this escaping. +On Windows, batch files (:file:`*.bat` or :file:`*.cmd`) may be launched by the +operating system in a system shell regardless of the arguments passed to this +library. This could result in arguments being parsed according to shell rules, +but without any escaping added by Python. If you are intentionally launching a +batch file with arguments from untrusted sources, consider passing +``shell=True`` to allow Python to escape special characters. See :gh:`114539` +for additional discussion. + Popen Objects -------------