The session cookies of web applications must have security attributes (HttpOnly, Secure, SameSite) and prefixes (e.g. __Host-).
When you have web applications that handle sessions, you can use different attributes to improve the security related to the cookies that handle these sessions. The attributes HttpOnly and Secure prevent the theft of the session cookie by denying the browser visibility and access to it (even when Cross Site Scripting [XSS] attacks are used) and allow the cookie to be sent only when the request is encrypted (using HTTPS), in this manner, session theft is greatly mitigated.
Implement the HttpOnly attribute: If the HttpOnly attribute is present in the HTTP response header, the cookie can not be accessed using client side scripts. As a result and even if there exist a cross-site scripting (XSS) vulnerability and a user accidentally accesses the link that exploits this vulnerability, the browser will not reveal the cookie to a third party. * If a browser does not support HttpOnly and the website tries to set the HttpOnly attribute, said attribute will be ignored by the browser thus creating a traditional cookie accessible by scripts. As a result, the cookie (usually a session cookie) becomes vulnerable to theft or modification by a malicious script.
Implement the Secure attribute: The secure attribute is an option that can be applied from the application server when a new cookie is sent to the user in a HTTP response. The purpose of the secure attribute is to prevent cookies from being viewed by unauthorized third parties due to the plain text transmission of the cookie.
Access-Control-Allow-Origin header set to *.
clientaccesspolicy.xml file granting unintended access to Silverlight controls.
crossdomain.xml file granting unintended access to Flash.
An attacker generates a script that is executed by a valid authenticated user without their knowledge, without the HTTPOnly and Secure attributes the script sends information to the attacker containing the session cookie used for session theft.
An attacker captures HTTP traffic using a Man in The Middle (MiTM) attack intercepting request and responses in plain text and extracting the session cookie used for session theft.
Layer: Application layer.
Asset: Session management.
Type of Control: Procedure.
CWE-352: Cross-Site Request Forgery (CSRF). The web application does not, or can not, sufficiently verify whether a well-formed, valid, consistent request was intentionally provided by the user who submitted the request.
CWE-614: Sensitive Cookie in HTTPS Session Without 'Secure' Attribute. The Secure attribute for sensitive cookies in HTTPS sessions is not set, which could cause the user agent to send those cookies in plaintext over an HTTP session.
CWE-1004: Sensitive Cookie Without 'HttpOnly' Flag. The software uses a cookie to store sensitive information, but the cookie is not marked with the HttpOnly flag.
NIST 800-63B 7.1.1 Browser Cookies Cookies SHALL be tagged to be accessible only on secure (HTTPS) sessions.
NIST 800-63B 7.1.1 Browser Cookies Cookies SHALL be accessible to the minimum practical set of hostnames and paths.
OWASP-ASVS v4.0.1 V3.2 Session Binding Requirements.(3.2.3) Verify the application only stores session tokens in the browser using secure methods such as appropriately secured cookies (see section 3.4) or HTML 5 session storage.
OWASP-ASVS v4.0.1 V3.4 Cookie-based Session Management.(3.4.1) Verify that cookie-based session tokens have the 'Secure' attribute set.
OWASP-ASVS v4.0.1 V3.4 Cookie-based Session Management.(3.4.2) Verify that cookie-based session tokens have the 'HttpOnly' attribute set.
OWASP-ASVS v4.0.1 V3.4 Cookie-based Session Management.(3.4.3) Verify that cookie-based session tokens utilize the 'SameSite' attribute to limit exposure to cross-site request forgery attacks.
OWASP-ASVS v4.0.1 V3.4 Cookie-based Session Management.(3.4.4) Verify that cookie-based session tokens use "__Host-" prefix (see references) to provide session cookie confidentiality.
OWASP-ASVS v4.0.1 V3.4 Cookie-based Session Management.(3.4.5) Verify that if the application is published under a domain name with other applications that set or use session cookies that might override or disclose the session cookies, the path attribute in cookie-based session tokens is set using the most precise path possible.
OWASP-ASVS v4.0.1 V4.2 Operation Level Access Control.(4.2.2) Verify that the application or framework enforces a strong anti-CSRF mechanism to protect authenticated functionality, and effective anti-automation or anti-CSRF protects unauthenticated functionality.