File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,27 @@ defmodule Port do
79
79
are for advanced usage within the VM. Also consider using `System.cmd/3`
80
80
if all you want is to execute a program and retrieve its return value.
81
81
82
+ > #### Windows argument splitting and untrusted arguments {: .warning}
83
+ >
84
+ > On Unix systems, arguments are passed to a new operating system
85
+ > process as an array of strings but on Windows it is up to the child
86
+ > process to parse them and some Windows programs may apply their own
87
+ > rules, which are inconsistent with the standard C runtime `argv` parsing
88
+ >
89
+ > This is particularly troublesome when invoking `.bat` or `.com` files
90
+ > as these run implicitly through `cmd.exe`, whose argument parsing is
91
+ > vulnerable to malicious input and can be used to run arbitrary shell
92
+ > commands.
93
+ >
94
+ > Therefore, if you are running on Windows and you execute batch
95
+ > files or `.com` applications, you must not pass untrusted input as
96
+ > arguments to the program. You may avoid accidentally executing them
97
+ > by explicitly passing the extension of the program you want to run,
98
+ > such as `.exe`, and double check the program is indeed not a batch
99
+ > file or `.com` application.
100
+ >
101
+ > This affects both `spawn` and `spawn_executable`.
102
+
82
103
### spawn
83
104
84
105
The `:spawn` tuple receives a binary that is going to be executed as a
Original file line number Diff line number Diff line change @@ -996,6 +996,25 @@ defmodule System do
996
996
`Port` module describes this problem and possible solutions under
997
997
the "Zombie processes" section.
998
998
999
+ > #### Windows argument splitting and untrusted arguments {: .warning}
1000
+ >
1001
+ > On Unix systems, arguments are passed to a new operating system
1002
+ > process as an array of strings but on Windows it is up to the child
1003
+ > process to parse them and some Windows programs may apply their own
1004
+ > rules, which are inconsistent with the standard C runtime `argv` parsing
1005
+ >
1006
+ > This is particularly troublesome when invoking `.bat` or `.com` files
1007
+ > as these run implicitly through `cmd.exe`, whose argument parsing is
1008
+ > vulnerable to malicious input and can be used to run arbitrary shell
1009
+ > commands.
1010
+ >
1011
+ > Therefore, if you are running on Windows and you execute batch
1012
+ > files or `.com` applications, you must not pass untrusted input as
1013
+ > arguments to the program. You may avoid accidentally executing them
1014
+ > by explicitly passing the extension of the program you want to run,
1015
+ > such as `.exe`, and double check the program is indeed not a batch
1016
+ > file or `.com` application.
1017
+
999
1018
## Examples
1000
1019
1001
1020
iex> System.cmd("echo", ["hello"])
You can’t perform that action at this time.
0 commit comments