Skip to content

Commit a385b30

Browse files
committed
Java: Factor common expr into class.
1 parent 958e2fa commit a385b30

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

java/ql/src/experimental/Security/CWE/CWE-347/MissingJWTSignatureCheck.ql

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class TypeJwtParser extends Interface {
1717
TypeJwtParser() { this.hasQualifiedName("io.jsonwebtoken", "JwtParser") }
1818
}
1919

20+
/** The interface `io.jsonwebtoken.JwtParser` or a type derived from it. */
21+
class TypeDerivedJwtParser extends RefType {
22+
TypeDerivedJwtParser() { this.getASourceSupertype*() instanceof TypeJwtParser }
23+
}
24+
2025
/** The interface `io.jsonwebtoken.JwtParserBuilder`. */
2126
class TypeJwtParserBuilder extends Interface {
2227
TypeJwtParserBuilder() { this.hasQualifiedName("io.jsonwebtoken", "JwtParserBuilder") }
@@ -122,7 +127,7 @@ private class JwtParserWithSigningKeyExpr extends Expr {
122127
MethodAccess signingMa;
123128

124129
JwtParserWithSigningKeyExpr() {
125-
this.getType().(RefType).getASourceSupertype*() instanceof TypeJwtParser and
130+
this.getType() instanceof TypeDerivedJwtParser and
126131
isSigningKeySetter(this, signingMa)
127132
}
128133

@@ -142,13 +147,13 @@ private class SigningToExprDataFlow extends DataFlow::Configuration {
142147
}
143148

144149
override predicate isSink(DataFlow::Node sink) {
145-
sink.asExpr().getType().(RefType).getASourceSupertype*() instanceof TypeJwtParser
150+
sink.asExpr().getType() instanceof TypeDerivedJwtParser
146151
}
147152

148153
/** Models the builder style of `JwtParser` and `JwtParserBuilder`. */
149154
override predicate isAdditionalFlowStep(DataFlow::Node pred, DataFlow::Node succ) {
150155
(
151-
pred.asExpr().getType().(RefType).getASourceSupertype*() instanceof TypeJwtParser or
156+
pred.asExpr().getType() instanceof TypeDerivedJwtParser or
152157
pred.asExpr().getType().(RefType).getASourceSupertype*() instanceof TypeJwtParserBuilder
153158
) and
154159
succ.asExpr().(MethodAccess).getQualifier() = pred.asExpr()

0 commit comments

Comments
 (0)