CWE-180 Variante Borrador

Incorrect Behavior Order: Validate Before Canonicalize

This vulnerability occurs when a system checks user input for malicious content before standardizing its format, allowing specially crafted data to bypass security checks.

Definición

What is CWE-180?

This vulnerability occurs when a system checks user input for malicious content before standardizing its format, allowing specially crafted data to bypass security checks.
When validation runs before canonicalization (the process of converting data into a standard, consistent form), attackers can exploit the gap between these two steps. They can submit input that appears safe during the initial check but transforms into a dangerous payload after it's standardized. For example, an attacker might use alternate character encodings, multiple slashes, or dot sequences that resolve to a forbidden path after canonicalization. This flaw effectively neutralizes security defenses like allow-lists or injection filters, creating a false sense of security. To prevent this, always canonicalize input first—convert it to its simplest, canonical form—and then perform validation and sanitization on that standardized data. This ensures your security logic evaluates the actual data the application will use.
Impacto en el mundo real

Real-world CVEs caused by CWE-180

  • Product allows remote attackers to view restricted files via an HTTP request containing a "*" (wildcard or asterisk) character.

  • Product modifies the first two letters of a filename extension after performing a security check, which allows remote attackers to bypass authentication via a filename with a .ats extension instead of a .hts extension.

  • Database consumes an extra character when processing a character that cannot be converted, which could remove an escape character from the query and make the application subject to SQL injection attacks.

  • Overlaps "fakechild/../realchild"

  • Product checks URI for "<" and other literal characters, but does it before hex decoding the URI, so "%3E" and other sequences are allowed.

Cómo lo explotan los atacantes

Ruta del atacante paso a paso

  1. 1

    The following code attempts to validate a given input path by checking it against an allowlist and then return the canonical path. In this specific case, the path is considered valid if it starts with the string "/safe_dir/".

  2. 2

    The problem with the above code is that the validation step occurs before canonicalization occurs. An attacker could provide an input path of "/safe_dir/../" that would pass the validation step. However, the canonicalization process sees the double dot as a traversal to the parent directory and hence when canonicized the path would become just "/".

  3. 3

    To avoid this problem, validation should occur after canonicalization takes place. In this case canonicalization occurs during the initialization of the File object. The code below fixes the issue.

Ejemplo de código vulnerable

Vulnerable Java

The following code attempts to validate a given input path by checking it against an allowlist and then return the canonical path. In this specific case, the path is considered valid if it starts with the string "/safe_dir/".

Vulnerable Java
String path = getInputPath();
  if (path.startsWith("/safe_dir/"))
  {
  	File f = new File(path);
  	return f.getCanonicalPath();
  }
Ejemplo de código seguro

Secure Java

To avoid this problem, validation should occur after canonicalization takes place. In this case canonicalization occurs during the initialization of the File object. The code below fixes the issue.

Seguro Java
String path = getInputPath();
  File f = new File(path);
  if (f.getCanonicalPath().startsWith("/safe_dir/"))
  {
  	return f.getCanonicalPath();
  }
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Lista de prevención

How to prevent CWE-180

  • Implementation Inputs should be decoded and canonicalized to the application's current internal representation before being validated (CWE-180). Make sure that the application does not decode the same input twice (CWE-174). Such errors could be used to bypass allowlist validation schemes by introducing dangerous inputs after they have been checked.
Señales de detección

How to detect CWE-180

SAST High

Ejecuta análisis estático (SAST) sobre el código buscando el patrón inseguro en el flujo de datos.

DAST Moderate

Ejecuta pruebas dinámicas de seguridad de aplicaciones (DAST) contra el endpoint en vivo.

Runtime Moderate

Vigila los logs en tiempo de ejecución para detectar trazas de excepción inusuales, entradas malformadas o intentos de bypass de autorización.

Code review Moderate

Revisión de código: marca cualquier código nuevo que maneje entrada desde esta superficie sin usar los helpers validados del framework.

Auto-corrección de Plexicus

Plexicus detecta automáticamente CWE-180 y abre un PR de corrección en menos de 60 segundos.

Codex Remedium escanea cada commit, identifica esta debilidad concreta y entrega un pull request listo para revisión con el parche. Sin tickets. Sin traspasos.

Preguntas frecuentes

Frequently asked questions

¿Qué es CWE-180?

This vulnerability occurs when a system checks user input for malicious content before standardizing its format, allowing specially crafted data to bypass security checks.

¿Qué gravedad tiene CWE-180?

MITRE no ha publicado una calificación de probabilidad de explotación para esta debilidad. Trátala como de impacto medio hasta que tu modelo de amenazas demuestre lo contrario.

¿Qué lenguajes o plataformas se ven afectados por CWE-180?

MITRE no ha especificado plataformas afectadas para esta CWE — puede aplicar a la mayoría de los stacks de aplicaciones.

¿Cómo puedo prevenir CWE-180?

Inputs should be decoded and canonicalized to the application's current internal representation before being validated (CWE-180). Make sure that the application does not decode the same input twice (CWE-174). Such errors could be used to bypass allowlist validation schemes by introducing dangerous inputs after they have been checked.

¿Cómo detecta y corrige Plexicus CWE-180?

El motor SAST de Plexicus detecta la firma de flujo de datos para CWE-180 en cada commit. Cuando hay coincidencia, nuestro agente Codex Remedium abre un PR de corrección con el código corregido, las pruebas y un resumen de una línea para el revisor.

¿Dónde puedo aprender más sobre CWE-180?

MITRE publica la definición canónica en https://cwe.mitre.org/data/definitions/180.html. También puedes consultar la documentación de OWASP y NIST para guías relacionadas.

Listo cuando tú lo estés

Deja de pagar por desarrollador.
Empieza a cerrar el bucle.

Plexicus es el ASPM nativo de IA que escanea, filtra, corrige, pentestea y explica — de forma autónoma. Desarrolladores ilimitados, repos ilimitados, acciones de IA de uso justo. Nivel gratuito real, €269/mo anual cuando estés listo.