11/** Provides classes and predicates for reasoning about insecure randomness. */
22
33import java
4+ private import semmle.code.java.frameworks.OpenSaml
45private import semmle.code.java.frameworks.Servlets
5- private import semmle.code.java.security.SensitiveActions
6- private import semmle.code.java.security.SensitiveApi
7- private import semmle.code.java.dataflow.TaintTracking
86private import semmle.code.java.dataflow.ExternalFlow
7+ private import semmle.code.java.dataflow.TaintTracking
8+ private import semmle.code.java.security.Cookies
99private import semmle.code.java.security.RandomQuery
10+ private import semmle.code.java.security.SensitiveActions
11+ private import semmle.code.java.security.SensitiveApi
1012
1113/**
1214 * A node representing a source of insecure randomness.
@@ -18,7 +20,7 @@ abstract class InsecureRandomnessSource extends DataFlow::Node { }
1820private class RandomMethodSource extends InsecureRandomnessSource {
1921 RandomMethodSource ( ) {
2022 exists ( RandomDataSource s | this .asExpr ( ) = s .getOutput ( ) |
21- not s .getQualifier ( ) . getType ( ) instanceof SafeRandomImplementation
23+ not s .getSourceOfRandomness ( ) instanceof SafeRandomImplementation
2224 )
2325 }
2426}
@@ -40,24 +42,15 @@ private class TypeHadoopOsSecureRandom extends SafeRandomImplementation {
4042}
4143
4244/**
43- * A node representing an operation which should not use a Insecurely random value.
45+ * A node representing an operation which should not use an insecurely random value.
4446 */
4547abstract class InsecureRandomnessSink extends DataFlow:: Node { }
4648
4749/**
4850 * A node which sets the value of a cookie.
4951 */
5052private class CookieSink extends InsecureRandomnessSink {
51- CookieSink ( ) {
52- exists ( Call c |
53- c .( ClassInstanceExpr ) .getConstructedType ( ) instanceof TypeCookie and
54- this .asExpr ( ) = c .getArgument ( 1 )
55- or
56- c .( MethodCall ) .getMethod ( ) .getDeclaringType ( ) instanceof TypeCookie and
57- c .( MethodCall ) .getMethod ( ) .hasName ( "setValue" ) and
58- this .asExpr ( ) = c .getArgument ( 0 )
59- )
60- }
53+ CookieSink ( ) { this .asExpr ( ) instanceof SetCookieValue }
6154}
6255
6356private class SensitiveActionSink extends InsecureRandomnessSink {
@@ -76,6 +69,8 @@ module InsecureRandomnessConfig implements DataFlow::ConfigSig {
7669
7770 predicate isBarrierIn ( DataFlow:: Node n ) { isSource ( n ) }
7871
72+ predicate isBarrierOut ( DataFlow:: Node n ) { isSink ( n ) }
73+
7974 predicate isAdditionalFlowStep ( DataFlow:: Node n1 , DataFlow:: Node n2 ) {
8075 n1 .asExpr ( ) = n2 .asExpr ( ) .( BinaryExpr ) .getAnOperand ( )
8176 or
@@ -88,6 +83,17 @@ module InsecureRandomnessConfig implements DataFlow::ConfigSig {
8883 n1 .asExpr ( ) = mc .getArgument ( 0 ) and
8984 n2 .asExpr ( ) = mc
9085 )
86+ or
87+ // TODO: Once we have a default sanitizer for UUIDs, we can convert these to global summaries.
88+ exists ( Call c |
89+ c .( ClassInstanceExpr ) .getConstructedType ( ) .hasQualifiedName ( "java.util" , "UUID" ) and
90+ n1 .asExpr ( ) = c .getAnArgument ( ) and
91+ n2 .asExpr ( ) = c
92+ or
93+ c .( MethodCall ) .getMethod ( ) .hasQualifiedName ( "java.util" , "UUID" , "toString" ) and
94+ n1 .asExpr ( ) = c .getQualifier ( ) and
95+ n2 .asExpr ( ) = c
96+ )
9197 }
9298}
9399
0 commit comments