CWE-1275 Variante Incompleto Medium likelihood

Sensitive Cookie with Improper SameSite Attribute

This vulnerability occurs when a sensitive cookie does not have a secure SameSite attribute configured, leaving it exposed to cross-site request forgery (CSRF) attacks.

Definição

What is CWE-1275?

This vulnerability occurs when a sensitive cookie does not have a secure SameSite attribute configured, leaving it exposed to cross-site request forgery (CSRF) attacks.
The SameSite cookie attribute is a critical browser security feature that controls whether a cookie is sent with cross-site requests. It has three possible values: 'Strict' (most secure, never sent cross-site), 'Lax' (sent with safe top-level navigation like links), and 'None' (always sent, requiring the Secure flag). When this attribute is omitted or set insecurely for sensitive cookies—like session or authentication tokens—those credentials can be automatically included in malicious cross-site requests, bypassing the browser's default protections. This creates a direct path for CSRF attacks, where an attacker's site can trigger authenticated actions on the target site without the user's consent. While other defenses like anti-CSRF tokens are important, properly configuring SameSite provides a fundamental, browser-enforced layer of security. For maximum protection, set sensitive cookies to 'Strict' or 'Lax' unless a specific cross-site functionality requires 'None', in which case the Secure flag is mandatory.
Impacto no mundo real

Real-world CVEs caused by CWE-1275

  • Web application for a room automation system has client-side JavaScript that sets a sensitive cookie without the SameSite security attribute, allowing the cookie to be sniffed

Como os atacantes a exploram

Trajeto do atacante passo a passo

  1. 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.

  2. 2

    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:

  3. 3

    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.

  4. 4

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

Exemplo de código vulnerável

Vulnerable JavaScript

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.

Vulnerável JavaScript
let sessionId = generateSessionId()
 let cookieOptions = { domain: 'example.com' }
 response.cookie('sessionid', sessionId, cookieOptions)
Payload do atacante

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:

Payload do atacante HTML
<html>

```
   <form id=evil action="http://local:3002/setEmail" method="POST">
  	 <input type="hidden" name="newEmail" value="abc@example.com" />
   </form>
 <script>evil.submit()</script>
 </html>
Exemplo de código seguro

Secure JavaScript

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

Seguro JavaScript
let sessionId = generateSessionId()
 let cookieOptions = { domain: 'example.com', sameSite: 'Strict' }
 response.cookie('sessionid', sessionId, cookieOptions)
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Lista de verificação de prevenção

How to prevent CWE-1275

  • Implementation Set the SameSite attribute of a sensitive cookie to 'Lax' or 'Strict'. This instructs the browser to apply this cookie only to same-domain requests, which provides a good Defense in Depth against CSRF attacks. When the 'Lax' value is in use, cookies are also sent for top-level cross-domain navigation via HTTP GET, HEAD, OPTIONS, and TRACE methods, but not for other HTTP methods that are more like to cause side-effects of state mutation.
Sinais de deteção

How to detect CWE-1275

Automated Static Analysis High

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Correção automática do Plexicus

O Plexicus deteta automaticamente o CWE-1275 e abre um PR de correção em menos de 60 segundos.

O Codex Remedium analisa cada commit, identifica esta fraqueza exata e entrega um pull request pronto para revisão com o patch. Sem tickets. Sem transferências.

Perguntas frequentes

Frequently asked questions

O que é o CWE-1275?

This vulnerability occurs when a sensitive cookie does not have a secure SameSite attribute configured, leaving it exposed to cross-site request forgery (CSRF) attacks.

Qual a gravidade do CWE-1275?

A MITRE classifica a probabilidade de exploração como Média — a exploração é realista mas normalmente requer condições específicas.

Que linguagens ou plataformas são afetadas pelo CWE-1275?

MITRE lists the following affected platforms: Not OS-Specific, Not Architecture-Specific, Web Based.

Como posso prevenir o CWE-1275?

Set the SameSite attribute of a sensitive cookie to 'Lax' or 'Strict'. This instructs the browser to apply this cookie only to same-domain requests, which provides a good Defense in Depth against CSRF attacks. When the 'Lax' value is in use, cookies are also sent for top-level cross-domain navigation via HTTP GET, HEAD, OPTIONS, and TRACE methods, but not for other HTTP methods that are more like to cause side-effects of state mutation.

Como é que o Plexicus deteta e corrige o CWE-1275?

O motor SAST do Plexicus correlaciona a assinatura de fluxo de dados do CWE-1275 em cada commit. Quando é encontrada uma correspondência, o nosso agente Codex Remedium abre um PR de correção com o código corrigido, testes e um resumo de uma linha para o revisor.

Onde posso saber mais sobre o CWE-1275?

A MITRE publica a definição canónica em https://cwe.mitre.org/data/definitions/1275.html. Pode também consultar a documentação da OWASP e do NIST para orientações adjacentes.

Fraquezas relacionadas

Weaknesses related to CWE-1275

CWE-923 Pai

Improper Restriction of Communication Channel to Intended Endpoints

This vulnerability occurs when a system opens a communication channel for a sensitive task but fails to properly verify that it's actually…

CWE-291 Irmão

Reliance on IP Address for Authentication

This vulnerability occurs when a system uses a client's IP address as the sole or primary method to verify their identity.

CWE-297 Irmão

Improper Validation of Certificate with Host Mismatch

This vulnerability occurs when an application accepts a valid SSL/TLS certificate without properly verifying that it actually belongs to…

CWE-300 Irmão

Channel Accessible by Non-Endpoint

This vulnerability occurs when a system fails to properly verify who is on the other end of a communication link or to secure the channel…

CWE-419 Irmão

Unprotected Primary Channel

This vulnerability occurs when an application exposes a privileged administrative interface or restricted functionality through a primary…

CWE-420 Irmão

Unprotected Alternate Channel

This vulnerability occurs when an application secures its main communication path but leaves a backup or alternative channel with weaker…

CWE-940 Irmão

Improper Verification of Source of a Communication Channel

This vulnerability occurs when an application accepts incoming communication requests without properly checking where they originate from,…

CWE-941 Irmão

Incorrectly Specified Destination in a Communication Channel

This vulnerability occurs when an application establishes an outgoing communication channel but fails to correctly define or enforce the…

CWE-942 Irmão

Permissive Cross-domain Security Policy with Untrusted Domains

This vulnerability occurs when a web application's cross-domain security policy, like a Content Security Policy (CSP), explicitly allows…

Pronto quando você estiver

Pare de pagar por desenvolvedor.
Comece a fechar o ciclo.

O Plexicus é o ASPM nativo de IA que verifica, filtra, corrige, pentesta e explica — de forma autónoma. Programadores ilimitados, repos ilimitados, ações de IA de utilização justa. Nível gratuito real, €269/mo anual quando estiver pronto.