CWE-784 Variante Brouillon High likelihood

Reliance on Cookies without Validation and Integrity Checking in a Security Decision

This vulnerability occurs when an application makes security decisions—like granting access or verifying identity—based solely on cookie data without first confirming the cookie's authenticity or…

Définition

What is CWE-784?

This vulnerability occurs when an application makes security decisions—like granting access or verifying identity—based solely on cookie data without first confirming the cookie's authenticity or integrity.
Attackers can easily manipulate cookie values directly in the browser or by crafting custom client-side requests. Since the application trusts this data without validation, attackers can forge cookies to impersonate other users, bypass login screens, or escalate their privileges by inserting expected values. To prevent this, developers must never treat cookies as a trusted security mechanism on their own. Always validate and verify cookie integrity on the server using techniques like cryptographic signing, comparing against server-side sessions, or using secure, tamper-proof tokens instead of plain data.
Impact réel

Real-world CVEs caused by CWE-784

  • Attacker can bypass authentication by setting a cookie to a specific value.

  • Attacker can bypass authentication and gain admin privileges by setting an "admin" cookie to 1.

  • Content management system allows admin privileges by setting a "login" cookie to "OK."

  • e-dating application allows admin privileges by setting the admin cookie to 1.

  • Web-based email list manager allows attackers to gain admin privileges by setting a login cookie to "admin."

Comment les attaquants l'exploitent

Parcours de l'attaquant étape par étape

  1. 1

    The following code excerpt reads a value from a browser cookie to determine the role of the user.

  2. 2

    The following code could be for a medical records application. It performs authentication by checking if a cookie has been set.

  3. 3

    The programmer expects that the AuthenticateUser() check will always be applied, and the "authenticated" cookie will only be set when authentication succeeds. The programmer even diligently specifies a 2-hour expiration for the cookie.

  4. 4

    However, the attacker can set the "authenticated" cookie to a non-zero value such as 1. As a result, the $auth variable is 1, and the AuthenticateUser() check is not even performed. The attacker has bypassed the authentication.

  5. 5

    In the following example, an authentication flag is read from a browser cookie, thus allowing for external control of user state data.

Exemple de code vulnérable

Vulnerable Java

The following code excerpt reads a value from a browser cookie to determine the role of the user.

Vulnérable Java
Cookie[] cookies = request.getCookies();
  for (int i =0; i< cookies.length; i++) {
  	Cookie c = cookies[i];
  	if (c.getName().equals("role")) {
  		userRole = c.getValue();
  	}
  }
Exemple de code sécurisé

Secure pseudo

Sécurisé pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
  const safe = validateAndEscape(input);
  return executeWithGuards(safe);
}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Liste de contrôle de prévention

How to prevent CWE-784

  • Architecture and Design Avoid using cookie data for a security-related decision.
  • Implementation Perform thorough input validation (i.e.: server side validation) on the cookie data if you're going to use it for a security related decision.
  • Architecture and Design Add integrity checks to detect tampering.
  • Architecture and Design Protect critical cookies from replay attacks, since cross-site scripting or other attacks may allow attackers to steal a strongly-encrypted cookie that also passes integrity checks. This mitigation applies to cookies that should only be valid during a single transaction or session. By enforcing timeouts, you may limit the scope of an attack. As part of your integrity check, use an unpredictable, server-side value that is not exposed to the client.
Signaux de détection

How to detect CWE-784

SAST High

Exécuter une analyse statique (SAST) sur le code source à la recherche du motif non sécurisé dans le flux de données.

DAST Moderate

Exécuter des tests de sécurité applicative dynamique (DAST) contre le point de terminaison en ligne.

Runtime Moderate

Surveiller les journaux runtime pour détecter des traces d'exception inhabituelles, des entrées malformées ou des tentatives de contournement d'autorisation.

Code review Moderate

Revue de code : signaler tout nouveau code qui traite les entrées de cette surface sans utiliser les helpers du framework validés.

Correction automatique Plexicus

Plexicus détecte automatiquement CWE-784 et ouvre une PR de correction en moins de 60 secondes.

Codex Remedium analyse chaque commit, identifie cette faiblesse précise et livre une pull request prête à être relue avec le correctif. Pas de tickets. Pas de transferts.

Questions fréquentes

Frequently asked questions

Qu'est-ce que CWE-784 ?

This vulnerability occurs when an application makes security decisions—like granting access or verifying identity—based solely on cookie data without first confirming the cookie's authenticity or integrity.

Quelle est la gravité de CWE-784 ?

MITRE évalue la probabilité d'exploitation comme Élevée — cette faiblesse est activement exploitée et doit être priorisée pour la remédiation.

Quels langages ou plateformes sont affectés par CWE-784 ?

MITRE lists the following affected platforms: Web Based.

Comment puis-je prévenir CWE-784 ?

Avoid using cookie data for a security-related decision. Perform thorough input validation (i.e.: server side validation) on the cookie data if you're going to use it for a security related decision.

Comment Plexicus détecte et corrige CWE-784 ?

Le moteur SAST de Plexicus reconnaît la signature de flux de données de CWE-784 à chaque commit. Lorsqu'une correspondance est trouvée, notre agent Codex Remedium ouvre une PR de correction avec le code corrigé, les tests et un résumé d'une ligne pour le relecteur.

Où puis-je en savoir plus sur CWE-784 ?

MITRE publie la définition canonique à https://cwe.mitre.org/data/definitions/784.html. Vous pouvez également consulter la documentation OWASP et NIST pour des conseils adjacents.

Prêt quand vous l'êtes

Arrêtez de payer par développeur.
Commencez à fermer la boucle.

Plexicus est l'ASPM natif IA qui scanne, filtre, corrige, penteste et explique — de façon autonome. Développeurs illimités, dépôts illimités, actions IA à usage équitable. Vrai niveau gratuit, €269/mo annuel quand vous êtes prêt.