CWE-180 Variante Rascunho

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.

Definição

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

Como os atacantes a exploram

Trajeto do atacante passo a passo

  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.

Exemplo de código vulnerável

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/".

Vulnerável Java
String path = getInputPath();
  if (path.startsWith("/safe_dir/"))
  {
  	File f = new File(path);
  	return f.getCanonicalPath();
  }
Exemplo 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 verificação de prevenção

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.
Sinais de deteção

How to detect CWE-180

SAST High

Executar análise estática (SAST) na base de código à procura do padrão inseguro no fluxo de dados.

DAST Moderate

Executar testes dinâmicos de segurança de aplicações (DAST) contra o endpoint em execução.

Runtime Moderate

Monitorizar os registos em tempo de execução para traços de exceção invulgares, input malformado ou tentativas de contornar a autorização.

Code review Moderate

Revisão de código: sinalizar qualquer novo código que trate input desta superfície sem usar os ajudantes validados do framework.

Correção automática do Plexicus

O Plexicus deteta automaticamente o CWE-180 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-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.

Qual a gravidade do CWE-180?

A MITRE não publicou uma classificação de probabilidade de exploração para esta fraqueza. Trate-a como impacto médio até o seu modelo de ameaças provar o contrário.

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

A MITRE não especificou as plataformas afetadas por este CWE — pode aplicar-se à maioria das stacks de aplicações.

Como posso prevenir o 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.

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

O motor SAST do Plexicus correlaciona a assinatura de fluxo de dados do CWE-180 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-180?

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

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.