A cookie policy sends cookies over plain HTTP or lets scripts read them

tx0/csharp:weak-cookie-policyrecommendedwarningsecurity/authn-authzdepth fastsecurity, cwe-614

What it finds

CookieSecurePolicy.None lets cookies travel over unencrypted connections, where they can be read and replayed, and HttpOnlyPolicy.None lets scripts, including injected ones, read them. The policies of ASP.NET Core apply to every cookie of the app.

From the rule's source, weak_cookie_policy.rs.

Example from the rule's tests
using Microsoft.AspNetCore.Http; class Cookies{    void Set(CookieBuilder cookie)    {        cookie.SecurePolicy = CookieSecurePolicy.None;tx0 reports: CookieSecurePolicy.None weakens the protection of every cookie        cookie.SecurePolicy = CookieSecurePolicy.Always;    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/csharp:weak-cookie-policy" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/csharp:weak-cookie-policy] reason="..."

tx0 explain tx0/csharp:weak-cookie-policy shows the same in the terminal. Found a false positive? Report it.