Skip to content

Commit 412e841

Browse files
committed
JS: Add environment threat-model source
1 parent f733ac1 commit 412e841

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

javascript/ql/lib/semmle/javascript/frameworks/NodeJSLib.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,4 +1244,13 @@ module NodeJSLib {
12441244
result = moduleImport().getAPropertyRead(member)
12451245
}
12461246
}
1247+
1248+
/** A read of `process.env`, considered as a threat-model source. */
1249+
private class ProcessEnvThreatSource extends ThreatModelSource::Range {
1250+
ProcessEnvThreatSource() { this = NodeJSLib::process().getAPropertyRead("env") }
1251+
1252+
override string getThreatModel() { result = "environment" }
1253+
1254+
override string getSourceType() { result = "process.env" }
1255+
}
12471256
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
testFailures
2+
failures
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import javascript
2+
import testUtilities.InlineExpectationsTest
3+
4+
class TestSourcesConfiguration extends TaintTracking::Configuration {
5+
TestSourcesConfiguration() { this = "TestSources" }
6+
7+
override predicate isSource(DataFlow::Node source) { source instanceof ThreatModelSource }
8+
9+
override predicate isSink(DataFlow::Node sink) {
10+
exists(CallExpr call |
11+
call.getAnArgument() = sink.asExpr() and
12+
call.getCalleeName() = "SINK"
13+
)
14+
}
15+
}
16+
17+
private module InlineTestSources implements TestSig {
18+
string getARelevantTag() { result in ["hasFlow", "threat-source"] }
19+
20+
predicate hasActualResult(Location location, string element, string tag, string value) {
21+
exists(DataFlow::Node sink |
22+
any(TestSourcesConfiguration c).hasFlow(_, sink) and
23+
value = "" and
24+
location = sink.getLocation() and
25+
tag = "hasFlow" and
26+
element = sink.toString()
27+
)
28+
or
29+
exists(ThreatModelSource source |
30+
value = source.getThreatModel() and
31+
location = source.getLocation() and
32+
tag = "threat-source" and
33+
element = source.toString()
34+
)
35+
}
36+
}
37+
38+
import MakeTest<InlineTestSources>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import 'dummy';
2+
3+
var x = process.env['foo']; // $ threat-source=environment
4+
SINK(x); // $ hasFlow

0 commit comments

Comments
 (0)