-
Couldn't load subscription status.
- Fork 1.8k
C#: Promote insecure cookie and httponly cookie queries #20692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
C#: Promote insecure cookie and httponly cookie queries #20692
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR promotes the cs/web/cookie-secure-not-set and cs/web/cookie-httponly-not-set queries from experimental to the main query pack, making them available for standard security analysis.
Key changes:
- Moved cookie security queries from experimental to main Security Features directory
- Reorganized test structure to align with promoted query locations
- Updated query metadata and documentation for production readiness
Reviewed Changes
Copilot reviewed 111 out of 137 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
csharp/ql/src/Security Features/CWE-614/CookieWithoutSecure.ql |
New production query for detecting cookies without Secure attribute |
csharp/ql/src/Security Features/CWE-1004/CookieWithoutHttpOnly.ql |
New production query for detecting cookies without HttpOnly attribute |
csharp/ql/lib/semmle/code/csharp/security/auth/SecureCookies.qll |
Updated library removing deprecated annotations and improving documentation |
csharp/ql/test/query-tests/Security Features/CWE-614/InsecureCookie/ |
New test structure for Secure attribute query |
csharp/ql/test/query-tests/Security Features/CWE-1004/HttpOnlyCookie/ |
New test structure for HttpOnly attribute query |
csharp/ql/test/experimental/Security Features/CWE-614/ |
Removed experimental tests (moved to main) |
csharp/ql/test/experimental/Security Features/CWE-1004/ |
Removed experimental tests (moved to main) |
csharp/ql/src/experimental/Security Features/CWE-614/ |
Removed experimental query sources |
csharp/ql/src/experimental/Security Features/CWE-1004/ |
Removed experimental query sources |
csharp/ql/src/change-notes/2025-10-24-insecure-cookie-query-promote.md |
Release note documenting query promotion |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| @@ -1,13 +1,12 @@ | |||
| /** | |||
| * Provides classes and predicates for detecting insecure cookies. | |||
| * Definitions for detecting insecure and non-httponly cookies. | |||
Copilot
AI
Oct 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description should use consistent terminology. Change 'non-httponly' to 'non-HttpOnly' to match the casing used throughout the codebase and in the HttpOnly property name.
| * Definitions for detecting insecure and non-httponly cookies. | |
| * Definitions for detecting insecure and non-HttpOnly cookies. |
| <references> | ||
|
|
||
| <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> | ||
| <li>MDN: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie">Set-Cookie</a> Header</li>. |
Copilot
AI
Oct 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the extra period after the closing </li> tag - the period should be inside the tag or removed entirely.
| <li>MDN: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie">Set-Cookie</a> Header</li>. | |
| <li>MDN: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie">Set-Cookie</a> Header.</li> |
|
QHelp previews: csharp/ql/src/Security Features/CWE-1004/CookieWithoutHttpOnly.qhelpCookie 'HttpOnly' attribute is not set to trueCookies without the RecommendationSet the When using ASP.NET Core, ExampleIn the example below, class MyController : Controller
{
void Login()
{
var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions() { HttpOnly = true };
Response.Cookies.Append("auth", "secret", cookieOptions);
}
}In the following example, public class Startup
{
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseCookiePolicy(new CookiePolicyOptions()
{
Secure = Microsoft.AspNetCore.Http.CookieSecurePolicy.Always,
HttpOnly = Microsoft.AspNetCore.CookiePolicy.HttpOnlyPolicy.Always
});
}
}In the example below, class MyController : Controller
{
void Login()
{
var cookie = new System.Web.HttpCookie("cookieName") { HttpOnly = true };
}
}In the example below, the References
csharp/ql/src/Security Features/CWE-614/CookieWithoutSecure.qhelpCookie 'Secure' attribute is not set to trueCookies without the RecommendationWhen using ASP.NET Core, ensure cookies have the secure flag set by setting When using ASP.NET Web Forms, cookies can be configured as secure by default in the ExampleIn the example below, class MyController : Controller
{
void Login()
{
var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions() { Secure = true };
Response.Cookies.Append("auth", "secret", cookieOptions);
}
}In the following example, public class Startup
{
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseCookiePolicy(new CookiePolicyOptions()
{
Secure = Microsoft.AspNetCore.Http.CookieSecurePolicy.Always,
HttpOnly = Microsoft.AspNetCore.CookiePolicy.HttpOnlyPolicy.Always
});
}
}In the example below class MyController : Controller
{
void Login()
{
var cookie = new System.Web.HttpCookie("cookieName") { Secure = true };
}
}In the example below, the References
|
Promotes the
cs/web/cookie-secure-not-setandcs/web/cookie-httponly-not-setqueries from experimental.