@@ -18,7 +18,8 @@ class TokenValidationParametersPropertyWriteToBypassSensitiveValidation extends
18
18
p .getAnAccess ( ) = this and
19
19
c .getAProperty ( ) = p and
20
20
p .getName ( ) in [
21
- "ValidateIssuer" , "ValidateAudience" , "ValidateLifetime" , "RequireExpirationTime" , "RequireAudience"
21
+ "ValidateIssuer" , "ValidateAudience" , "ValidateLifetime" , "RequireExpirationTime" ,
22
+ "RequireAudience"
22
23
]
23
24
)
24
25
}
@@ -38,9 +39,9 @@ class FalseValueFlowsToTokenValidationParametersPropertyWriteToBypassValidation
38
39
}
39
40
40
41
override predicate isSink ( DataFlow:: Node sink ) {
41
- exists ( Assignment a |
42
- sink .asExpr ( ) = a .getRValue ( )
43
- and a .getLValue ( ) instanceof TokenValidationParametersPropertyWrite
42
+ exists ( Assignment a |
43
+ sink .asExpr ( ) = a .getRValue ( ) and
44
+ a .getLValue ( ) instanceof TokenValidationParametersPropertyWrite
44
45
)
45
46
}
46
47
}
@@ -139,18 +140,28 @@ class TokenValidationParametersPropertyWriteToValidationDelegated extends Proper
139
140
* Holds if the callable has a return statement and it always returns true for all such statements
140
141
*/
141
142
predicate callableHasAReturnStmtAndAlwaysReturnsTrue ( Callable c ) {
142
- c .getReturnType ( ) .toString ( ) = "Boolean" and
143
+ c .getReturnType ( ) instanceof BoolType and
144
+ not callableMayThrowException ( c ) and
143
145
forall ( ReturnStmt rs | rs .getEnclosingCallable ( ) = c |
144
- rs .getChildExpr ( 0 ) .( BoolLiteral ) .getBoolValue ( ) = true
146
+ rs .getNumberOfChildren ( ) = 1 and
147
+ isExpressionAlwaysTrue ( rs .getChildExpr ( 0 ) )
145
148
) and
146
149
exists ( ReturnStmt rs | rs .getEnclosingCallable ( ) = c )
147
150
}
148
151
149
152
/**
150
153
* Holds if the lambda expression `le` always returns true
151
154
*/
152
- predicate lambdaExprReturnsOnlyLiteralTrue ( LambdaExpr le ) {
155
+ predicate lambdaExprReturnsOnlyLiteralTrue ( AnonymousFunctionExpr le ) {
153
156
le .getExpressionBody ( ) .( BoolLiteral ) .getBoolValue ( ) = true
157
+ or
158
+ // special scenarios where the expression is not a `BoolLiteral`, but it will evaluatue to `true`
159
+ exists ( Expr e | le .getExpressionBody ( ) = e |
160
+ not e instanceof Call and
161
+ not e instanceof Literal and
162
+ e .getType ( ) instanceof BoolType and
163
+ e .getValue ( ) = "true"
164
+ )
154
165
}
155
166
156
167
class CallableAlwaysReturnsTrue extends Callable {
@@ -159,9 +170,12 @@ class CallableAlwaysReturnsTrue extends Callable {
159
170
or
160
171
lambdaExprReturnsOnlyLiteralTrue ( this )
161
172
or
162
- exists ( LambdaExpr le , Call call , CallableAlwaysReturnsTrue cat | this = le |
173
+ exists ( AnonymousFunctionExpr le , Call call , CallableAlwaysReturnsTrue cat , Callable callable |
174
+ this = le
175
+ |
176
+ callable .getACall ( ) = call and
163
177
call = le .getExpressionBody ( ) and
164
- cat . getACall ( ) = call
178
+ callableHasAReturnStmtAndAlwaysReturnsTrue ( callable )
165
179
)
166
180
}
167
181
}
@@ -188,10 +202,16 @@ class CallableAlwaysReturnsTrueHigherPrecision extends CallableAlwaysReturnsTrue
188
202
callable instanceof CallableAlwaysReturnsTrueHigherPrecision
189
203
)
190
204
or
191
- exists ( LambdaExpr le , Call call , CallableAlwaysReturnsTrueHigherPrecision cat | this = le |
205
+ exists ( AnonymousFunctionExpr le , Call call , CallableAlwaysReturnsTrueHigherPrecision cat |
206
+ this = le
207
+ |
192
208
le .canReturn ( call ) and
193
209
cat .getACall ( ) = call
194
210
)
211
+ or
212
+ exists ( LambdaExpr le | le = this |
213
+ le .getBody ( ) instanceof CallableAlwaysReturnsTrueHigherPrecision
214
+ )
195
215
)
196
216
}
197
217
}
@@ -231,7 +251,7 @@ class CallableAlwaysReturnsParameter0 extends CallableReturnsStringAndArg0IsStri
231
251
) and
232
252
exists ( ReturnStmt rs | rs .getEnclosingCallable ( ) = this )
233
253
or
234
- exists ( LambdaExpr le , Call call , CallableAlwaysReturnsParameter0 cat | this = le |
254
+ exists ( AnonymousFunctionExpr le , Call call , CallableAlwaysReturnsParameter0 cat | this = le |
235
255
call = le .getExpressionBody ( ) and
236
256
cat .getACall ( ) = call
237
257
)
@@ -251,7 +271,9 @@ class CallableAlwaysReturnsParameter0MayThrowExceptions extends CallableReturnsS
251
271
) and
252
272
exists ( ReturnStmt rs | rs .getEnclosingCallable ( ) = this )
253
273
or
254
- exists ( LambdaExpr le , Call call , CallableAlwaysReturnsParameter0MayThrowExceptions cat |
274
+ exists (
275
+ AnonymousFunctionExpr le , Call call , CallableAlwaysReturnsParameter0MayThrowExceptions cat
276
+ |
255
277
this = le
256
278
|
257
279
call = le .getExpressionBody ( ) and
@@ -263,3 +285,31 @@ class CallableAlwaysReturnsParameter0MayThrowExceptions extends CallableReturnsS
263
285
this .getBody ( ) = this .getParameter ( 0 ) .getAnAccess ( )
264
286
}
265
287
}
288
+
289
+ /**
290
+ * Hold if the `Expr` e is a `BoolLiteral` with value true,
291
+ * the expression has a predictable value == `true`,
292
+ * or if it is a `ConditionalExpr` where the `then` and `else` expressions meet `isExpressionAlwaysTrue` criteria
293
+ */
294
+ predicate isExpressionAlwaysTrue ( Expr e ) {
295
+ e .( BoolLiteral ) .getBoolValue ( ) = true
296
+ or
297
+ e .( Expr ) .getValue ( ) = "true"
298
+ or
299
+ e instanceof ConditionalExpr and
300
+ isExpressionAlwaysTrue ( e .( ConditionalExpr ) .getThen ( ) ) and
301
+ isExpressionAlwaysTrue ( e .( ConditionalExpr ) .getElse ( ) )
302
+ or
303
+ exists ( Callable callable |
304
+ callableHasAReturnStmtAndAlwaysReturnsTrue ( callable ) and
305
+ callable .getACall ( ) = e
306
+ )
307
+ }
308
+
309
+ /**
310
+ * Holds if the `Callable` c throws any exception other than `ThrowsArgumentNullException`
311
+ */
312
+ predicate callableMayThrowException ( Callable c ) {
313
+ exists ( ThrowStmt thre | c = thre .getEnclosingCallable ( ) ) and
314
+ not callableOnlyThrowsArgumentNullException ( c )
315
+ }
0 commit comments