|
8 | 8 | } |
9 | 9 | </code></pre> |
10 | 10 |
|
11 | | -*This shell command depends on an uncontrolled [absolute path](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/src/Security/CWE-078/examples/shell-command-injection-from-environment.js#L4-L4).* |
| 11 | +<details> |
| 12 | +<summary><i>This shell command depends on an uncontrolled absolute path.</i></summary> |
| 13 | + |
| 14 | +#### Paths |
| 15 | + |
| 16 | +Path with 5 steps |
| 17 | +1. [javascript/ql/src/Security/CWE-078/examples/shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/src/Security/CWE-078/examples/shell-command-injection-from-environment.js#L4-L4) |
| 18 | + <pre><code class="javascript"> path = require("path"); |
| 19 | + function cleanupTemp() { |
| 20 | + let cmd = "rm -rf " + path.join(<strong>__dirname</strong>, "temp"); |
| 21 | + cp.execSync(cmd); // BAD |
| 22 | + } |
| 23 | + </code></pre> |
| 24 | + |
| 25 | +2. [javascript/ql/src/Security/CWE-078/examples/shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/src/Security/CWE-078/examples/shell-command-injection-from-environment.js#L4-L4) |
| 26 | + <pre><code class="javascript"> path = require("path"); |
| 27 | + function cleanupTemp() { |
| 28 | + let cmd = "rm -rf " + <strong>path.join(__dirname, "temp")</strong>; |
| 29 | + cp.execSync(cmd); // BAD |
| 30 | + } |
| 31 | + </code></pre> |
| 32 | + |
| 33 | +3. [javascript/ql/src/Security/CWE-078/examples/shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/src/Security/CWE-078/examples/shell-command-injection-from-environment.js#L4-L4) |
| 34 | + <pre><code class="javascript"> path = require("path"); |
| 35 | + function cleanupTemp() { |
| 36 | + let cmd = <strong>"rm -rf " + path.join(__dirname, "temp")</strong>; |
| 37 | + cp.execSync(cmd); // BAD |
| 38 | + } |
| 39 | + </code></pre> |
| 40 | + |
| 41 | +4. [javascript/ql/src/Security/CWE-078/examples/shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/src/Security/CWE-078/examples/shell-command-injection-from-environment.js#L4-L4) |
| 42 | + <pre><code class="javascript"> path = require("path"); |
| 43 | + function cleanupTemp() { |
| 44 | + let <strong>cmd = "rm -rf " + path.join(__dirname, "temp")</strong>; |
| 45 | + cp.execSync(cmd); // BAD |
| 46 | + } |
| 47 | + </code></pre> |
| 48 | + |
| 49 | +5. [javascript/ql/src/Security/CWE-078/examples/shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/src/Security/CWE-078/examples/shell-command-injection-from-environment.js#L5-L5) |
| 50 | + <pre><code class="javascript">function cleanupTemp() { |
| 51 | + let cmd = "rm -rf " + path.join(__dirname, "temp"); |
| 52 | + cp.execSync(<strong>cmd</strong>); // BAD |
| 53 | + } |
| 54 | + </code></pre> |
| 55 | + |
| 56 | + |
| 57 | +</details> |
| 58 | + |
12 | 59 |
|
13 | 60 | ---------------------------------------- |
14 | 61 |
|
|
21 | 68 | execa.shell('rm -rf ' + path.join(__dirname, "temp")); // NOT OK |
22 | 69 | </code></pre> |
23 | 70 |
|
24 | | -*This shell command depends on an uncontrolled [absolute path](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L6-L6).* |
| 71 | +<details> |
| 72 | +<summary><i>This shell command depends on an uncontrolled absolute path.</i></summary> |
| 73 | + |
| 74 | +#### Paths |
| 75 | + |
| 76 | +Path with 3 steps |
| 77 | +1. [javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L6-L6) |
| 78 | + <pre><code class="javascript">(function() { |
| 79 | + cp.execFileSync('rm', ['-rf', path.join(__dirname, "temp")]); // GOOD |
| 80 | + cp.execSync('rm -rf ' + path.join(<strong>__dirname</strong>, "temp")); // BAD |
| 81 | + |
| 82 | + execa.shell('rm -rf ' + path.join(__dirname, "temp")); // NOT OK |
| 83 | + </code></pre> |
| 84 | + |
| 85 | +2. [javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L6-L6) |
| 86 | + <pre><code class="javascript">(function() { |
| 87 | + cp.execFileSync('rm', ['-rf', path.join(__dirname, "temp")]); // GOOD |
| 88 | + cp.execSync('rm -rf ' + <strong>path.join(__dirname, "temp")</strong>); // BAD |
| 89 | + |
| 90 | + execa.shell('rm -rf ' + path.join(__dirname, "temp")); // NOT OK |
| 91 | + </code></pre> |
| 92 | + |
| 93 | +3. [javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L6-L6) |
| 94 | + <pre><code class="javascript">(function() { |
| 95 | + cp.execFileSync('rm', ['-rf', path.join(__dirname, "temp")]); // GOOD |
| 96 | + cp.execSync(<strong>'rm -rf ' + path.join(__dirname, "temp")</strong>); // BAD |
| 97 | + |
| 98 | + execa.shell('rm -rf ' + path.join(__dirname, "temp")); // NOT OK |
| 99 | + </code></pre> |
| 100 | + |
| 101 | + |
| 102 | +</details> |
| 103 | + |
25 | 104 |
|
26 | 105 | ---------------------------------------- |
27 | 106 |
|
|
34 | 113 |
|
35 | 114 | </code></pre> |
36 | 115 |
|
37 | | -*This shell command depends on an uncontrolled [absolute path](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L8-L8).* |
| 116 | +<details> |
| 117 | +<summary><i>This shell command depends on an uncontrolled absolute path.</i></summary> |
| 118 | + |
| 119 | +#### Paths |
| 120 | + |
| 121 | +Path with 3 steps |
| 122 | +1. [javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L8-L8) |
| 123 | + <pre><code class="javascript"> cp.execSync('rm -rf ' + path.join(__dirname, "temp")); // BAD |
| 124 | + |
| 125 | + execa.shell('rm -rf ' + path.join(<strong>__dirname</strong>, "temp")); // NOT OK |
| 126 | + execa.shellSync('rm -rf ' + path.join(__dirname, "temp")); // NOT OK |
| 127 | + |
| 128 | + </code></pre> |
| 129 | + |
| 130 | +2. [javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L8-L8) |
| 131 | + <pre><code class="javascript"> cp.execSync('rm -rf ' + path.join(__dirname, "temp")); // BAD |
| 132 | + |
| 133 | + execa.shell('rm -rf ' + <strong>path.join(__dirname, "temp")</strong>); // NOT OK |
| 134 | + execa.shellSync('rm -rf ' + path.join(__dirname, "temp")); // NOT OK |
| 135 | + |
| 136 | + </code></pre> |
| 137 | + |
| 138 | +3. [javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L8-L8) |
| 139 | + <pre><code class="javascript"> cp.execSync('rm -rf ' + path.join(__dirname, "temp")); // BAD |
| 140 | + |
| 141 | + execa.shell(<strong>'rm -rf ' + path.join(__dirname, "temp")</strong>); // NOT OK |
| 142 | + execa.shellSync('rm -rf ' + path.join(__dirname, "temp")); // NOT OK |
| 143 | + |
| 144 | + </code></pre> |
| 145 | + |
| 146 | + |
| 147 | +</details> |
| 148 | + |
38 | 149 |
|
39 | 150 | ---------------------------------------- |
40 | 151 |
|
|
47 | 158 | const safe = "\"" + path.join(__dirname, "temp") + "\""; |
48 | 159 | </code></pre> |
49 | 160 |
|
50 | | -*This shell command depends on an uncontrolled [absolute path](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L9-L9).* |
| 161 | +<details> |
| 162 | +<summary><i>This shell command depends on an uncontrolled absolute path.</i></summary> |
| 163 | + |
| 164 | +#### Paths |
| 165 | + |
| 166 | +Path with 3 steps |
| 167 | +1. [javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L9-L9) |
| 168 | + <pre><code class="javascript"> |
| 169 | + execa.shell('rm -rf ' + path.join(__dirname, "temp")); // NOT OK |
| 170 | + execa.shellSync('rm -rf ' + path.join(<strong>__dirname</strong>, "temp")); // NOT OK |
| 171 | + |
| 172 | + const safe = "\"" + path.join(__dirname, "temp") + "\""; |
| 173 | + </code></pre> |
| 174 | + |
| 175 | +2. [javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L9-L9) |
| 176 | + <pre><code class="javascript"> |
| 177 | + execa.shell('rm -rf ' + path.join(__dirname, "temp")); // NOT OK |
| 178 | + execa.shellSync('rm -rf ' + <strong>path.join(__dirname, "temp")</strong>); // NOT OK |
| 179 | + |
| 180 | + const safe = "\"" + path.join(__dirname, "temp") + "\""; |
| 181 | + </code></pre> |
| 182 | + |
| 183 | +3. [javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js](https://github.com/github/codeql/blob/48015e5a2e6202131f2d1062cc066dc33ed69a9b/javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js#L9-L9) |
| 184 | + <pre><code class="javascript"> |
| 185 | + execa.shell('rm -rf ' + path.join(__dirname, "temp")); // NOT OK |
| 186 | + execa.shellSync(<strong>'rm -rf ' + path.join(__dirname, "temp")</strong>); // NOT OK |
| 187 | + |
| 188 | + const safe = "\"" + path.join(__dirname, "temp") + "\""; |
| 189 | + </code></pre> |
| 190 | + |
| 191 | + |
| 192 | +</details> |
| 193 | + |
51 | 194 |
|
52 | 195 | ---------------------------------------- |
0 commit comments