The analyzer has detected that a server sets cookies without the Secure attribute.
The Secure attribute tells the browser that cookies can be sent only over a secure HTTPS connection. If it's missing, the browser may send cookies via a standard HTTP request to the same domain if an attacker triggers such a request. All the user has to do is click a link starting with http://.... This works even if the website can be accessed only via HTTPS.
If a leak happens, the attacker, who is eavesdropping on the network traffic (for example, on an open Wi-Fi network), receives the cookie value in plain text. If it contains a session ID or an access token, that is enough to hijack the session and act on the user's behalf.
Vulnerabilities related to the missing Secure attribute in cookies are included in the OWASP Top 10 Application Security Risks 2025: A02:2025 Security Misconfiguration.
The example:
func Login(w http.ResponseWriter, r *http.Request) {
....
token := createSession(user)
http.SetCookie(w, &http.Cookie{
Name: "session_id",
Value: token,
Path: "/",
HttpOnly: true,
})
....
}
The Secure field in the http.Cookie structure is not set, so its default value is false. The HttpOnly attribute prevents JavaScript from reading cookies, but it does not affect the protocol used to transmit them.
To ensure that cookies are transmitted only via HTTPS, the Secure field must be explicitly set:
func Login(w http.ResponseWriter, r *http.Request) {
....
token := createSession(user)
http.SetCookie(w, &http.Cookie{
Name: "session_id",
Value: token,
Path: "/",
Secure: true,
HttpOnly: true,
})
....
}
You can find more security recommendations on the OWASP Cheat Sheet Series pages, such as:
This diagnostic rule is classified as:
|