CWE-412 Base Incompleto

Unrestricted Externally Accessible Lock

This vulnerability occurs when a system correctly checks for a lock's existence, but an unauthorized external actor can control or influence that lock.

Definição

What is CWE-412?

This vulnerability occurs when a system correctly checks for a lock's existence, but an unauthorized external actor can control or influence that lock.
When an attacker can manipulate a lock—such as a mutex, file lock, or a shared resource used as a lock—they can prevent the application from accessing critical resources or performing essential operations. This effectively creates a denial-of-service condition, as the system remains blocked waiting for a lock it cannot acquire. The severity of this issue escalates if the attacker can hold the lock indefinitely, leading to a permanent disruption of service. Developers must ensure that lock mechanisms are secured within the application's trusted boundary and cannot be created, modified, or sustained by untrusted external sources.
Impacto no mundo real

Real-world CVEs caused by CWE-412

  • Program can not execute when attacker obtains a mutex.

  • Program can not execute when attacker obtains a lock on a critical output file.

  • Program can not execute when attacker obtains a lock on a critical output file.

  • Critical file can be opened with exclusive read access by user, preventing application of security policy. Possibly related to improper permissions, large-window race condition.

  • Chain: predictable file names used for locking, allowing attacker to create the lock beforehand. Resultant from permissions and randomness.

  • Chain: Lock files with predictable names. Resultant from randomness.

  • Product does not check if it can write to a log file, allowing attackers to avoid logging by accessing the file using an exclusive lock. Overlaps unchecked error condition. This is not quite CWE-412, but close.

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 PHP

This code tries to obtain a lock for a file, then writes to it.

Vulnerável PHP
function writeToLog($message){
  	$logfile = fopen("logFile.log", "a");
```
//attempt to get logfile lock* 
  	if (flock($logfile, LOCK_EX)) {
  	```
  		fwrite($logfile,$message);
```
// unlock logfile* 
  		flock($logfile, LOCK_UN);}
  	else {
  	```
  		print "Could not obtain lock on logFile.log, message not recorded\n";
  	}
  }
  fclose($logFile);
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-412

  • Architecture and Design / Implementation Use any access control that is offered by the functionality that is offering the lock.
  • Architecture and Design / Implementation Use unpredictable names or identifiers for the locks. This might not always be possible or feasible.
  • Architecture and Design Consider modifying your code to use non-blocking synchronization methods.
Sinais de deteção

How to detect CWE-412

White Box

Automated code analysis techniques might not be able to reliably detect this weakness, since the application's behavior and general security model dictate which resource locks are critical. Interpretation of the weakness might require knowledge of the environment, e.g. if the existence of a file is used as a lock, but the file is created in a world-writable directory.

Correção automática do Plexicus

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

This vulnerability occurs when a system correctly checks for a lock's existence, but an unauthorized external actor can control or influence that lock.

Qual a gravidade do CWE-412?

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

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

Use any access control that is offered by the functionality that is offering the lock. Use unpredictable names or identifiers for the locks. This might not always be possible or feasible.

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

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

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

Fraquezas relacionadas

Weaknesses related to CWE-412

CWE-667 Pai

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-1232 Irmão

Improper Lock Behavior After Power State Transition

This vulnerability occurs when a hardware lock bit, designed to protect critical system configuration registers, is improperly reset or…

CWE-1233 Irmão

Security-Sensitive Hardware Controls with Missing Lock Bit Protection

This vulnerability occurs when a hardware device uses a lock bit to protect critical configuration registers, but the lock fails to…

CWE-1234 Irmão

Hardware Internal or Debug Modes Allow Override of Locks

Hardware debug modes or internal states can bypass critical system lock protections, allowing unauthorized changes to device configuration.

CWE-413 Irmão

Improper Resource Locking

This vulnerability occurs when an application fails to properly lock a shared resource, such as a file or memory location, before…

CWE-414 Irmão

Missing Lock Check

This vulnerability occurs when software fails to verify that a proper synchronization lock is active before accessing or modifying a…

CWE-609 Irmão

Double-Checked Locking

Double-checked locking is an insufficient synchronization pattern where a program checks a resource's state, acquires a lock, and checks…

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…

CWE-765 Irmão

Multiple Unlocks of a Critical Resource

This vulnerability occurs when a critical resource, like a lock or semaphore, is unlocked more times than it was locked, putting the…

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.