简体   繁体   English

CheckMarx 中等严重性警告 - 启动时的 HttpOnly cookie

[英]CheckMarx Medium severity warning - HttpOnly cookie at Startup

CheckMarx is flagging an error which looks like a false positive to me. CheckMarx 正在标记一个错误,这对我来说似乎是误报。 Our application is written in C# and uses ASP.NET Core.我们的应用程序是用 C# 编写的,并使用 ASP.NET Core。

The error is:错误是:

The web application's Startup method creates a cookie Startup, at line 22 of Startup.cs, and returns it in the response. Web 应用程序的 Startup 方法在 Startup.cs 的第 22 行创建一个 cookie Startup,并在响应中返回它。 However, the application is not configured to automatically set the cookie with the "httpOnly" attribute, and the code does not explicitly add this to the cookie.但是,应用程序没有配置为使用“httpOnly”属性自动设置 cookie,并且代码没有明确地将其添加到 cookie 中。

This is line 22:这是第 22 行:

public class Startup

And we do have the cookie policy set correctly:我们确实正确设置了 cookie 策略:

app.UseCookiePolicy(new CookiePolicyOptions
{
    HttpOnly = Microsoft.AspNetCore.CookiePolicy.HttpOnlyPolicy.Always
});

But CheckMarx is still flagging this warning.但 CheckMarx 仍在标记此警告。 And I do not think that my Startup class creates a cookie called Startup.而且我认为我的 Startup 类不会创建一个名为 Startup 的 cookie。

I found a similar post here (unanswered) - https://github.com/Azure/azure-functions-vs-build-sdk/issues/469 .我在这里找到了类似的帖子(未答复) - https://github.com/Azure/azure-functions-vs-build-sdk/issues/469

So is this a false positive?那么这是误报吗? And how do I get CheckMarx to stop flagging it?以及如何让 CheckMarx 停止标记它?

The only way to remove those warnings was to rename the Startup class to something else, for example to Startup123.删除这些警告的唯一方法是将 Startup 类重命名为其他名称,例如 Startup123。

Nothing else removes the warning, and I think it is definitely a false positive.没有其他方法可以消除警告,我认为这绝对是误报。

For .NET Core 3.1, I fixed this vulnerability warning by configuring the service in Startup class and then using CookiePolicy middleware.对于 .NET Core 3.1,我通过在 Startup 类中配置服务然后使用 CookiePolicy 中间件来修复此漏洞警告。

In ConfigureServices function:在 ConfigureServices 函数中:

services.Configure<CookiePolicyOptions>(options =>
{
    options.Secure = CookieSecurePolicy.Always;
});

In Configure function:在配置功能中:

app.UseCookiePolicy();

This could be also used to fix HttpOnlyPolicy vulnerability in middleware like:这也可以用来修复中间件中的 HttpOnlyPolicy 漏洞,例如:

services.Configure<CookiePolicyOptions>(options =>
{
    options.HttpOnly = HttpOnlyPolicy.Always;
    options.Secure = CookieSecurePolicy.Always;
});

Remember to use the correct order for middlewares.请记住对中间件使用正确的顺序。 You could refer to ASP.NET Core Middleware Docs to read more about and get some examples.您可以参考ASP.NET Core Middleware Docs以了解更多信息并获取一些示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM