CWE-639 Base Incompleto High likelihood

Authorization Bypass Through User-Controlled Key

This vulnerability occurs when an application's authorization system fails to verify that a user is allowed to access specific data before retrieving it, allowing an attacker to access another…

Definição

What is CWE-639?

This vulnerability occurs when an application's authorization system fails to verify that a user is allowed to access specific data before retrieving it, allowing an attacker to access another user's information by manipulating an identifier they control.
This flaw typically appears in features that fetch user-specific data, like account pages or search results. The application uses a key—such as a database ID, account number, or session token—to locate the correct record. However, if this key is taken directly from a user-controllable source like a URL parameter, form field, or cookie without verifying the requesting user's permissions, an attacker can simply change the key value to access data belonging to someone else. Attackers often exploit this by tampering with sequential, predictable, or easily-guessed identifiers. For instance, using a simple integer like `user_id=1001` and changing it to `1002` to access another account. The core failure is that the system performs a lookup based on the provided key but skips the critical authorization check to confirm the authenticated user actually owns or has the right to view that specific record.
Impacto no mundo real

Real-world CVEs caused by CWE-639

  • An educational application does not appropriately restrict file IDs to a particular user. The attacker can brute-force guess IDs, indicating IDOR.

Como os atacantes a exploram

Trajeto do atacante passo a passo

  1. 1

    Identificar um caminho de código que trata input não confiável sem validação.

  2. 2

    Criar um payload que explora o comportamento inseguro — injeção, traversal, overflow ou abuso de lógica.

  3. 3

    Entregar o payload através de um pedido normal e observar a reação da aplicação.

  4. 4

    Iterar até que a resposta exponha dados, execute código do atacante ou escale privilégios.

Exemplo de código vulnerável

Vulnerable C#

The following code uses a parameterized statement, which escapes metacharacters and prevents SQL injection vulnerabilities, to construct and execute a SQL query that searches for an invoice matching the specified identifier [1]. The identifier is selected from a list of all invoices associated with the current authenticated user.

Vulnerável C#
...
   conn = new SqlConnection(_ConnectionString);
   conn.Open();
   int16 id = System.Convert.ToInt16(invoiceID.Text);
   SqlCommand query = new SqlCommand( "SELECT * FROM invoices WHERE id = @id", conn);
   query.Parameters.AddWithValue("@id", id);
   SqlDataReader objReader = objCommand.ExecuteReader();
   ...
Exemplo de código seguro

Secure pseudo

Seguro 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.
Lista de verificação de prevenção

How to prevent CWE-639

  • Architecture and Design For each and every data access, ensure that the user has sufficient privilege to access the record that is being requested.
  • Architecture and Design / Implementation Make sure that the key that is used in the lookup of a specific user's record is not controllable externally by the user or that any tampering can be detected.
  • Architecture and Design Use encryption in order to make it more difficult to guess other legitimate values of the key or associate a digital signature with the key so that the server can verify that there has been no tampering.
Sinais de deteção

How to detect CWE-639

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-639 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-639?

This vulnerability occurs when an application's authorization system fails to verify that a user is allowed to access specific data before retrieving it, allowing an attacker to access another user's information by manipulating an identifier they control.

Qual a gravidade do CWE-639?

A MITRE classifica a probabilidade de exploração como Alta — esta fraqueza é ativamente explorada em campo e deve ser priorizada para remediação.

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

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-639?

For each and every data access, ensure that the user has sufficient privilege to access the record that is being requested. Make sure that the key that is used in the lookup of a specific user's record is not controllable externally by the user or that any tampering can be detected.

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

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

A MITRE publica a definição canónica em https://cwe.mitre.org/data/definitions/639.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.