14
14
15
15
import csharp
16
16
import semmle.code.csharp.frameworks.Test
17
- import semmle.code.csharp.dataflow.DataFlow :: DataFlow :: PathGraph
17
+ import Random :: InsecureRandomness :: PathGraph
18
18
19
19
module Random {
20
20
import semmle.code.csharp.security.dataflow.flowsources.Remote
@@ -38,21 +38,24 @@ module Random {
38
38
/**
39
39
* A taint-tracking configuration for insecure randomness in security sensitive context.
40
40
*/
41
- class TaintTrackingConfiguration extends TaintTracking :: Configuration {
42
- TaintTrackingConfiguration ( ) { this = "RandomDataFlowConfiguration" }
41
+ module InsecureRandomnessConfig implements DataFlow :: ConfigSig {
42
+ predicate isSource ( DataFlow :: Node source ) { source instanceof Source }
43
43
44
- override predicate isSource ( DataFlow:: Node source ) { source instanceof Source }
44
+ predicate isSink ( DataFlow:: Node sink ) { sink instanceof Sink }
45
45
46
- override predicate isSink ( DataFlow:: Node sink ) { sink instanceof Sink }
46
+ predicate isBarrier ( DataFlow:: Node node ) { node instanceof Sanitizer }
47
47
48
- override predicate isSanitizer ( DataFlow:: Node node ) { node instanceof Sanitizer }
49
-
50
- override predicate isAdditionalTaintStep ( DataFlow:: Node pred , DataFlow:: Node succ ) {
48
+ predicate isAdditionalFlowStep ( DataFlow:: Node pred , DataFlow:: Node succ ) {
51
49
// succ = array_or_indexer[pred] - use of random numbers in an index
52
50
succ .asExpr ( ) .( ElementAccess ) .getAnIndex ( ) = pred .asExpr ( )
53
51
}
54
52
}
55
53
54
+ /**
55
+ * A taint-tracking module for insecure randomness in security sensitive context.
56
+ */
57
+ module InsecureRandomness = TaintTracking:: Global< InsecureRandomnessConfig > ;
58
+
56
59
/** A source of cryptographically insecure random numbers. */
57
60
class RandomSource extends Source {
58
61
RandomSource ( ) {
@@ -112,10 +115,8 @@ module Random {
112
115
}
113
116
}
114
117
115
- from
116
- Random:: TaintTrackingConfiguration randomTracking , DataFlow:: PathNode source ,
117
- DataFlow:: PathNode sink
118
- where randomTracking .hasFlowPath ( source , sink )
118
+ from Random:: InsecureRandomness:: PathNode source , Random:: InsecureRandomness:: PathNode sink
119
+ where Random:: InsecureRandomness:: flowPath ( source , sink )
119
120
select sink .getNode ( ) , source , sink ,
120
121
"This uses a cryptographically insecure random number generated at $@ in a security context." ,
121
122
source .getNode ( ) , source .getNode ( ) .toString ( )
0 commit comments