You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: javascript/ql/src/Security/CWE-078/CommandInjection.inc.qhelp
+7-11Lines changed: 7 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -10,15 +10,14 @@ allows the user to execute malicious code.</p>
10
10
</overview>
11
11
12
12
<recommendation>
13
-
<p>If possible, use APIs that don't run shell commands, and accept command
13
+
<p>If possible, use APIs that don't run shell commands and accept command
14
14
arguments as an array of strings rather than a single concatenated string. This
15
15
is both safer and more portable.</p>
16
16
17
-
<p>If you are given the arguments as a single string, note that it is not safe
18
-
to simply split the string on whitespace, since an argument may contain quoted
19
-
whitespace which would cause it to be split into multiple arguments. Instead,
20
-
use a library such as <code>shell-quote</code> to parse the string into an array
21
-
of arguments.</p>
17
+
<p>If given arguments as a single string, avoid simply splitting the string on
18
+
whitespace. Arguments may contain quoted whitespace, causing them to split into
19
+
multiple arguments. Use a library like <code>shell-quote</code> to parse the string
20
+
into an array of arguments instead.</p>
22
21
23
22
<p>If this approach is not viable, then add code to verify that the user input
24
23
string is safe before using it.</p>
@@ -31,12 +30,9 @@ command to count its lines without examining it first.</p>
31
30
32
31
<samplesrc="examples/command-injection.js" />
33
32
34
-
<p>A malicious user can exploit this code to execute arbitrary shell commands by
35
-
passing a filename like <code>foo.txt; rm -rf .</code>, which will first count
36
-
the lines in <code>foo.txt</code> and then delete all files in the current
37
-
directory.</p>
33
+
<p>A malicious user can take advantage of this code by executing arbitrary shell commands. For instance, by providing a filename like <code>foo.txt; rm -rf .</code>, the user can first count the lines in <code>foo.txt</code> and subsequently delete all files in the current directory. </p>
38
34
39
-
<p>To avoid this catastrophic loophole, use an API like
35
+
<p>To avoid this catastrophic loophole, use an API such as
40
36
<code>child_process.execFileSync</code> that does not spawn a shell by
0 commit comments