1111 * external/cwe/cwe-352
1212 */
1313
14- import python
15- import semmle.python.Concepts
16- private import semmle.python.dataflow.new.DataFlow
17- predicate containsStar ( DataFlow:: Node array ) {
18- ( array .asExpr ( ) instanceof List and
19- array .asExpr ( ) .getASubExpression ( ) .( StringLiteral ) .getText ( ) .matches ( "*" ) ) or
20- ( array .asExpr ( ) .( StringLiteral ) .getText ( ) .matches ( [ "*" , "null" ] ) )
14+ import python
15+ import semmle.python.Concepts
16+ private import semmle.python.dataflow.new.DataFlow
2117
22- }
23-
24- predicate isCorsMiddleware ( Http:: Server:: CorsMiddleware middleware ) {
25- middleware .middleware_name ( ) .matches ( "CORSMiddleware" )
26- }
27-
28- predicate credentialsAllowed ( Http:: Server:: CorsMiddleware middleware ) {
29- middleware .allowed_credentials ( ) .asExpr ( ) instanceof True
30- }
31-
32- from Http:: Server:: CorsMiddleware a
33- where credentialsAllowed ( a ) and
34- containsStar ( a .allowed_origins ( ) .getALocalSource ( ) ) and
35- isCorsMiddleware ( a )
36- select a , "This CORS middleware uses a vulnerable configuration that leaves it open to attacks from arbitrary websites"
18+ predicate containsStar ( DataFlow:: Node array ) {
19+ array .asExpr ( ) instanceof List and
20+ array .asExpr ( ) .getASubExpression ( ) .( StringLiteral ) .getText ( ) = [ "*" , "null" ]
21+ or
22+ array .asExpr ( ) .( StringLiteral ) .getText ( ) = [ "*" , "null" ]
23+ }
24+
25+ predicate isCorsMiddleware ( Http:: Server:: CorsMiddleware middleware ) {
26+ middleware .middleware_name ( ) .matches ( "CORSMiddleware" )
27+ }
28+
29+ predicate credentialsAllowed ( Http:: Server:: CorsMiddleware middleware ) {
30+ middleware .allowed_credentials ( ) .asExpr ( ) instanceof True
31+ }
32+
33+ from Http:: Server:: CorsMiddleware a
34+ where
35+ credentialsAllowed ( a ) and
36+ containsStar ( a .allowed_origins ( ) .getALocalSource ( ) ) and
37+ isCorsMiddleware ( a )
38+ select a ,
39+ "This CORS middleware uses a vulnerable configuration that leaves it open to attacks from arbitrary websites"
0 commit comments