Skip to content

Commit dcf7e29

Browse files
Update comments and names
1 parent cbcf4c0 commit dcf7e29

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

csharp/ql/lib/semmle/code/csharp/security/auth/SecureCookies.qll

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
2-
* Provides classes and predicates for detecting insecure cookies.
2+
* Definitions for detecting insecure and non-httponly cookies.
33
*/
44

55
import csharp
66
import semmle.code.csharp.frameworks.microsoft.AspNetCore
77

88
/**
9-
* Holds if the expression is a variable with a sensitive name.
9+
* Holds if the expression is a sensitive string literal or a variable with a sensitive name.
1010
*/
1111
predicate isCookieWithSensitiveName(Expr cookieExpr) {
1212
exists(DataFlow::Node sink |
@@ -16,7 +16,7 @@ predicate isCookieWithSensitiveName(Expr cookieExpr) {
1616
}
1717

1818
/**
19-
* Configuration for tracking if a variable with a sensitive name is used as an argument.
19+
* Configuration for tracking if a sensitive string literal or a variable with a sensitive name is used as an argument.
2020
*/
2121
private module AuthCookieNameConfig implements DataFlow::ConfigSig {
2222
private predicate isAuthVariable(Expr expr) {
@@ -118,13 +118,13 @@ private signature string propertyName();
118118

119119
/**
120120
* Configuration for tracking if a callback used in `OnAppendCookie` sets a cookie property to `true`.
121+
*
122+
* ` getPropertyName` specifies the cookie property name to track.
121123
*/
122124
private module OnAppendCookieTrackingConfig<propertyName/0 getPropertyName> implements
123125
DataFlow::ConfigSig
124126
{
125-
/**
126-
* Specifies the cookie property name to track.
127-
*/
127+
/** Source is the parameter of a callback passed to `OnAppendCookie` */
128128
predicate isSource(DataFlow::Node source) {
129129
exists(PropertyWrite pw, Assignment delegateAssign, Callable c |
130130
pw.getProperty().getName() = "OnAppendCookie" and
@@ -145,6 +145,7 @@ private module OnAppendCookieTrackingConfig<propertyName/0 getPropertyName> impl
145145
)
146146
}
147147

148+
/** Sink is a property write that sets the given property to `true`. */
148149
predicate isSink(DataFlow::Node sink) {
149150
exists(PropertyWrite pw, Assignment a |
150151
pw.getProperty().getDeclaringType() instanceof MicrosoftAspNetCoreHttpCookieOptions and
@@ -177,7 +178,7 @@ private module OnAppendCookieSecureTrackingConfig =
177178
OnAppendCookieTrackingConfig<getPropertyNameSecure/0>;
178179

179180
/**
180-
* Tracks if a callback used in `OnAppendCookie` sets `Secure` to `true`.
181+
* Tracks if a callback used in `OnAppendCookie` sets `Secure` to `true`, and thus cookies appended to responses are secure by default.
181182
*/
182183
module OnAppendCookieSecureTracking = DataFlow::Global<OnAppendCookieSecureTrackingConfig>;
183184

@@ -190,6 +191,6 @@ private module OnAppendCookieHttpOnlyTrackingConfig =
190191
OnAppendCookieTrackingConfig<getPropertyNameHttpOnly/0>;
191192

192193
/**
193-
* Tracks if a callback used in `OnAppendCookie` sets `HttpOnly` to `true`.
194+
* Tracks if a callback used in `OnAppendCookie` sets `HttpOnly` to `true`, and thus cookies appended to responses are httponly by default.
194195
*/
195196
module OnAppendCookieHttpOnlyTracking = DataFlow::Global<OnAppendCookieHttpOnlyTrackingConfig>;

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
/**
2-
* @name 'HttpOnly' attribute is not set to true
3-
* @description Omitting the 'HttpOnly' attribute for security sensitive data allows
4-
* malicious JavaScript to steal it in case of XSS vulnerability. Always set
5-
* 'HttpOnly' to 'true' to authentication related cookie to make it
6-
* not accessible by JavaScript.
2+
* @name Cookie 'HttpOnly' attribute is not set to true
3+
* @description Sensitive cookies without the `HttpOnly` property set are accessible by client-side scripts such as JavaScript.
4+
* This makes them more vulnerable to being stolen by an XSS attack.
75
* @kind problem
86
* @problem.severity warning
7+
* @security-severity 5.0
98
* @precision high
109
* @id cs/web/cookie-httponly-not-set
1110
* @tags security
12-
* experimental
1311
* external/cwe/cwe-1004
1412
*/
1513

@@ -51,7 +49,7 @@ predicate nonHttpOnlyCookieOptionsCreation(ObjectCreation oc, MethodCall append)
5149
)
5250
}
5351

54-
predicate nonHttpOnlySensitiveCookieCreation(ObjectCreation oc) {
52+
predicate nonHttpOnlySystemWebSensitiveCookieCreation(ObjectCreation oc) {
5553
oc.getType() instanceof SystemWebHttpCookie and
5654
isCookieWithSensitiveName(oc.getArgument(0)) and
5755
(
@@ -88,7 +86,7 @@ predicate nonHttpOnlyCookieCall(Call c) {
8886
)
8987
)
9088
or
91-
nonHttpOnlySensitiveCookieCreation(c)
89+
nonHttpOnlySystemWebSensitiveCookieCreation(c)
9290
)
9391
}
9492

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
2-
* @name 'Secure' attribute is not set to true
3-
* @description Omitting the 'Secure' attribute allows data to be transmitted insecurely
4-
* using HTTP. Always set 'Secure' to 'true' to ensure that HTTPS
5-
* is used at all times.
2+
* @name Cookie 'Secure' attribute is not set to true
3+
* @description Cookies without the `Secure` flag may be sent in cleartext.
4+
* This makes them vulnerable to be intercepted by an attacker.
65
* @kind problem
76
* @problem.severity error
7+
* @security-severity 5.0
88
* @precision high
99
* @id cs/web/cookie-secure-not-set
1010
* @tags security
@@ -61,15 +61,14 @@ predicate insecureCookieAppend(Expr sink) {
6161
)
6262
}
6363

64-
predicate insecureCookieCreation(ObjectCreation oc) {
64+
predicate insecureSystemWebCookieCreation(ObjectCreation oc) {
6565
oc.getType() instanceof SystemWebHttpCookie and
6666
(
6767
secureFalse(oc)
6868
or
6969
// `Secure` property in `System.Web.HttpCookie` wasn't set, so a default value from config is used
70-
isPropertySet(oc, "Secure") and
70+
not isPropertySet(oc, "Secure") and
7171
// the default in config is not set to `true`
72-
// the `exists` below covers the `cs/web/requiressl-not-set`
7372
not exists(XmlElement element |
7473
element instanceof FormsElement and
7574
element.(FormsElement).isRequireSsl()
@@ -88,7 +87,7 @@ predicate insecureCookieCall(Call c) {
8887
insecureCookieAppend(c)
8988
)
9089
or
91-
insecureCookieCreation(c)
90+
insecureSystemWebCookieCreation(c)
9291
}
9392

9493
predicate insecureSecurePolicyAssignment(Assignment a, Expr val) {
@@ -105,12 +104,14 @@ predicate insecureSecurePolicyAssignment(Assignment a, Expr val) {
105104
)
106105
}
107106

108-
from Expr secureSink
107+
from Expr secureSink, string msg
109108
where
110-
insecureCookieCall(secureSink)
109+
insecureCookieCall(secureSink) and
110+
msg = "Cookie attribute 'Secure' is not set to true."
111111
or
112112
exists(Assignment a |
113113
secureSink = a.getRValue() and
114114
insecureSecurePolicyAssignment(a, _)
115-
)
116-
select secureSink, "Cookie attribute 'Secure' is not set to true."
115+
) and
116+
msg = "Cookie security policy sets cookies as insecure by default."
117+
select secureSink, msg

0 commit comments

Comments
 (0)