@@ -21,44 +21,11 @@ class TypeRandom extends RefType {
21
21
*/
22
22
abstract class WeakRandomnessSource extends DataFlow:: Node { }
23
23
24
- /**
25
- * A node representing a call to a constructor of `java.util.Random`.
26
- */
27
- private class JavaRandomSource extends WeakRandomnessSource {
28
- JavaRandomSource ( ) { this .asExpr ( ) .( ClassInstanceExpr ) .getType ( ) instanceof TypeRandom }
29
- }
30
-
31
- /**
32
- * A node representing a call to one of the methods of `org.apache.commons.lang.RandomStringUtils`.
33
- */
34
- private class ApacheRandomStringUtilsMethodAccessSource extends WeakRandomnessSource {
35
- ApacheRandomStringUtilsMethodAccessSource ( ) {
36
- this .asExpr ( )
37
- .( MethodAccess )
38
- .getMethod ( )
39
- .hasQualifiedName ( "org.apache.commons.lang" , "RandomStringUtils" ,
40
- [
41
- "random" , "randomAlphabetic" , "randomAlphanumeric" , "randomAscii" , "randomGraph" ,
42
- "randomNumeric" , "randomPrint"
43
- ] )
44
- }
45
- }
46
-
47
- private class ThreadLocalRandomSource extends WeakRandomnessSource {
48
- ThreadLocalRandomSource ( ) {
49
- this .asExpr ( )
50
- .( MethodAccess )
51
- .getMethod ( )
52
- .hasQualifiedName ( "java.util.concurrent" , "ThreadLocalRandom" , "current" )
53
- }
54
- }
55
-
56
- /**
57
- * The `random` method of `java.lang.Math`.
58
- */
59
- private class MathRandomMethodAccess extends WeakRandomnessSource {
60
- MathRandomMethodAccess ( ) {
61
- this .asExpr ( ) .( MethodAccess ) .getMethod ( ) .hasQualifiedName ( "java.lang" , "Math" , "random" )
24
+ private class RandomMethodSource extends WeakRandomnessSource {
25
+ RandomMethodSource ( ) {
26
+ exists ( RandomDataSource s | this .asExpr ( ) = s .getOutput ( ) |
27
+ not s .getQualifier ( ) .getType ( ) instanceof SafeRandomImplementation
28
+ )
62
29
}
63
30
}
64
31
@@ -121,27 +88,13 @@ module WeakRandomnessConfig implements DataFlow::ConfigSig {
121
88
122
89
predicate isSink ( DataFlow:: Node sink ) { sink instanceof WeakRandomnessSink }
123
90
124
- predicate isBarrier ( DataFlow:: Node n ) { n .getTypeBound ( ) instanceof SafeRandomImplementation }
125
-
126
91
predicate isBarrierIn ( DataFlow:: Node n ) { isSource ( n ) }
127
92
128
93
predicate isAdditionalFlowStep ( DataFlow:: Node n1 , DataFlow:: Node n2 ) {
129
94
n1 .asExpr ( ) = n2 .asExpr ( ) .( BinaryExpr ) .getAnOperand ( )
130
95
or
131
96
n1 .asExpr ( ) = n2 .asExpr ( ) .( UnaryExpr ) .getExpr ( )
132
97
or
133
- exists ( MethodAccess ma , Method m |
134
- n1 .asExpr ( ) = ma .getQualifier ( ) and
135
- ma .getMethod ( ) = m and
136
- m .getDeclaringType ( ) .getAnAncestor ( ) instanceof TypeRandom
137
- |
138
- m .hasName ( [ "nextInt" , "nextLong" , "nextFloat" , "nextDouble" , "nextBoolean" , "nextGaussian" ] ) and
139
- n2 .asExpr ( ) = ma
140
- or
141
- m .hasName ( "nextBytes" ) and
142
- n2 .( DataFlow:: PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( ) = ma .getArgument ( 0 )
143
- )
144
- or
145
98
covertsBytesToString ( n1 , n2 )
146
99
}
147
100
}
0 commit comments