1
1
/**
2
- * @name CORS misconfiguration
3
- * @description Keeping an open CORS policy may result in security issues as third party website may be able to
4
- * access other websites .
2
+ * @name Credentialed CORS Misconfiguration
3
+ * @description Allowing any origin while allowing credentials may result in security issues as third party website may be able to
4
+ * access private resources .
5
5
* @kind problem
6
6
* @problem.severity error
7
7
* @security-severity 7.5
8
8
* @precision high
9
- * @id cs/web/cors-misconfiguration
9
+ * @id cs/web/cors-misconfiguration-credentials
10
10
* @tags security
11
11
* external/cwe/cwe-942
12
12
*/
@@ -37,22 +37,22 @@ private predicate alwaysReturnsTrue(Callable c) {
37
37
}
38
38
39
39
/**
40
- * Holds if the application uses a vulnerable CORS policy .
40
+ * Holds if the application allows an origin using "*" origin .
41
41
*/
42
- private predicate hasDangerousOrigins ( MethodCall m ) {
42
+ private predicate allowAnyOrigin ( MethodCall m ) {
43
43
m .getTarget ( )
44
44
.hasFullyQualifiedName ( "Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder" ,
45
- "WithOrigins" ) and
46
- m .getAnArgument ( ) .getValue ( ) = [ "null" , "*" ]
45
+ "AllowAnyOrigin" )
47
46
}
48
47
49
48
/**
50
- * Holds if the application allows an origin using "*" origin .
49
+ * Holds if the application uses a vulnerable CORS policy .
51
50
*/
52
- private predicate allowAnyOrigin ( MethodCall m ) {
51
+ private predicate hasDangerousOrigins ( MethodCall m ) {
53
52
m .getTarget ( )
54
53
.hasFullyQualifiedName ( "Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder" ,
55
- "AllowAnyOrigin" )
54
+ "WithOrigins" ) and
55
+ m .getAnArgument ( ) .getValue ( ) = [ "null" , "*" ]
56
56
}
57
57
58
58
/**
@@ -64,25 +64,30 @@ private predicate configIsUsed(MethodCall add_policy) {
64
64
.hasFullyQualifiedName ( "Microsoft.AspNetCore.Builder.CorsMiddlewareExtensions" , "UseCors" ) and
65
65
(
66
66
uc .getArgument ( 1 ) .getValue ( ) = add_policy .getArgument ( 0 ) .getValue ( ) or
67
+ uc .getArgument ( 1 ) .( VariableAccess ) .getTarget ( ) =
68
+ add_policy .getArgument ( 0 ) .( VariableAccess ) .getTarget ( ) or
67
69
localFlow ( DataFlow:: exprNode ( add_policy .getArgument ( 0 ) ) , DataFlow:: exprNode ( uc .getArgument ( 1 ) ) )
68
70
)
69
71
)
70
72
}
71
73
72
- from MethodCall add_policy , MethodCall m
74
+ from MethodCall add_policy , MethodCall m , MethodCall allowsCredentials
73
75
where
74
76
(
75
77
add_policy
76
78
.getTarget ( )
77
79
.hasFullyQualifiedName ( "Microsoft.AspNetCore.Cors.Infrastructure.CorsOptions" , "AddPolicy" ) and
78
80
add_policy .getArgument ( 1 ) = m .getParent * ( ) and
79
- configIsUsed ( add_policy )
81
+ configIsUsed ( add_policy ) and
82
+ add_policy .getArgument ( 1 ) = allowsCredentials .getParent * ( )
80
83
or
81
84
add_policy
82
85
.getTarget ( )
83
86
.hasFullyQualifiedName ( "Microsoft.AspNetCore.Cors.Infrastructure.CorsOptions" ,
84
87
"AddDefaultPolicy" ) and
85
- add_policy .getArgument ( 0 ) = m .getParent * ( )
88
+ add_policy .getArgument ( 0 ) = m .getParent * ( ) and
89
+ add_policy .getArgument ( 0 ) = allowsCredentials .getParent * ( )
86
90
) and
87
91
( hasDangerousOrigins ( m ) or allowAnyOrigin ( m ) or functionAlwaysReturnsTrue ( m ) )
88
- select add_policy , "The following CORS policy may be vulnerable to 3rd party websites"
92
+ select add_policy ,
93
+ "The following CORS policy may allow credentialed requests from 3rd party websites"
0 commit comments