Skip to content

Commit 7527b7a

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Convert InsecureIV.ql to use the new dataflow API
1 parent 251e0ed commit 7527b7a

File tree

2 files changed

+33
-41
lines changed

2 files changed

+33
-41
lines changed

javascript/lib/ghsl/InsecureIV.qll

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,41 @@ import semmle.javascript.dataflow.TaintTracking
22

33
import ghsl.CommandLine
44

5-
class RandomTaintsSourceConfiguration extends TaintTracking::Configuration {
6-
RandomTaintsSourceConfiguration() { this = "RandomTaintsSourceConfiguration" }
5+
module RandomTaintsSourceConfig implements DataFlow::ConfigSig {
6+
predicate isSource(DataFlow::Node source) { isSecureRandom(source) }
77

8-
override predicate isSource(DataFlow::Node source) {
9-
isSecureRandom(source)
10-
}
11-
12-
override predicate isSink(DataFlow::Node sink) {
13-
not isSecureRandom(sink)
14-
}
8+
predicate isSink(DataFlow::Node sink) { not isSecureRandom(sink) }
159
}
1610

17-
class InsecureIVConfiguration extends TaintTracking::Configuration {
18-
InsecureIVConfiguration() { this = "InsecureIVConfiguration" }
11+
module RandomTaintsSourceFlow = TaintTracking::Global<RandomTaintsSourceConfig>;
1912

20-
override predicate isSource(DataFlow::Node source) {
21-
exists(Literal literal|literal.flow() = source)
22-
or
23-
source instanceof DataFlow::ArrayLiteralNode
24-
or
25-
source instanceof RemoteFlowSource
26-
or
27-
source instanceof FileSystemReadAccess
28-
or
29-
source instanceof DatabaseAccess
30-
or
31-
source instanceof CommandLineArgument
32-
or
33-
// an external function that is not a known source of randomness
34-
(
35-
source instanceof ExternalCallWithOutput
36-
and not source instanceof CreateIVArgument
37-
and not source instanceof SecureRandomSource
38-
)
39-
}
13+
module InsecureIVConfig implements DataFlow::ConfigSig {
14+
predicate isSource(DataFlow::Node source) {
15+
exists(Literal literal | literal.flow() = source)
16+
or
17+
source instanceof DataFlow::ArrayLiteralNode
18+
or
19+
source instanceof RemoteFlowSource
20+
or
21+
source instanceof FileSystemReadAccess
22+
or
23+
source instanceof DatabaseAccess
24+
or
25+
source instanceof CommandLineArgument
26+
or
27+
// an external function that is not a known source of randomness
28+
(
29+
source instanceof ExternalCallWithOutput
30+
and not source instanceof CreateIVArgument
31+
and not source instanceof SecureRandomSource
32+
)
33+
}
4034

41-
override predicate isSink(DataFlow::Node sink) {
42-
sink instanceof CreateIVArgument
43-
}
35+
predicate isSink(DataFlow::Node sink) { sink instanceof CreateIVArgument }
4436
}
4537

38+
module InsecureIVFlow = TaintTracking::Global<InsecureIVConfig>;
39+
4640
class ExternalCallWithOutput extends DataFlow::Node {
4741
CallExpr call;
4842

javascript/src/security/CWE-329/InsecureIV.ql

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@
1515

1616
import javascript
1717
import semmle.javascript.dataflow.TaintTracking
18-
import DataFlow::PathGraph
18+
import InsecureIVFlow::PathGraph
1919
import ghsl.InsecureIV
2020

21-
from InsecureIVConfiguration insecurecfg, DataFlow::PathNode source, DataFlow::PathNode sink
21+
from InsecureIVFlow::PathNode source, InsecureIVFlow::PathNode sink
2222
where
23-
insecurecfg.hasFlowPath(source, sink) and
24-
not exists(DataFlow::Node randomSource, RandomTaintsSourceConfiguration randomConfig |
25-
randomSource instanceof SecureRandomSource
26-
|
27-
randomConfig.hasFlow(randomSource, source.getNode())
23+
InsecureIVFlow::flowPath(source, sink) and
24+
not exists(DataFlow::Node randomSource | randomSource instanceof SecureRandomSource |
25+
RandomTaintsSourceFlow::flow(randomSource, source.getNode())
2826
) and
2927
not knownCryptTest(sink.getNode())
3028
select sink, source, sink,

0 commit comments

Comments
 (0)