File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,18 @@ The :mod:`shlex` module defines the following functions:
61
61
string that can safely be used as one token in a shell command line, for
62
62
cases where you cannot use a list.
63
63
64
+ .. warning ::
65
+
66
+ The ``shlex `` module is **only designed for Unix systems **.
67
+
68
+ The :func: `quote ` function is not garaunteed to be safe on other operating
69
+ systems such as Windows. Executing commands quoted by this module on
70
+ other operating systems can open the possibility of a command injection
71
+ vulnerability.
72
+
73
+ Consider using functions that pass command arguments with lists such as
74
+ :func: `subprocess.run ` with ``shell=False ``.
75
+
64
76
This idiom would be unsafe:
65
77
66
78
>>> filename = ' somefile; rm -rf ~'
Original file line number Diff line number Diff line change @@ -693,9 +693,12 @@ quoted appropriately to avoid
693
693
`shell injection <https://en.wikipedia.org/wiki/Shell_injection#Shell_injection >`_
694
694
vulnerabilities.
695
695
696
- When using ``shell=True ``, the :func: `shlex.quote ` function can be
697
- used to properly escape whitespace and shell metacharacters in strings
698
- that are going to be used to construct shell commands.
696
+ When using ``shell=True `` on **Unix ** systems, the :func: `shlex.quote `
697
+ function can be used to properly escape whitespace and shell metacharacters in
698
+ strings that are going to be used to construct shell commands. Note that
699
+ the :mod: `shlex ` module is *only meant for Unix systems * and using it on other
700
+ operating systems such as Windows can create a command injection vulnerability
701
+ when coupled with ``shell=True ``.
699
702
700
703
701
704
Popen Objects
You can’t perform that action at this time.
0 commit comments