Skip to content

Commit 31caadf

Browse files
Update qhelp
1 parent aad8320 commit 31caadf

File tree

3 files changed

+50
-29
lines changed

3 files changed

+50
-29
lines changed

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,57 @@
44
<qhelp>
55

66
<overview>
7-
<p>
8-
Cookies without <code>HttpOnly</code> flag are accessible to JavaScript running in the same origin. In case of
9-
Cross-Site Scripting (XSS) vulnerability the cookie can be stolen by malicious script.
10-
</p>
7+
<p>Cookies without the <code>HttpOnly</code> flag set are accessible to client-side scripts such as JavaScript running in the same origin.
8+
In case of a Cross-Site Scripting (XSS) vulnerability, the cookie can be stolen by a malicious script.
9+
If a sensitive cookie does not need to be accessed directly by client-side JS, the <code>HttpOnly</code> flag should be set.</p>
1110
</overview>
1211

1312
<recommendation>
1413
<p>
15-
Protect sensitive cookies, such as related to authentication, by setting <code>HttpOnly</code> to <code>true</code> to make
16-
them not accessible to JavaScript. In ASP.NET case it is also possible to set the attribute via <code>&lt;httpCookies&gt;</code> element
17-
of <code>web.config</code> with the attribute <code>httpOnlyCookies="true"</code>.
14+
Set the <code>HttpOnly</code> flag to <code>true</code> for authentication cookies to ensure they are not accessible to client-side scripts.
15+
</p>
16+
<p>
17+
When using ASP.NET Core, <code>CookiePolicyOptions</code> can be used to set a default policy for cookies.
18+
19+
When using ASP.NET Web Forms, a default may also be configured in the <code>Web.config</code> file, using the <code>httpOnlyCookies</code> attribute of the
20+
the <code>&lt;httpCookies&gt;</code> element.
1821
</p>
1922
</recommendation>
2023

2124
<example>
2225

2326
<p>
24-
In the example below <code>Microsoft.AspNetCore.Http.CookieOptions.HttpOnly</code> is set to <code>true</code>.
27+
In the example below, <code>Microsoft.AspNetCore.Http.CookieOptions.HttpOnly</code> is set to <code>true</code>.
2528
</p>
2629

2730
<sample src="httponlyflagcore.cs" />
2831

2932
<p>
30-
In the following example <code>CookiePolicyOptions</code> are set programmatically to configure defaults.
33+
In the following example, <code>CookiePolicyOptions</code> are set programmatically to configure defaults.
3134
</p>
3235

3336
<sample src="cookiepolicyoptions.cs" />
3437

3538
<p>
36-
In the example below <code>System.Web.HttpCookie.HttpOnly</code> is set to <code>true</code>.
39+
In the example below, <code>System.Web.HttpCookie.HttpOnly</code> is set to <code>true</code>.
3740
</p>
3841

3942
<sample src="httponlyflag.cs" />
4043

44+
<p>
45+
In the example below, the <code>httpOnlyCookies</code> attribute is set to <code>true</code> in the <code>Web.config</code> file.
46+
</p>
47+
<sample src="Web.config"/>
48+
4149
</example>
4250

4351
<references>
4452

45-
<li><a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.cookieoptions.httponly">CookieOptions.HttpOnly Property,</a></li>
46-
<li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie">Set-Cookie</a> Header,</li>
47-
<li><a href="https://msdn.microsoft.com/en-us/library/system.web.httpcookie.httponly(v=vs.110).aspx">HttpCookie.HttpOnly Property,</a></li>
48-
<li><a href="https://msdn.microsoft.com/library/ms228262%28v=vs.100%29.aspx">httpCookies Element,</a></li>
53+
<li>ASP.Net Core docs: <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.cookieoptions.httponly">CookieOptions.HttpOnly Property</a>.</li>
54+
<li>MDN: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie">Set-Cookie</a> Header</li>.
55+
<li>Web Forms docs: <a href="https://msdn.microsoft.com/en-us/library/system.web.httpcookie.httponly(v=vs.110).aspx">HttpCookie.HttpOnly Property</a>.</li>
56+
<li>Web Forms docs: <a href="https://msdn.microsoft.com/library/ms228262%28v=vs.100%29.aspx">httpCookies Element</a>.</li>
57+
<li>PortSwigger: <a href="https://portswigger.net/kb/issues/00500600_cookie-without-httponly-flag-set">Cookie without HttpOnly flag set</a></li>
4958

5059
</references>
5160
</qhelp>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<system.web>
4+
<httpCookies httpOnlyCookies="true"/>
5+
</system.web>
6+
</configuration>

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,32 @@
44
<qhelp>
55

66
<overview>
7-
<p>
8-
Sensitive data that is transmitted using HTTP is vulnerable to being read by a third party. By default,
9-
cookies are sent via HTTP, not HTTPS.
10-
</p>
7+
<p>Cookies without the <code>Secure</code> flag set may be transmitted using HTTP instead of HTTPS.
8+
This leaves them vulnerable to being read by a third party attacker. If a sensitive cookie such as a session
9+
key is intercepted this way, it would allow the attacker to perform actions on a user's behalf.</p>
1110
</overview>
1211

1312
<recommendation>
1413
<p>
15-
In ASP.NET case when using cookies ensure that HTTPS is used by setting the property <code>Microsoft.AspNetCore.Http.CookieOptions.Secure</code> to <code>true</code>.
14+
When using ASP.NET Core, ensure cookies have the secure flag set by setting <code>Microsoft.AspNetCore.Http.CookieOptions.Secure</code> to <code>true</code>, or
15+
using <code>CookiePolicyOptions</code> to set a default security policy.
1616
</p>
1717
<p>
18-
In ASP.NET Core case when using cookies, ensure that HTTPS is used, either via the <code>&lt;forms&gt;</code> attribute above, or
19-
the <code>&lt;httpCookies&gt;</code> element, with the attribute <code>requireSSL="true"</code>. It is also possible to require cookies
20-
to use HTTPS programmatically, by setting the property <code>System.Web.HttpCookie.Secure</code> to <code>true</code>.
18+
When using ASP.NET Web Forms, cookies can be configured as secure by default in the <code>Web.config</code> file, setting the <code>requireSSL</code> attribute to <code>true</code> in the <code>forms</code> or <code>httpCookies</code> element.
19+
Cookies may also be set to be secure programmatically by setting the <code>System.Web.HttpCookie.Secure</code> attribute to <code>true</code>.
2120
</p>
2221
</recommendation>
2322

2423
<example>
2524

2625
<p>
27-
In the example below <code>Microsoft.AspNetCore.Http.CookieOptions.Secure</code> is set to <code>true</code> programmatically.
26+
In the example below, <code>Microsoft.AspNetCore.Http.CookieOptions.Secure</code> is set to <code>true</code>.
2827
</p>
2928

3029
<sample src="secureflagcore.cs" />
3130

3231
<p>
33-
In the following example <code>CookiePolicyOptions</code> are set programmatically to configure defaults.
32+
In the following example, <code>CookiePolicyOptions</code> are set programmatically to configure defaults.
3433
</p>
3534

3635
<sample src="cookiepolicyoptions.cs" />
@@ -41,15 +40,22 @@ In the example below <code>System.Web.HttpCookie.Secure</code> is set to <code>t
4140

4241
<sample src="secureflag.cs" />
4342

43+
<p>
44+
In the example below, the <code>requireSSL</code> attribute is set to <code>true</code> in the <code>forms</code> element of the <code>Web.config</code> file.
45+
</p>
46+
<sample src="Web.config" />
47+
4448
</example>
4549

4650
<references>
4751

48-
<li><a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.cookieoptions.secure">CookieOptions.Secure Property,</a></li>
49-
<li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie">Set-Cookie</a> Header,</li>
50-
<li><a href="https://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.requiressl(v=vs.110).aspx">FormsAuthentication.RequireSSL Property,</a></li>
51-
<li><a href="https://msdn.microsoft.com/en-us/library/1d3t3c61(v=vs.100).aspx">forms Element for authentication,</a></li>
52-
<li><a href="https://msdn.microsoft.com/library/ms228262%28v=vs.100%29.aspx">httpCookies Element,</a></li>
52+
<li>ASP.NET Core docs: <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.cookieoptions.secure">CookieOptions.Secure Property</a>.</li>
53+
<li>MDN: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie">Set-Cookie</a> Header.</li>
54+
<li>Web Forms docs: <a href="https://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.requiressl(v=vs.110).aspx">FormsAuthentication.RequireSSL Property</a>.</li>
55+
<li>Web Forms docs: <a href="https://msdn.microsoft.com/en-us/library/1d3t3c61(v=vs.100).aspx">forms Element for authentication</a>.</li>
56+
<li>Web Forms docs: <a href="https://msdn.microsoft.com/library/ms228262%28v=vs.100%29.aspx">httpCookies Element</a>.</li>
57+
<li>Detectify: <a href="https://support.detectify.com/support/solutions/articles/48001048982-cookie-lack-secure-flag">Cookie lack Secure flag</a>.</li>
58+
<li>PortSwigger: <a href="https://portswigger.net/kb/issues/00500200_tls-cookie-without-secure-flag-set">TLS cookie without secure flag set</a>.</li>
5359

5460
</references>
5561
</qhelp>

0 commit comments

Comments
 (0)