Skip to content

Commit 7e162f5

Browse files
committed
JS: Port experimental EnvValueInjection to ConfigSig
1 parent 4f83907 commit 7e162f5

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

javascript/ql/src/experimental/Security/CWE-099/EnvValueInjection.ql

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@
1111
*/
1212

1313
import javascript
14-
import DataFlow::PathGraph
1514

1615
/** A taint tracking configuration for unsafe environment injection. */
17-
class Configuration extends TaintTracking::Configuration {
18-
Configuration() { this = "envInjection" }
16+
module EnvValueInjectionConfig implements DataFlow::ConfigSig {
17+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
1918

20-
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
21-
22-
override predicate isSink(DataFlow::Node sink) {
19+
predicate isSink(DataFlow::Node sink) {
2320
sink = API::moduleImport("process").getMember("env").getAMember().asSink()
2421
}
2522
}
2623

27-
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
28-
where cfg.hasFlowPath(source, sink)
24+
module EnvValueInjectionFlow = TaintTracking::Global<EnvValueInjectionConfig>;
25+
26+
import EnvValueInjectionFlow::PathGraph
27+
28+
from EnvValueInjectionFlow::PathNode source, EnvValueInjectionFlow::PathNode sink
29+
where EnvValueInjectionFlow::flowPath(source, sink)
2930
select sink.getNode(), source, sink, "this environment variable assignment is $@.",
3031
source.getNode(), "user controllable"

javascript/ql/test/experimental/Security/CWE-099/EnvValueInjection/EnvValueInjection.expected

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
1-
nodes
2-
| test.js:4:9:4:20 | { EnvValue } |
3-
| test.js:4:9:4:31 | EnvValue |
4-
| test.js:4:11:4:18 | EnvValue |
5-
| test.js:4:24:4:31 | req.body |
6-
| test.js:4:24:4:31 | req.body |
7-
| test.js:5:35:5:42 | EnvValue |
8-
| test.js:5:35:5:42 | EnvValue |
9-
| test.js:6:23:6:30 | EnvValue |
10-
| test.js:6:23:6:30 | EnvValue |
11-
| test.js:7:22:7:29 | EnvValue |
12-
| test.js:7:22:7:29 | EnvValue |
131
edges
14-
| test.js:4:9:4:20 | { EnvValue } | test.js:4:11:4:18 | EnvValue |
15-
| test.js:4:9:4:31 | EnvValue | test.js:5:35:5:42 | EnvValue |
16-
| test.js:4:9:4:31 | EnvValue | test.js:5:35:5:42 | EnvValue |
17-
| test.js:4:9:4:31 | EnvValue | test.js:6:23:6:30 | EnvValue |
18-
| test.js:4:9:4:31 | EnvValue | test.js:6:23:6:30 | EnvValue |
19-
| test.js:4:9:4:31 | EnvValue | test.js:7:22:7:29 | EnvValue |
20-
| test.js:4:9:4:31 | EnvValue | test.js:7:22:7:29 | EnvValue |
21-
| test.js:4:11:4:18 | EnvValue | test.js:4:9:4:31 | EnvValue |
22-
| test.js:4:24:4:31 | req.body | test.js:4:9:4:20 | { EnvValue } |
23-
| test.js:4:24:4:31 | req.body | test.js:4:9:4:20 | { EnvValue } |
2+
| test.js:4:9:4:20 | { EnvValue } | test.js:4:9:4:31 | EnvValue | provenance | |
3+
| test.js:4:9:4:31 | EnvValue | test.js:5:35:5:42 | EnvValue | provenance | |
4+
| test.js:4:9:4:31 | EnvValue | test.js:6:23:6:30 | EnvValue | provenance | |
5+
| test.js:4:9:4:31 | EnvValue | test.js:7:22:7:29 | EnvValue | provenance | |
6+
| test.js:4:24:4:31 | req.body | test.js:4:9:4:20 | { EnvValue } | provenance | |
7+
nodes
8+
| test.js:4:9:4:20 | { EnvValue } | semmle.label | { EnvValue } |
9+
| test.js:4:9:4:31 | EnvValue | semmle.label | EnvValue |
10+
| test.js:4:24:4:31 | req.body | semmle.label | req.body |
11+
| test.js:5:35:5:42 | EnvValue | semmle.label | EnvValue |
12+
| test.js:6:23:6:30 | EnvValue | semmle.label | EnvValue |
13+
| test.js:7:22:7:29 | EnvValue | semmle.label | EnvValue |
14+
subpaths
2415
#select
2516
| test.js:5:35:5:42 | EnvValue | test.js:4:24:4:31 | req.body | test.js:5:35:5:42 | EnvValue | this environment variable assignment is $@. | test.js:4:24:4:31 | req.body | user controllable |
2617
| test.js:6:23:6:30 | EnvValue | test.js:4:24:4:31 | req.body | test.js:6:23:6:30 | EnvValue | this environment variable assignment is $@. | test.js:4:24:4:31 | req.body | user controllable |

0 commit comments

Comments
 (0)