﻿# V5915\. OWASP\. A cookie is added without the 'Secure' attribute\. It can be transmitted over an unencrypted connection\.

The analyzer has detected that a server sets cookies without the Secure attribute\. 

The [Secure](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie) 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](https://top10.owasp.org/2025/A02_2025-Security_Misconfiguration/)\.

The example:

```cpp
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:

```cpp
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:

* [Session Management Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html#secure-attribute)
* [HTTP Strict Transport Security Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Strict_Transport_Security_Cheat_Sheet.html)