mirror of
https://github.com/github/codeql.git
synced 2026-04-25 08:45:14 +02:00
JS: Add environment threat-model source
This commit is contained in:
@@ -1244,4 +1244,13 @@ module NodeJSLib {
|
||||
result = moduleImport().getAPropertyRead(member)
|
||||
}
|
||||
}
|
||||
|
||||
/** A read of `process.env`, considered as a threat-model source. */
|
||||
private class ProcessEnvThreatSource extends ThreatModelSource::Range {
|
||||
ProcessEnvThreatSource() { this = NodeJSLib::process().getAPropertyRead("env") }
|
||||
|
||||
override string getThreatModel() { result = "environment" }
|
||||
|
||||
override string getSourceType() { result = "process.env" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
testFailures
|
||||
failures
|
||||
@@ -0,0 +1,38 @@
|
||||
import javascript
|
||||
import testUtilities.InlineExpectationsTest
|
||||
|
||||
class TestSourcesConfiguration extends TaintTracking::Configuration {
|
||||
TestSourcesConfiguration() { this = "TestSources" }
|
||||
|
||||
override predicate isSource(DataFlow::Node source) { source instanceof ThreatModelSource }
|
||||
|
||||
override predicate isSink(DataFlow::Node sink) {
|
||||
exists(CallExpr call |
|
||||
call.getAnArgument() = sink.asExpr() and
|
||||
call.getCalleeName() = "SINK"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private module InlineTestSources implements TestSig {
|
||||
string getARelevantTag() { result in ["hasFlow", "threat-source"] }
|
||||
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(DataFlow::Node sink |
|
||||
any(TestSourcesConfiguration c).hasFlow(_, sink) and
|
||||
value = "" and
|
||||
location = sink.getLocation() and
|
||||
tag = "hasFlow" and
|
||||
element = sink.toString()
|
||||
)
|
||||
or
|
||||
exists(ThreatModelSource source |
|
||||
value = source.getThreatModel() and
|
||||
location = source.getLocation() and
|
||||
tag = "threat-source" and
|
||||
element = source.toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<InlineTestSources>
|
||||
@@ -0,0 +1,4 @@
|
||||
import 'dummy';
|
||||
|
||||
var x = process.env['foo']; // $ threat-source=environment
|
||||
SINK(x); // $ hasFlow
|
||||
Reference in New Issue
Block a user