CWE-1275: Sensitive Cookie with Improper SameSite Attribute

Description

The SameSite attribute for sensitive cookies is not set, or an insecure value is used.

Submission Date :

June 19, 2020, midnight

Modification Date :

2023-10-26 00:00:00+00:00

Organization :

Veracode
Extended Description

The SameSite attribute controls how cookies are sent for cross-domain requests. This attribute may have three values: 'Lax', 'Strict', or 'None'. If the 'None' value is used, a website may create a cross-domain POST HTTP request to another website, and the browser automatically adds cookies to this request. This may lead to Cross-Site-Request-Forgery (CSRF) attacks if there are no additional protections in place (such as Anti-CSRF tokens).

Example Vulnerable Codes

Example - 1

In this example, a cookie is used to store a session ID for a client's interaction with a website. The snippet of code below establishes a new cookie to hold the sessionID.


let sessionId = generateSessionId()let cookieOptions = { domain: 'example.com' }response.cookie('sessionid', sessionId, cookieOptions)

Since the sameSite attribute is not specified, the cookie will be sent to the website with each request made by the client. An attacker can potentially perform a CSRF attack by using the following malicious page:




<input type="hidden" name="newEmail" value="[email protected]" />
<form id=evil action="http://local:3002/setEmail" method="POST"></form>
<html><script>evil.submit()</script></html>

When the client visits this malicious web page, it submits a '/setEmail' POST HTTP request to the vulnerable website. Since the browser automatically appends the 'sessionid' cookie to the request, the website automatically performs a 'setEmail' action on behalf of the client.

To mitigate the risk, use the sameSite attribute of the 'sessionid' cookie set to 'Strict'.


let sessionId = generateSessionId()let cookieOptions = { domain: 'example.com', sameSite: 'Strict' }response.cookie('sessionid', sessionId, cookieOptions)

Related Weaknesses

This table shows the weaknesses and high level categories that are related to this weakness. These relationships are defined to give an overview of the different insight to similar items that may exist at higher and lower levels of abstraction.

Visit http://cwe.mitre.org/ for more details.