Cookie Without the Secure Attribute

A sensitive cookie, often the session cookie, is set without the Secure attribute, so the browser will also send it over unencrypted HTTP connections to the same host.

SeverityLow
CVSS 3.13.1 CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:N/A:N Open in the calculator
CVSS 4.02.3 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-614: Sensitive Cookie in HTTPS Session Without 'Secure' Attribute
OWASP Top 10A02:2025 Security Misconfiguration
MITRE ATT&CKT1539 Steal Web Session Cookie, T1557 Adversary-in-the-Middle
CategorySecurity Misconfiguration

Description

The application sets one or more sensitive cookies, such as session identifiers or authentication tokens, without the Secure attribute. The attribute tells the browser to send the cookie only over HTTPS. Without it, the browser includes the cookie in any plain HTTP request to the same host, even if the application itself is only ever used over HTTPS.

An attacker able to observe and tamper with the user's network traffic, such as on a shared wireless network, does not need the user to visit an HTTP page of the application deliberately. Any HTTP navigation to the host sends the cookie, and by tampering with the user's other unencrypted traffic the attacker can cause one, for example by redirecting an HTTP page the user visits to the host's http:// address, then answer that request on the network, even if the server does not listen on port 80, and read the cookie. Where the cookie is a session identifier, the attacker can then use the session as the user, with the user's privileges, until it expires or is ended. An attacker in that position can also set or overwrite cookies that lack the attribute through a forged HTTP response.

The attack needs a position on the network path while the user's session is active, which limits the opportunity. An HTTP Strict Transport Security (HSTS) policy covering the host stops the browser making such requests, which removes most of the opportunity, but only once the browser has received it.

The issue is identified by inspecting the Set-Cookie headers or the browser's cookie storage. Cookies holding only non-sensitive values, such as display preferences, do not need the attribute for security, though setting it on every cookie is simpler.

Remediation

Set the Secure attribute on every cookie that carries a session identifier, authentication token or other sensitive value, and preferably on all cookies, since the application is served over HTTPS:

  • Enable the framework or server setting that marks session cookies as secure, for example session.cookie_secure in PHP, requireSSL on httpCookies and on forms authentication in ASP.NET, CookieSecurePolicy.Always in ASP.NET Core, cookie.secure in express-session, or <secure>true</secure> under session-config and cookie-config in a Java web.xml.
  • Where a load balancer or proxy terminates TLS, make sure the application knows the original request used HTTPS, for example through a trusted X-Forwarded-Proto header, since some frameworks only set the attribute on requests they believe are secure.
  • Use the __Host- name prefix for session cookies where possible: browsers only accept such a cookie when it has Secure, Path=/ and no Domain attribute.
  • Enable HSTS on the host so that browsers do not make HTTP requests to it at all.
Set-Cookie: __Host-id=38afes7a8; Secure; HttpOnly; SameSite=Lax; Path=/

Confirm the fix by inspecting the Set-Cookie headers after login and checking that the cookie is not sent with an HTTP request to the host.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Web Applications Findings

Every Web Applications finding