CWE-561 Base Rascunho

Dead Code

Dead code refers to sections of a program that can never run during normal execution, effectively making them inactive and unreachable.

Definição

What is CWE-561?

Dead code refers to sections of a program that can never run during normal execution, effectively making them inactive and unreachable.
Dead code occurs when logic within the program, such as conditional statements or function calls, permanently prevents its execution. This often results from overly restrictive conditions, code that's been commented out but left in place, or legacy functions that are no longer invoked after software updates. While not directly exploitable like a vulnerability, it bloats the codebase, obscures real issues during security reviews, and can mislead developers about the program's actual behavior. From a security and maintenance perspective, dead code creates unnecessary noise during static analysis and manual audits, potentially causing real vulnerabilities to be overlooked. It also increases the attack surface by adding complexity without providing value. Regularly removing dead code through refactoring and using code coverage tools helps keep the application lean, understandable, and easier to secure.
Impacto no mundo real

Real-world CVEs caused by CWE-561

  • chain: incorrect "goto" in Apple SSL product bypasses certificate validation, allowing Adversary-in-the-Middle (AITM) attack (Apple "goto fail" bug). CWE-705 (Incorrect Control Flow Scoping) -> CWE-561 (Dead Code) -> CWE-295 (Improper Certificate Validation) -> CWE-393 (Return of Wrong Status Code) -> CWE-300 (Channel Accessible by Non-Endpoint).

Como os atacantes a exploram

Trajeto do atacante passo a passo

  1. 1

    The condition for the second if statement is impossible to satisfy. It requires that the variables be non-null. However, on the only path where s can be assigned a non-null value, there is a return statement.

  2. 2

    In the following class, two private methods call each other, but since neither one is ever invoked from anywhere else, they are both dead code.

  3. 3

    (In this case it is a good thing that the methods are dead: invoking either one would cause an infinite loop.)

  4. 4

    The field named glue is not used in the following class. The author of the class has accidentally put quotes around the field name, transforming it into a string constant.

Exemplo de código vulnerável

Vulnerable C++

The condition for the second if statement is impossible to satisfy. It requires that the variables be non-null. However, on the only path where s can be assigned a non-null value, there is a return statement.

Vulnerável C++
String s = null;
  if (b) {
  	s = "Yes";
  	return;
  }
  if (s != null) {
  	Dead();
  }
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-561

  • Implementation Remove dead code before deploying the application.
  • Testing Use a static analysis tool to spot dead code.
Sinais de deteção

How to detect CWE-561

Architecture or Design Review High

According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Inspection (IEEE 1028 standard) (can apply to requirements, design, source code, etc.) Formal Methods / Correct-By-Construction ``` Cost effective for partial coverage: ``` Attack Modeling

Automated Static Analysis - Binary or Bytecode High

According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Binary / Bytecode Quality Analysis Compare binary / bytecode to application permission manifest

Dynamic Analysis with Manual Results Interpretation SOAR Partial

According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Automated Monitored Execution

Automated Static Analysis SOAR Partial

According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Permission Manifest Analysis

Automated Static Analysis - Source Code High

According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Source Code Quality Analyzer ``` Cost effective for partial coverage: ``` Warning Flags Source code Weakness Analyzer Context-configured Source Code Weakness Analyzer

Dynamic Analysis with Automated Results Interpretation SOAR Partial

According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Web Application Scanner Web Services Scanner Database Scanners

Correção automática do Plexicus

O Plexicus deteta automaticamente o CWE-561 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-561?

Dead code refers to sections of a program that can never run during normal execution, effectively making them inactive and unreachable.

Qual a gravidade do CWE-561?

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

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

Remove dead code before deploying the application. Use a static analysis tool to spot dead code.

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

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

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