@@ -17,89 +17,91 @@ import csharp
1717import semmle.code.asp.WebConfig
1818import semmle.code.csharp.frameworks.system.Web
1919import semmle.code.csharp.frameworks.microsoft.AspNetCore
20- import experimental.dataflow.flowsources.AuthCookie
20+ deprecated import experimental.dataflow.flowsources.AuthCookie
2121
22- from Expr httpOnlySink
23- where
24- exists ( Assignment a , Expr val |
25- httpOnlySink = a .getRValue ( ) and
26- val .getValue ( ) = "false" and
27- (
28- exists ( ObjectCreation oc |
29- getAValueForProp ( oc , a , "HttpOnly" ) = val and
30- (
31- oc .getType ( ) instanceof SystemWebHttpCookie and
32- isCookieWithSensitiveName ( oc .getArgument ( 0 ) )
33- or
34- exists ( MethodCall mc , MicrosoftAspNetCoreHttpResponseCookies iResponse |
35- oc .getType ( ) instanceof MicrosoftAspNetCoreHttpCookieOptions and
36- iResponse .getAppendMethod ( ) = mc .getTarget ( ) and
37- isCookieWithSensitiveName ( mc .getArgument ( 0 ) ) and
38- // there is no callback `OnAppendCookie` that sets `HttpOnly` to true
39- not OnAppendCookieHttpOnlyTracking:: flowTo ( _) and
40- // Passed as third argument to `IResponseCookies.Append`
41- exists ( DataFlow:: Node creation , DataFlow:: Node append |
42- CookieOptionsTracking:: flow ( creation , append ) and
43- creation .asExpr ( ) = oc and
44- append .asExpr ( ) = mc .getArgument ( 2 )
22+ deprecated query predicate problems ( Expr httpOnlySink , string message ) {
23+ (
24+ exists ( Assignment a , Expr val |
25+ httpOnlySink = a .getRValue ( ) and
26+ val .getValue ( ) = "false" and
27+ (
28+ exists ( ObjectCreation oc |
29+ getAValueForProp ( oc , a , "HttpOnly" ) = val and
30+ (
31+ oc .getType ( ) instanceof SystemWebHttpCookie and
32+ isCookieWithSensitiveName ( oc .getArgument ( 0 ) )
33+ or
34+ exists ( MethodCall mc , MicrosoftAspNetCoreHttpResponseCookies iResponse |
35+ oc .getType ( ) instanceof MicrosoftAspNetCoreHttpCookieOptions and
36+ iResponse .getAppendMethod ( ) = mc .getTarget ( ) and
37+ isCookieWithSensitiveName ( mc .getArgument ( 0 ) ) and
38+ // there is no callback `OnAppendCookie` that sets `HttpOnly` to true
39+ not OnAppendCookieHttpOnlyTracking:: flowTo ( _) and
40+ // Passed as third argument to `IResponseCookies.Append`
41+ exists ( DataFlow:: Node creation , DataFlow:: Node append |
42+ CookieOptionsTracking:: flow ( creation , append ) and
43+ creation .asExpr ( ) = oc and
44+ append .asExpr ( ) = mc .getArgument ( 2 )
45+ )
4546 )
4647 )
4748 )
48- )
49- or
50- exists ( PropertyWrite pw |
51- (
52- pw .getProperty ( ) .getDeclaringType ( ) instanceof MicrosoftAspNetCoreHttpCookieBuilder or
53- pw . getProperty ( ) . getDeclaringType ( ) instanceof
54- MicrosoftAspNetCoreAuthenticationCookiesCookieAuthenticationOptions
55- ) and
56- pw . getProperty ( ) . getName ( ) = "HttpOnly" and
57- a . getLValue ( ) = pw and
58- DataFlow :: localExprFlow ( val , a . getRValue ( ) )
49+ or
50+ exists ( PropertyWrite pw |
51+ (
52+ pw . getProperty ( ) . getDeclaringType ( ) instanceof MicrosoftAspNetCoreHttpCookieBuilder or
53+ pw .getProperty ( ) .getDeclaringType ( ) instanceof
54+ MicrosoftAspNetCoreAuthenticationCookiesCookieAuthenticationOptions
55+ ) and
56+ pw . getProperty ( ) . getName ( ) = "HttpOnly" and
57+ a . getLValue ( ) = pw and
58+ DataFlow :: localExprFlow ( val , a . getRValue ( ) )
59+ )
5960 )
6061 )
61- )
62- or
63- exists ( Call c |
64- httpOnlySink = c and
65- (
66- exists ( MicrosoftAspNetCoreHttpResponseCookies iResponse , MethodCall mc |
67- // default is not configured or is not set to `Always`
68- not getAValueForCookiePolicyProp ( "HttpOnly" ) . getValue ( ) = "1" and
69- // there is no callback `OnAppendCookie` that sets `HttpOnly` to true
70- not OnAppendCookieHttpOnlyTracking :: flowTo ( _ ) and
71- iResponse . getAppendMethod ( ) = mc .getTarget ( ) and
72- isCookieWithSensitiveName ( mc . getArgument ( 0 ) ) and
73- (
74- // `HttpOnly` property in `CookieOptions` passed to IResponseCookies.Append(...) wasn't set
75- exists ( ObjectCreation oc |
76- oc = c and
77- oc . getType ( ) instanceof MicrosoftAspNetCoreHttpCookieOptions and
78- not isPropertySet ( oc , "HttpOnly" ) and
79- exists ( DataFlow :: Node creation |
80- CookieOptionsTracking :: flow ( creation , _ ) and
81- creation . asExpr ( ) = oc
62+ or
63+ exists ( Call c |
64+ httpOnlySink = c and
65+ (
66+ exists ( MicrosoftAspNetCoreHttpResponseCookies iResponse , MethodCall mc |
67+ // default is not configured or is not set to `Always`
68+ not getAValueForCookiePolicyProp ( "HttpOnly" ) . getValue ( ) = "1" and
69+ // there is no callback `OnAppendCookie` that sets `HttpOnly` to true
70+ not OnAppendCookieHttpOnlyTracking :: flowTo ( _ ) and
71+ iResponse . getAppendMethod ( ) = mc . getTarget ( ) and
72+ isCookieWithSensitiveName ( mc .getArgument ( 0 ) ) and
73+ (
74+ // `HttpOnly` property in `CookieOptions` passed to IResponseCookies.Append(...) wasn't set
75+ exists ( ObjectCreation oc |
76+ oc = c and
77+ oc . getType ( ) instanceof MicrosoftAspNetCoreHttpCookieOptions and
78+ not isPropertySet ( oc , "HttpOnly" ) and
79+ exists ( DataFlow :: Node creation |
80+ CookieOptionsTracking :: flow ( creation , _ ) and
81+ creation . asExpr ( ) = oc
82+ )
8283 )
84+ or
85+ // IResponseCookies.Append(String, String) was called, `HttpOnly` is set to `false` by default
86+ mc = c and
87+ mc .getNumberOfArguments ( ) < 3
8388 )
84- or
85- // IResponseCookies.Append(String, String) was called, `HttpOnly` is set to `false` by default
86- mc = c and
87- mc .getNumberOfArguments ( ) < 3
8889 )
89- )
90- or
91- exists ( ObjectCreation oc |
92- oc = c and
93- oc .getType ( ) instanceof SystemWebHttpCookie and
94- isCookieWithSensitiveName ( oc . getArgument ( 0 ) ) and
95- // the property wasn't explicitly set, so a default value from config is used
96- not isPropertySet ( oc , "HttpOnly" ) and
97- // the default in config is not set to `true`
98- not exists ( XmlElement element |
99- element instanceof HttpCookiesElement and
100- element . ( HttpCookiesElement ) . isHttpOnlyCookies ( )
90+ or
91+ exists ( ObjectCreation oc |
92+ oc = c and
93+ oc . getType ( ) instanceof SystemWebHttpCookie and
94+ isCookieWithSensitiveName ( oc .getArgument ( 0 ) ) and
95+ // the property wasn't explicitly set, so a default value from config is used
96+ not isPropertySet ( oc , "HttpOnly" ) and
97+ // the default in config is not set to `true`
98+ not exists ( XmlElement element |
99+ element instanceof HttpCookiesElement and
100+ element . ( HttpCookiesElement ) . isHttpOnlyCookies ( )
101+ )
101102 )
102103 )
103104 )
104- )
105- select httpOnlySink , "Cookie attribute 'HttpOnly' is not set to true."
105+ ) and
106+ message = "Cookie attribute 'HttpOnly' is not set to true."
107+ }
0 commit comments