11/**
2- * Provides classes and predicates for detecting insecure cookies.
2+ * Definitions for detecting insecure and non-httponly cookies.
33 */
44
55import csharp
66import 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 */
1111predicate 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 */
2121private 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 */
122124private 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 */
182183module 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 */
195196module OnAppendCookieHttpOnlyTracking = DataFlow:: Global< OnAppendCookieHttpOnlyTrackingConfig > ;
0 commit comments