@@ -25,37 +25,31 @@ abstract class WeakRandomnessSource extends DataFlow::Node { }
25
25
* A node representing a call to a constructor of `java.util.Random`.
26
26
*/
27
27
private class JavaRandomSource extends WeakRandomnessSource {
28
- JavaRandomSource ( ) {
29
- this .asExpr ( ) .getType ( ) instanceof TypeRandom and this .asExpr ( ) instanceof ConstructorCall
30
- }
28
+ JavaRandomSource ( ) { this .asExpr ( ) .( ClassInstanceExpr ) .getType ( ) instanceof TypeRandom }
31
29
}
32
30
33
31
/**
34
32
* A node representing a call to one of the methods of `org.apache.commons.lang.RandomStringUtils`.
35
33
*/
36
34
private class ApacheRandomStringUtilsMethodAccessSource extends WeakRandomnessSource {
37
35
ApacheRandomStringUtilsMethodAccessSource ( ) {
38
- exists ( MethodAccess ma | this .asExpr ( ) = ma |
39
- ma .getMethod ( )
40
- .hasName ( [
41
- "random" , "randomAlphabetic" , "randomAlphanumeric" , "randomAscii" , "randomGraph" ,
42
- "randomNumeric" , "randomPrint"
43
- ] ) and
44
- ma .getMethod ( )
45
- .getDeclaringType ( )
46
- .hasQualifiedName ( "org.apache.commons.lang" , "RandomStringUtils" )
47
- )
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
+ ] )
48
44
}
49
45
}
50
46
51
47
private class ThreadLocalRandomSource extends WeakRandomnessSource {
52
48
ThreadLocalRandomSource ( ) {
53
- exists ( MethodAccess ma | this .asExpr ( ) = ma |
54
- ma .getMethod ( ) .hasName ( "current" ) and
55
- ma .getMethod ( )
56
- .getDeclaringType ( )
57
- .hasQualifiedName ( "java.util.concurrent" , "ThreadLocalRandom" )
58
- )
49
+ this .asExpr ( )
50
+ .( MethodAccess )
51
+ .getMethod ( )
52
+ .hasQualifiedName ( "java.util.concurrent" , "ThreadLocalRandom" , "current" )
59
53
}
60
54
}
61
55
@@ -64,10 +58,7 @@ private class ThreadLocalRandomSource extends WeakRandomnessSource {
64
58
*/
65
59
private class MathRandomMethodAccess extends WeakRandomnessSource {
66
60
MathRandomMethodAccess ( ) {
67
- exists ( MethodAccess ma | this .asExpr ( ) = ma |
68
- ma .getMethod ( ) .hasName ( "random" ) and
69
- ma .getMethod ( ) .getDeclaringType ( ) .hasQualifiedName ( "java.lang" , "Math" )
70
- )
61
+ this .asExpr ( ) .( MethodAccess ) .getMethod ( ) .hasQualifiedName ( "java.lang" , "Math" , "random" )
71
62
}
72
63
}
73
64
@@ -98,7 +89,7 @@ abstract class WeakRandomnessSink extends DataFlow::Node { }
98
89
*/
99
90
private class CookieSink extends WeakRandomnessSink {
100
91
CookieSink ( ) {
101
- this .asExpr ( ) . getType ( ) instanceof TypeCookie and
92
+ this .getType ( ) instanceof TypeCookie and
102
93
exists ( MethodAccess ma | ma .getMethod ( ) .hasName ( "addCookie" ) |
103
94
ma .getArgument ( 0 ) = this .asExpr ( )
104
95
)
@@ -142,14 +133,13 @@ module WeakRandomnessConfig implements DataFlow::ConfigSig {
142
133
exists ( MethodAccess ma , Method m |
143
134
n1 .asExpr ( ) = ma .getQualifier ( ) and
144
135
ma .getMethod ( ) = m and
145
- m .getDeclaringType ( ) .getAnAncestor ( ) instanceof TypeRandom and
146
- (
147
- m .hasName ( [ "nextInt" , "nextLong" , "nextFloat" , "nextDouble" , "nextBoolean" , "nextGaussian" ] ) and
148
- n2 .asExpr ( ) = ma
149
- or
150
- m .hasName ( "nextBytes" ) and
151
- n2 .( DataFlow:: PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( ) = ma .getArgument ( 0 )
152
- )
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 )
153
143
)
154
144
or
155
145
covertsBytesToString ( n1 , n2 )
0 commit comments