A cookie is made without Secure or without HttpOnly

tx0/go:cookie-without-protectionstrictwarningsecurity, cwe-614, cwe-1004

What it finds

http.Cookie{Name: "session", Value: id}: without Secure, the browser also sends the cookie over plain HTTP, where anyone on the path can read it; without HttpOnly, scripts in the page can read it, so a single injected script steals the session. A cookie that scripts must read, or a site served only over HTTP during development, is a deliberate exception, so the rule is strict.

A composite literal of http.Cookie, resolved through the imports, is reported when it does not set Secure, or HttpOnly, to an expression other than false.

From the rule's source, cookie_without_protection.rs.

Example from the rule's tests
package p import "net/http" func f(w http.ResponseWriter, id string) {	http.SetCookie(w, &http.Cookie{Name: "session", Value: id})tx0 reports: this cookie is made without Secure and HttpOnly	http.SetCookie(w, &http.Cookie{Name: "theme", Value: "dark", Secure: true})tx0 reports: this cookie is made without HttpOnly	http.SetCookie(w, &http.Cookie{Name: "session", Value: id, Secure: true, HttpOnly: true})}
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 strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:cookie-without-protection" = "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/go:cookie-without-protection] reason="..."

tx0 explain tx0/go:cookie-without-protection shows the same in the terminal. Found a false positive? Report it.