3
3
*/
4
4
5
5
import java
6
+ private import semmle.code.java.dataflow.ExternalFlow
6
7
private import semmle.code.java.dataflow.FlowSources
7
8
8
- /** The Java class `com.auth0.jwt.JWT`. */
9
+ /** The class `com.auth0.jwt.JWT`. */
9
10
class Jwt extends RefType {
10
11
Jwt ( ) { this .hasQualifiedName ( "com.auth0.jwt" , "JWT" ) }
11
12
}
12
13
13
- /** The Java class `com.auth0.jwt.JWTCreator.Builder`. */
14
+ /** The class `com.auth0.jwt.JWTCreator.Builder`. */
14
15
class JwtBuilder extends RefType {
15
16
JwtBuilder ( ) { this .hasQualifiedName ( "com.auth0.jwt" , "JWTCreator$Builder" ) }
16
17
}
17
18
18
- /** The Java class `com.auth0.jwt.algorithms.Algorithm`. */
19
- class Algorithm extends RefType {
20
- Algorithm ( ) { this .hasQualifiedName ( "com.auth0.jwt.algorithms" , "Algorithm" ) }
19
+ /** The class `com.auth0.jwt.algorithms.Algorithm`. */
20
+ class JwtAlgorithm extends RefType {
21
+ JwtAlgorithm ( ) { this .hasQualifiedName ( "com.auth0.jwt.algorithms" , "Algorithm" ) }
21
22
}
22
23
23
24
/**
24
- * The Java interface `com.auth0.jwt.interfaces.JWTVerifier` or it implementation class
25
+ * The interface `com.auth0.jwt.interfaces.JWTVerifier` or its implementation
25
26
* `com.auth0.jwt.JWTVerifier`.
26
27
*/
27
28
class JwtVerifier extends RefType {
@@ -30,15 +31,11 @@ class JwtVerifier extends RefType {
30
31
}
31
32
}
32
33
33
- /** The secret generation method declared in `com.auth0.jwt.algorithms.Algorithm`. */
34
- class GetSecretMethod extends Method {
35
- GetSecretMethod ( ) {
36
- this .getDeclaringType ( ) instanceof Algorithm and
37
- (
38
- this .getName ( ) .substring ( 0 , 4 ) = "HMAC" or
39
- this .getName ( ) .substring ( 0 , 5 ) = "ECDSA" or
40
- this .getName ( ) .substring ( 0 , 3 ) = "RSA"
41
- )
34
+ /** A method that creates an instance of `com.auth0.jwt.algorithms.Algorithm`. */
35
+ class GetAlgorithmMethod extends Method {
36
+ GetAlgorithmMethod ( ) {
37
+ this .getDeclaringType ( ) instanceof JwtAlgorithm and
38
+ this .getName ( ) .matches ( [ "HMAC%" , "ECDSA%" , "RSA%" ] )
42
39
}
43
40
}
44
41
@@ -76,19 +73,11 @@ abstract class JwtKeySource extends DataFlow::Node { }
76
73
*/
77
74
abstract class JwtTokenSink extends DataFlow:: Node { }
78
75
79
- private predicate isTestCode ( Expr e ) {
80
- e .getFile ( ) .getAbsolutePath ( ) .toLowerCase ( ) .matches ( "%test%" ) and
81
- not e .getFile ( ) .getAbsolutePath ( ) .toLowerCase ( ) .matches ( "%ql/test%" )
82
- }
83
-
84
76
/**
85
77
* A hardcoded string literal as a source for JWT token signing vulnerabilities.
86
78
*/
87
79
class HardcodedKeyStringSource extends JwtKeySource {
88
- HardcodedKeyStringSource ( ) {
89
- this .asExpr ( ) instanceof CompileTimeConstantExpr and
90
- not isTestCode ( this .asExpr ( ) )
91
- }
80
+ HardcodedKeyStringSource ( ) { this .asExpr ( ) instanceof CompileTimeConstantExpr }
92
81
}
93
82
94
83
/**
@@ -128,7 +117,7 @@ class HardcodedJwtKeyConfiguration extends TaintTracking::Configuration {
128
117
override predicate isAdditionalTaintStep ( DataFlow:: Node prev , DataFlow:: Node succ ) {
129
118
exists ( MethodAccess ma |
130
119
(
131
- ma .getMethod ( ) instanceof GetSecretMethod or
120
+ ma .getMethod ( ) instanceof GetAlgorithmMethod or
132
121
ma .getMethod ( ) instanceof RequireMethod
133
122
) and
134
123
prev .asExpr ( ) = ma .getArgument ( 0 ) and
@@ -145,12 +134,12 @@ private class VerificationFlowStep extends SummaryModelCsv {
145
134
"com.auth0.jwt.interfaces;Verification;true;build;;;Argument[-1];ReturnValue;taint" ,
146
135
"com.auth0.jwt.interfaces;Verification;true;" +
147
136
[ "acceptLeeway" , "acceptExpiresAt" , "acceptNotBefore" , "acceptIssuedAt" , "ignoreIssuedAt" ]
148
- + ";;;Argument[-1];ReturnValue;taint " ,
137
+ + ";;;Argument[-1];ReturnValue;value " ,
149
138
"com.auth0.jwt.interfaces;Verification;true;with" +
150
139
[
151
140
"Issuer" , "Subject" , "Audience" , "AnyOfAudience" , "ClaimPresence" , "Claim" ,
152
141
"ArrayClaim" , "JWTId"
153
- ] + ";;;Argument[-1];ReturnValue;taint "
142
+ ] + ";;;Argument[-1];ReturnValue;value "
154
143
]
155
144
}
156
145
}
0 commit comments