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.
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.
What is CWE-412?
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.
Trajeto do atacante passo a passo
- 1
Identificar um caminho de código que trata input não confiável sem validação.
- 2
Criar um payload que explora o comportamento inseguro — injeção, traversal, overflow ou abuso de lógica.
- 3
Entregar o payload através de um pedido normal e observar a reação da aplicação.
- 4
Iterar até que a resposta exponha dados, execute código do atacante ou escale privilégios.
Vulnerable PHP
This code tries to obtain a lock for a file, then writes to it.
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); Secure pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
const safe = validateAndEscape(input);
return executeWithGuards(safe);
} 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.
How to detect CWE-412
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.
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.
Weaknesses related to CWE-412
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…
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…
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…
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.
Improper Resource Locking
This vulnerability occurs when an application fails to properly lock a shared resource, such as a file or memory location, before…
Missing Lock Check
This vulnerability occurs when software fails to verify that a proper synchronization lock is active before accessing or modifying a…
Double-Checked Locking
Double-checked locking is an insufficient synchronization pattern where a program checks a resource's state, acquires a lock, and checks…
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…
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…
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.