Skip to content

Commit 393649b

Browse files
committed
don't call environment variables for command-line arguments
1 parent 3647812 commit 393649b

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

javascript/ql/lib/semmle/javascript/security/dataflow/IndirectCommandInjectionCustomizations.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ module IndirectCommandInjection {
1010
/**
1111
* A data flow source for command-injection vulnerabilities.
1212
*/
13-
abstract class Source extends DataFlow::Node { }
13+
abstract class Source extends DataFlow::Node {
14+
/** Gets a description of this source. */
15+
string describe() { result = "command-line argument" }
16+
}
1417

1518
/**
1619
* A data flow sink for command-injection vulnerabilities.
@@ -42,6 +45,8 @@ module IndirectCommandInjection {
4245
*/
4346
private class ProcessEnvAsSource extends Source {
4447
ProcessEnvAsSource() { this = NodeJSLib::process().getAPropertyRead("env") }
48+
49+
override string describe() { result = "environment variable" }
4550
}
4651

4752
/**

javascript/ql/lib/semmle/javascript/security/dataflow/RegExpInjectionCustomizations.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module RegExpInjection {
4040
* expression injection.
4141
*/
4242
class ArgvAsSource extends Source instanceof IndirectCommandInjection::Source {
43-
override string describe() { result = "command-line argument" }
43+
override string describe() { result = IndirectCommandInjection::Source.super.describe() }
4444
}
4545

4646
/**

javascript/ql/src/Security/CWE-078/IndirectCommandInjection.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ where
2525
then cfg.isSinkWithHighlight(sink.getNode(), highlight)
2626
else highlight = sink.getNode()
2727
select highlight, source, sink, "This command depends on an unsanitized $@.", source.getNode(),
28-
"command-line argument"
28+
source.getNode().(Source).describe()

javascript/ql/test/query-tests/Security/CWE-730/RegExpInjection.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,6 @@ edges
164164
| RegExpInjection.js:54:14:54:52 | key.spl ... in("-") | RegExpInjection.js:5:13:5:28 | req.param("key") | RegExpInjection.js:54:14:54:52 | key.spl ... in("-") | This regular expression is constructed from a $@. | RegExpInjection.js:5:13:5:28 | req.param("key") | user-provided value |
165165
| RegExpInjection.js:64:14:64:18 | input | RegExpInjection.js:60:39:60:56 | req.param("input") | RegExpInjection.js:64:14:64:18 | input | This regular expression is constructed from a $@. | RegExpInjection.js:60:39:60:56 | req.param("input") | user-provided value |
166166
| RegExpInjection.js:87:14:87:55 | "^.*\\.( ... + ")$" | RegExpInjection.js:82:15:82:32 | req.param("input") | RegExpInjection.js:87:14:87:55 | "^.*\\.( ... + ")$" | This regular expression is constructed from a $@. | RegExpInjection.js:82:15:82:32 | req.param("input") | user-provided value |
167-
| RegExpInjection.js:91:16:91:50 | `^${pro ... r.app$` | RegExpInjection.js:91:20:91:30 | process.env | RegExpInjection.js:91:16:91:50 | `^${pro ... r.app$` | This regular expression is constructed from a $@. | RegExpInjection.js:91:20:91:30 | process.env | command-line argument |
167+
| RegExpInjection.js:91:16:91:50 | `^${pro ... r.app$` | RegExpInjection.js:91:20:91:30 | process.env | RegExpInjection.js:91:16:91:50 | `^${pro ... r.app$` | This regular expression is constructed from a $@. | RegExpInjection.js:91:20:91:30 | process.env | environment variable |
168168
| RegExpInjection.js:93:16:93:49 | `^${pro ... r.app$` | RegExpInjection.js:93:20:93:31 | process.argv | RegExpInjection.js:93:16:93:49 | `^${pro ... r.app$` | This regular expression is constructed from a $@. | RegExpInjection.js:93:20:93:31 | process.argv | command-line argument |
169169
| tst.js:3:16:3:35 | "^"+ data.name + "$" | tst.js:1:46:1:46 | e | tst.js:3:16:3:35 | "^"+ data.name + "$" | This regular expression is constructed from a $@. | tst.js:1:46:1:46 | e | user-provided value |

0 commit comments

Comments
 (0)