33 */
44
55import java
6+ private import semmle.code.java.dataflow.ExternalFlow
67private import semmle.code.java.dataflow.FlowSources
78
8- /** The Java class `com.auth0.jwt.JWT`. */
9+ /** The class `com.auth0.jwt.JWT`. */
910class Jwt extends RefType {
1011 Jwt ( ) { this .hasQualifiedName ( "com.auth0.jwt" , "JWT" ) }
1112}
1213
13- /** The Java class `com.auth0.jwt.JWTCreator.Builder`. */
14+ /** The class `com.auth0.jwt.JWTCreator.Builder`. */
1415class JwtBuilder extends RefType {
1516 JwtBuilder ( ) { this .hasQualifiedName ( "com.auth0.jwt" , "JWTCreator$Builder" ) }
1617}
1718
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" ) }
2122}
2223
2324/**
24- * The Java interface `com.auth0.jwt.interfaces.JWTVerifier` or it implementation class
25+ * The interface `com.auth0.jwt.interfaces.JWTVerifier` or its implementation
2526 * `com.auth0.jwt.JWTVerifier`.
2627 */
2728class JwtVerifier extends RefType {
@@ -30,15 +31,11 @@ class JwtVerifier extends RefType {
3031 }
3132}
3233
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%" ] )
4239 }
4340}
4441
@@ -76,19 +73,11 @@ abstract class JwtKeySource extends DataFlow::Node { }
7673 */
7774abstract class JwtTokenSink extends DataFlow:: Node { }
7875
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-
8476/**
8577 * A hardcoded string literal as a source for JWT token signing vulnerabilities.
8678 */
8779class HardcodedKeyStringSource extends JwtKeySource {
88- HardcodedKeyStringSource ( ) {
89- this .asExpr ( ) instanceof CompileTimeConstantExpr and
90- not isTestCode ( this .asExpr ( ) )
91- }
80+ HardcodedKeyStringSource ( ) { this .asExpr ( ) instanceof CompileTimeConstantExpr }
9281}
9382
9483/**
@@ -128,7 +117,7 @@ class HardcodedJwtKeyConfiguration extends TaintTracking::Configuration {
128117 override predicate isAdditionalTaintStep ( DataFlow:: Node prev , DataFlow:: Node succ ) {
129118 exists ( MethodAccess ma |
130119 (
131- ma .getMethod ( ) instanceof GetSecretMethod or
120+ ma .getMethod ( ) instanceof GetAlgorithmMethod or
132121 ma .getMethod ( ) instanceof RequireMethod
133122 ) and
134123 prev .asExpr ( ) = ma .getArgument ( 0 ) and
@@ -145,12 +134,12 @@ private class VerificationFlowStep extends SummaryModelCsv {
145134 "com.auth0.jwt.interfaces;Verification;true;build;;;Argument[-1];ReturnValue;taint" ,
146135 "com.auth0.jwt.interfaces;Verification;true;" +
147136 [ "acceptLeeway" , "acceptExpiresAt" , "acceptNotBefore" , "acceptIssuedAt" , "ignoreIssuedAt" ]
148- + ";;;Argument[-1];ReturnValue;taint " ,
137+ + ";;;Argument[-1];ReturnValue;value " ,
149138 "com.auth0.jwt.interfaces;Verification;true;with" +
150139 [
151140 "Issuer" , "Subject" , "Audience" , "AnyOfAudience" , "ClaimPresence" , "Claim" ,
152141 "ArrayClaim" , "JWTId"
153- ] + ";;;Argument[-1];ReturnValue;taint "
142+ ] + ";;;Argument[-1];ReturnValue;value "
154143 ]
155144 }
156145}
0 commit comments