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.)
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, data structure, or file) without proper synchronization.…
What is CWE-366?
Real-world CVEs caused by CWE-366
-
Chain: two threads in a web browser use the same resource (CWE-366), but one of those threads can destroy the resource before the other has completed (CWE-416).
Step-by-step attacker path
- 1
Identify a code path that handles untrusted input without validation.
- 2
Craft a payload that exercises the unsafe behavior — injection, traversal, overflow, or logic abuse.
- 3
Deliver the payload through a normal request and observe the application's reaction.
- 4
Iterate until the response leaks data, executes attacker code, or escalates privileges.
Vulnerable C
The following example demonstrates the weakness.
int foo = 0;
int storenum(int num) {
static int counter = 0;
counter++;
if (num > foo) foo = num;
return foo;
} 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-366
- Architecture and Design Use locking functionality. This is the recommended solution. Implement some form of locking mechanism around code which alters or reads persistent data in a multithreaded environment.
- Architecture and Design Create resource-locking validation checks. If no inherent locking mechanisms exist, use flags and signals to enforce your own blocking scheme when resources are being used by other threads of execution.
How to detect CWE-366
Plexicus auto-detects CWE-366 and opens a fix PR in under 60 seconds.
Codex Remedium scans every commit, identifies this exact weakness, and ships a reviewer-ready pull request with the patch. No tickets. No hand-offs.
Frequently asked questions
What is CWE-366?
This vulnerability occurs when two or more threads within the same application access and manipulate a shared resource (like a variable, data structure, or file) without proper synchronization. Because the threads can execute in an unpredictable order, they can corrupt the resource's state, leading to crashes, incorrect calculations, or data loss.
How serious is CWE-366?
MITRE rates the likelihood of exploit as Medium — exploitation is realistic but typically requires specific conditions.
What languages or platforms are affected by CWE-366?
MITRE lists the following affected platforms: C, C++, Java, C#.
How can I prevent CWE-366?
Use locking functionality. This is the recommended solution. Implement some form of locking mechanism around code which alters or reads persistent data in a multithreaded environment. Create resource-locking validation checks. If no inherent locking mechanisms exist, use flags and signals to enforce your own blocking scheme when resources are being used by other threads of execution.
How does Plexicus detect and fix CWE-366?
Plexicus's SAST engine matches the data-flow signature for CWE-366 on every commit. When a match is found, our Codex Remedium agent opens a fix PR with the corrected code, tests, and a one-line summary for the reviewer.
Where can I learn more about CWE-366?
MITRE publishes the canonical definition at https://cwe.mitre.org/data/definitions/366.html. You can also reference OWASP and NIST documentation for adjacent guidance.
Weaknesses related to CWE-366
Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')
A race condition occurs when multiple processes or threads access a shared resource simultaneously without proper coordination, creating a…
Race Condition for Write-Once Attributes
This vulnerability occurs when an untrusted software component wins a race condition and writes to a hardware register before the trusted…
Hardware Logic Contains Race Conditions
A hardware race condition occurs when security-critical logic circuits receive signals at slightly different times, creating temporary…
Signal Handler Race Condition
A signal handler race condition occurs when a program's signal handling routine is vulnerable to timing issues, allowing its state to be…
Time-of-check Time-of-use (TOCTOU) Race Condition
This vulnerability occurs when a program verifies a resource's state (like a file's permissions or existence) but then uses it after that…
Context Switching Race Condition
This vulnerability occurs when an application switches between different security contexts (like privilege levels or domains) using a…
Race Condition During Access to Alternate Channel
A race condition occurs when an application opens a secondary communication channel intended for an authorized user, but fails to secure…
Permission Race Condition During Resource Copy
This vulnerability occurs when a system copies a file or resource but delays setting its final permissions until the entire copy operation…
Don't Let Security
Weigh You Down.
Stop choosing between AI velocity and security debt. Plexicus is the only platform that runs Vibe Coding Security and ASPM in parallel — one workflow, every codebase.