@@ -18,7 +18,8 @@ class TokenValidationParametersPropertyWriteToBypassSensitiveValidation extends
1818 p .getAnAccess ( ) = this and
1919 c .getAProperty ( ) = p and
2020 p .getName ( ) in [
21- "ValidateIssuer" , "ValidateAudience" , "ValidateLifetime" , "RequireExpirationTime" , "RequireAudience"
21+ "ValidateIssuer" , "ValidateAudience" , "ValidateLifetime" , "RequireExpirationTime" ,
22+ "RequireAudience"
2223 ]
2324 )
2425 }
@@ -38,9 +39,9 @@ class FalseValueFlowsToTokenValidationParametersPropertyWriteToBypassValidation
3839 }
3940
4041 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
4445 )
4546 }
4647}
@@ -139,18 +140,28 @@ class TokenValidationParametersPropertyWriteToValidationDelegated extends Proper
139140 * Holds if the callable has a return statement and it always returns true for all such statements
140141 */
141142predicate callableHasAReturnStmtAndAlwaysReturnsTrue ( Callable c ) {
142- c .getReturnType ( ) .toString ( ) = "Boolean" and
143+ c .getReturnType ( ) instanceof BoolType and
144+ not callableMayThrowException ( c ) and
143145 forall ( ReturnStmt rs | rs .getEnclosingCallable ( ) = c |
144- rs .getChildExpr ( 0 ) .( BoolLiteral ) .getBoolValue ( ) = true
146+ rs .getNumberOfChildren ( ) = 1 and
147+ isExpressionAlwaysTrue ( rs .getChildExpr ( 0 ) )
145148 ) and
146149 exists ( ReturnStmt rs | rs .getEnclosingCallable ( ) = c )
147150}
148151
149152/**
150153 * Holds if the lambda expression `le` always returns true
151154 */
152- predicate lambdaExprReturnsOnlyLiteralTrue ( LambdaExpr le ) {
155+ predicate lambdaExprReturnsOnlyLiteralTrue ( AnonymousFunctionExpr le ) {
153156 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+ )
154165}
155166
156167class CallableAlwaysReturnsTrue extends Callable {
@@ -159,9 +170,12 @@ class CallableAlwaysReturnsTrue extends Callable {
159170 or
160171 lambdaExprReturnsOnlyLiteralTrue ( this )
161172 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
163177 call = le .getExpressionBody ( ) and
164- cat . getACall ( ) = call
178+ callableHasAReturnStmtAndAlwaysReturnsTrue ( callable )
165179 )
166180 }
167181}
@@ -188,10 +202,16 @@ class CallableAlwaysReturnsTrueHigherPrecision extends CallableAlwaysReturnsTrue
188202 callable instanceof CallableAlwaysReturnsTrueHigherPrecision
189203 )
190204 or
191- exists ( LambdaExpr le , Call call , CallableAlwaysReturnsTrueHigherPrecision cat | this = le |
205+ exists ( AnonymousFunctionExpr le , Call call , CallableAlwaysReturnsTrueHigherPrecision cat |
206+ this = le
207+ |
192208 le .canReturn ( call ) and
193209 cat .getACall ( ) = call
194210 )
211+ or
212+ exists ( LambdaExpr le | le = this |
213+ le .getBody ( ) instanceof CallableAlwaysReturnsTrueHigherPrecision
214+ )
195215 )
196216 }
197217}
@@ -231,7 +251,7 @@ class CallableAlwaysReturnsParameter0 extends CallableReturnsStringAndArg0IsStri
231251 ) and
232252 exists ( ReturnStmt rs | rs .getEnclosingCallable ( ) = this )
233253 or
234- exists ( LambdaExpr le , Call call , CallableAlwaysReturnsParameter0 cat | this = le |
254+ exists ( AnonymousFunctionExpr le , Call call , CallableAlwaysReturnsParameter0 cat | this = le |
235255 call = le .getExpressionBody ( ) and
236256 cat .getACall ( ) = call
237257 )
@@ -251,7 +271,9 @@ class CallableAlwaysReturnsParameter0MayThrowExceptions extends CallableReturnsS
251271 ) and
252272 exists ( ReturnStmt rs | rs .getEnclosingCallable ( ) = this )
253273 or
254- exists ( LambdaExpr le , Call call , CallableAlwaysReturnsParameter0MayThrowExceptions cat |
274+ exists (
275+ AnonymousFunctionExpr le , Call call , CallableAlwaysReturnsParameter0MayThrowExceptions cat
276+ |
255277 this = le
256278 |
257279 call = le .getExpressionBody ( ) and
@@ -263,3 +285,31 @@ class CallableAlwaysReturnsParameter0MayThrowExceptions extends CallableReturnsS
263285 this .getBody ( ) = this .getParameter ( 0 ) .getAnAccess ( )
264286 }
265287}
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