CWE-543

Use of Singleton Pattern Without Synchronization in a Multithreaded Context

Medium

Description

The product uses the singleton pattern when creating a resource within a multithreaded environment.

Potential Impact

How to Fix

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).

Detection Methods

Related Weaknesses

References

View on MITRE CWE Database →

Need Help Fixing This Vulnerability?

Our security experts can help you identify and remediate CWE-543 vulnerabilities in your codebase.

Get Security Assessment