Skip to content

Commit 40e8a90

Browse files
author
edvraa
committed
Apply changes from code review
1 parent 6393dca commit 40e8a90

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,9 @@ Expr getAValueForProp(ObjectCreation create, Assignment a, string prop) {
104104
}
105105

106106
/**
107-
* Similar to getAValueForProp, checks if the given property was explicitly set to a value.
107+
* Checks if the given property was explicitly set to a value.
108108
*/
109-
predicate isPropertySet(ObjectCreation oc, string prop) {
110-
exists(Assignment a, PropertyAccess pa |
111-
a.getLValue() = pa and
112-
pa.getTarget().hasName(prop) and
113-
DataFlow::localExprFlow(oc, pa.getQualifier())
114-
)
115-
or
116-
exists(Assignment a, PropertyAccess pa, Expr src |
117-
a.getLValue() = pa and
118-
pa.getTarget().hasName(prop) and
119-
a.getRValue() = src and
120-
DataFlow::localExprFlow(src,
121-
oc.getInitializer().(ObjectInitializer).getAMemberInitializer().getRValue())
122-
)
123-
}
109+
predicate isPropertySet(ObjectCreation oc, string prop) { exists(getAValueForProp(oc, _, prop)) }
124110

125111
/**
126112
* Tracks if a callback used in `OnAppendCookie` sets `Secure` to `true`.
@@ -143,7 +129,7 @@ class OnAppendCookieHttpOnlyTrackingConfig extends OnAppendCookieTrackingConfig
143129
/**
144130
* Tracks if a callback used in `OnAppendCookie` sets a cookie property to `true`.
145131
*/
146-
private abstract class OnAppendCookieTrackingConfig extends DataFlow::Configuration {
132+
abstract private class OnAppendCookieTrackingConfig extends DataFlow::Configuration {
147133
bindingset[this]
148134
OnAppendCookieTrackingConfig() { any() }
149135

@@ -186,6 +172,10 @@ private abstract class OnAppendCookieTrackingConfig extends DataFlow::Configurat
186172
}
187173

188174
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
189-
node2.asExpr() = any(PropertyRead other | other.getQualifier() = node1.asExpr())
175+
node2.asExpr() =
176+
any(PropertyRead pr |
177+
pr.getQualifier() = node1.asExpr() and
178+
pr.getProperty().getDeclaringType() instanceof MicrosoftAspNetCoreCookiePolicyAppendCookieContext
179+
)
190180
}
191181
}

csharp/ql/src/semmle/code/csharp/frameworks/microsoft/AspNetCore.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,13 @@ class MicrosoftAspNetCoreBuilderCookiePolicyOptions extends RefType {
319319
}
320320
}
321321

322+
/** The `Microsoft.AspNetCore.CookiePolicy.AppendCookieContext` class. */
323+
class MicrosoftAspNetCoreCookiePolicyAppendCookieContext extends RefType {
324+
MicrosoftAspNetCoreCookiePolicyAppendCookieContext() {
325+
this.hasQualifiedName("Microsoft.AspNetCore.CookiePolicy", "AppendCookieContext")
326+
}
327+
}
328+
322329
/** The `Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationOptions` class. */
323330
class MicrosoftAspNetCoreAuthenticationCookiesCookieAuthenticationOptions extends RefType {
324331
MicrosoftAspNetCoreAuthenticationCookiesCookieAuthenticationOptions() {

0 commit comments

Comments
 (0)