CWE-820 Base Incompleto

Missing Synchronization

This vulnerability occurs when multiple parts of your application (like threads or processes) use the same resource—such as a variable, file, or data structure—without proper coordination to control…

Definição

What is CWE-820?

This vulnerability occurs when multiple parts of your application (like threads or processes) use the same resource—such as a variable, file, or data structure—without proper coordination to control who accesses it and when.
When different parts of your code run concurrently and touch a shared resource without synchronization, the resource's state can become unpredictable. One thread might read a value while another is halfway through modifying it, or two processes might overwrite each other's changes, leading to corrupted data, crashes, or incorrect calculations that break your application's logic. This lack of coordination creates a race condition window that attackers can potentially exploit. By carefully timing their interactions, an attacker might manipulate the shared resource into an unexpected state that bypasses security checks, leaks sensitive information, or causes the system to behave in unintended and insecure ways.
Impacto no mundo real

Real-world CVEs caused by CWE-820

Ainda não há referências CVE públicas associadas a este CWE no catálogo da MITRE.

Como os atacantes a exploram

Trajeto do atacante passo a passo

  1. 1

    The following code intends to fork a process, then have both the parent and child processes print a single line.

  2. 2

    One might expect the code to print out something like:

  3. 3

    ``` PARENT child ```

  4. 4

    However, because the parent and child are executing concurrently, and stdout is flushed each time a character is printed, the output might be mixed together, such as:

  5. 5

    ``` PcAhRiElNdT [blank line] [blank line] ```

Exemplo de código vulnerável

Vulnerable C

The following code intends to fork a process, then have both the parent and child processes print a single line.

Vulnerável C
static void print (char * string) {
  		char * word;
  		int counter;
  		for (word = string; counter = *word++; ) {
  				putc(counter, stdout);
  				fflush(stdout);
```
/* Make timing window a little larger... */* 
  				
  				sleep(1);}}
  
  int main(void) {
  ```
  		pid_t pid;
  		pid = fork();
  		if (pid == -1) {
  			exit(-2);
  		}
  		else if (pid == 0) {
  			print("child\n");
  		}
  		else {
  			print("PARENT\n");
  		}
  		exit(0);
  }
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-820

  • Architecture Use safe-by-default frameworks and APIs that prevent the unsafe pattern from being expressible.
  • Implementation Validate input at trust boundaries; use allowlists, not denylists.
  • Implementation Apply the principle of least privilege to credentials, file paths, and runtime permissions.
  • Testing Cover this weakness in CI: SAST rules + targeted unit tests for the data flow.
  • Operation Monitor logs for the runtime signals listed in the next section.
Sinais de deteção

How to detect CWE-820

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

This vulnerability occurs when multiple parts of your application (like threads or processes) use the same resource—such as a variable, file, or data structure—without proper coordination to control who accesses it and when.

Qual a gravidade do CWE-820?

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

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

Use safe-by-default frameworks, validate untrusted input at trust boundaries, and apply the principle of least privilege. Cover the data-flow signature in CI with SAST.

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

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

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

Fraquezas relacionadas

Weaknesses related to CWE-820

CWE-662 Pai

Improper Synchronization

This vulnerability occurs when a multi-threaded or multi-process application allows shared resources to be accessed by multiple threads or…

CWE-1058 Irmão

Invokable Control Element in Multi-Thread Context with non-Final Static Storable or Member Element

This happens when a method or function, designed to run in a multi-threaded environment, accesses or modifies a non-final static variable…

CWE-1096 Irmão

Singleton Class Instance Creation without Proper Locking or Synchronization

This flaw occurs when a Singleton class is implemented without proper thread-safe controls, allowing multiple instances to be created in…

CWE-366 Irmão

Race Condition within a Thread

This vulnerability occurs when two or more threads within the same application access and manipulate a shared resource (like a variable,…

CWE-543 Irmão

Use of Singleton Pattern Without Synchronization in a Multithreaded Context

This vulnerability occurs when a singleton pattern is implemented in a multithreaded application without proper synchronization,…

CWE-567 Irmão

Unsynchronized Access to Shared Data in a Multithreaded Context

This vulnerability occurs when multiple threads in an application can read and modify shared data, like static variables, without proper…

CWE-663 Irmão

Use of a Non-reentrant Function in a Concurrent Context

This vulnerability occurs when a program uses a function that is not safe for reentrancy within a concurrent environment, such as…

CWE-667 Irmão

Improper Locking

This vulnerability occurs when a program fails to correctly acquire or release a lock on a shared resource, such as a file, database…

CWE-764 Irmão

Multiple Locks of a Critical Resource

This vulnerability occurs when a critical resource, such as a file, data structure, or connection, is locked more times than the software…

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.