Run static analysis (SAST) on the codebase looking for the unsafe pattern in the data flow.
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, potentially leading to multiple instances or corrupted state.
What is CWE-543?
Real-world CVEs caused by CWE-543
No public CVE references are linked to this CWE in MITRE's catalog yet.
Step-by-step attacker path
- 1
This method is part of a singleton pattern, yet the following singleton() pattern is not thread-safe. It is possible that the method will create two objects instead of only one.
- 2
Consider the following course of events:
- 3
- Thread A enters the method, finds singleton to be null, begins the NumberConverter constructor, and then is swapped out of execution. - Thread B enters the method and finds that singleton remains null. This will happen if A was swapped out during the middle of the constructor, because the object reference is not set to point at the new object on the heap until the object is fully initialized. - Thread B continues and constructs another NumberConverter object and returns it while exiting the method. - Thread A continues, finishes constructing its NumberConverter object, and returns its version.
- 4
At this point, the threads have created and returned two different objects.
Vulnerable Java
This method is part of a singleton pattern, yet the following singleton() pattern is not thread-safe. It is possible that the method will create two objects instead of only one.
private static NumberConverter singleton;
public static NumberConverter get_singleton() {
if (singleton == null) {
singleton = new NumberConverter();
}
return singleton;
} 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-543
- Architecture and Design Use the Thread-Specific Storage Pattern. See References.
- Implementation Do not use member fields to store information in the Servlet. In multithreading environments, storing user data in Servlet member fields introduces a data access race condition.
- Implementation Avoid using the double-checked locking pattern in language versions that cannot guarantee thread safety. This pattern may be used to avoid the overhead of a synchronized call, but in certain versions of Java (for example), this has been shown to be unsafe because it still introduces a race condition (CWE-209).
How to detect CWE-543
Run dynamic application security testing against the live endpoint.
Watch runtime logs for unusual exception traces, malformed input, or authorization bypass attempts.
Code review: flag any new code that handles input from this surface without using the validated framework helpers.
Plexicus auto-detects CWE-543 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-543?
This vulnerability occurs when a singleton pattern is implemented in a multithreaded application without proper synchronization, potentially leading to multiple instances or corrupted state.
How serious is CWE-543?
MITRE has not published a likelihood-of-exploit rating for this weakness. Treat it as medium-impact until your threat model proves otherwise.
What languages or platforms are affected by CWE-543?
MITRE lists the following affected platforms: Java, C++.
How can I prevent CWE-543?
Use the Thread-Specific Storage Pattern. See References. Do not use member fields to store information in the Servlet. In multithreading environments, storing user data in Servlet member fields introduces a data access race condition.
How does Plexicus detect and fix CWE-543?
Plexicus's SAST engine matches the data-flow signature for CWE-543 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-543?
MITRE publishes the canonical definition at https://cwe.mitre.org/data/definitions/543.html. You can also reference OWASP and NIST documentation for adjacent guidance.
Weaknesses related to CWE-543
Missing Synchronization
This vulnerability occurs when multiple parts of your application (like threads or processes) use the same resource—such as a variable,…
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…
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…
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.