Skip to content

Commit a4ee353

Browse files
committed
C#: Re-factor CookieOptionsTracking to use the new API.
1 parent b3de105 commit a4ee353

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

csharp/ql/src/experimental/Security Features/CWE-1004/CookieWithoutHttpOnly.ql

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ where
3838
// there is no callback `OnAppendCookie` that sets `HttpOnly` to true
3939
not exists(OnAppendCookieHttpOnlyTrackingConfig config | config.hasFlowTo(_)) and
4040
// Passed as third argument to `IResponseCookies.Append`
41-
exists(
42-
CookieOptionsTrackingConfiguration cookieTracking, DataFlow::Node creation,
43-
DataFlow::Node append
44-
|
45-
cookieTracking.hasFlow(creation, append) and
41+
exists(DataFlow::Node creation, DataFlow::Node append |
42+
CookieOptionsTracking::flow(creation, append) and
4643
creation.asExpr() = oc and
4744
append.asExpr() = mc.getArgument(2)
4845
)
@@ -79,8 +76,8 @@ where
7976
oc = c and
8077
oc.getType() instanceof MicrosoftAspNetCoreHttpCookieOptions and
8178
not isPropertySet(oc, "HttpOnly") and
82-
exists(CookieOptionsTrackingConfiguration cookieTracking, DataFlow::Node creation |
83-
cookieTracking.hasFlow(creation, _) and
79+
exists(DataFlow::Node creation |
80+
CookieOptionsTracking::flow(creation, _) and
8481
creation.asExpr() = oc
8582
)
8683
)

csharp/ql/src/experimental/Security Features/CWE-614/CookieWithoutSecure.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ where
3737
oc = c and
3838
oc.getType() instanceof MicrosoftAspNetCoreHttpCookieOptions and
3939
not isPropertySet(oc, "Secure") and
40-
exists(CookieOptionsTrackingConfiguration cookieTracking, DataFlow::Node creation |
41-
cookieTracking.hasFlow(creation, _) and
40+
exists(DataFlow::Node creation |
41+
CookieOptionsTracking::flow(creation, _) and
4242
creation.asExpr() = oc
4343
)
4444
)
@@ -82,8 +82,8 @@ where
8282
// there is no callback `OnAppendCookie` that sets `Secure` to true
8383
not exists(OnAppendCookieSecureTrackingConfig config | config.hasFlowTo(_)) and
8484
// the cookie option is passed to `Append`
85-
exists(CookieOptionsTrackingConfiguration cookieTracking, DataFlow::Node creation |
86-
cookieTracking.hasFlow(creation, _) and
85+
exists(DataFlow::Node creation |
86+
CookieOptionsTracking::flow(creation, _) and
8787
creation.asExpr() = oc
8888
)
8989
)

csharp/ql/src/experimental/dataflow/flowsources/AuthCookie.qll

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ private class AuthCookieNameConfiguration extends DataFlow::Configuration {
4040
}
4141

4242
/**
43+
* DEPRECATED: Use `CookieOptionsTracking` instead.
44+
*
4345
* Tracks creation of `CookieOptions` to `IResponseCookies.Append(String, String, CookieOptions)` call as a third parameter.
4446
*/
45-
class CookieOptionsTrackingConfiguration extends DataFlow::Configuration {
47+
deprecated class CookieOptionsTrackingConfiguration extends DataFlow::Configuration {
4648
CookieOptionsTrackingConfiguration() { this = "CookieOptionsTrackingConfiguration" }
4749

4850
override predicate isSource(DataFlow::Node source) {
@@ -57,6 +59,29 @@ class CookieOptionsTrackingConfiguration extends DataFlow::Configuration {
5759
}
5860
}
5961

62+
/**
63+
* Configuration module tracking creation of `CookieOptions` to `IResponseCookies.Append(String, String, CookieOptions)`
64+
* calls as a third parameter.
65+
*/
66+
private module CookieOptionsTrackingConfig implements DataFlow::ConfigSig {
67+
predicate isSource(DataFlow::Node source) {
68+
source.asExpr().(ObjectCreation).getType() instanceof MicrosoftAspNetCoreHttpCookieOptions
69+
}
70+
71+
predicate isSink(DataFlow::Node sink) {
72+
exists(MicrosoftAspNetCoreHttpResponseCookies iResponse, MethodCall mc |
73+
iResponse.getAppendMethod() = mc.getTarget() and
74+
mc.getArgument(2) = sink.asExpr()
75+
)
76+
}
77+
}
78+
79+
/**
80+
* Tracking creation of `CookieOptions` to `IResponseCookies.Append(String, String, CookieOptions)`
81+
* calls as a third parameter.
82+
*/
83+
module CookieOptionsTracking = DataFlow::Global<CookieOptionsTrackingConfig>;
84+
6085
/**
6186
* Looks for property value of `CookiePolicyOptions` passed to `app.UseCookiePolicy` in `Startup.Configure`.
6287
*/

0 commit comments

Comments
 (0)