结构: Simple
Abstraction: Base
状态: Draft
被利用可能性: unkown
The product does not properly synchronize shared data, such as static variables across threads, which can lead to undefined behavior and unpredictable data changes.
Within servlets, shared static variables are not protected from concurrent access, but servlets are multithreaded. This is a typical programming mistake in J2EE applications, since the multithreading is handled by the framework. When a shared variable can be influenced by an attacker, one thread could wind up modifying the variable to contain data that is not valid for a different thread that is also using the data within the variable.
Note that this weakness is not unique to servlets.
cwe_Nature: ChildOf cwe_CWE_ID: 820 cwe_View_ID: 1000 cwe_Ordinal: Primary
cwe_Nature: CanPrecede cwe_CWE_ID: 488 cwe_View_ID: 1000
Language: {'cwe_Name': 'Java', 'cwe_Prevalence': 'Undetermined'}
范围 | 影响 | 注释 |
---|---|---|
['Confidentiality', 'Integrity', 'Availability'] | ['Read Application Data', 'Modify Application Data', 'DoS: Instability', 'DoS: Crash, Exit, or Restart'] | If the shared variable contains sensitive data, it may be manipulated or displayed in another user session. If this data is used to control the application, its value can be manipulated to cause the application to crash or perform poorly. |
策略:
Remove the use of static variables used between servlets. If this cannot be avoided, use synchronized access for these variables.
The following code implements a basic counter for how many times the page has been accesed.
bad Java
Consider when two separate threads, Thread A and Thread B, concurrently handle two different requests:
None
At this point, both Thread A and Thread B print that one hit has been seen, even though two separate requests have been processed. The value of count should be 2, not 1.
While this example does not have any real serious implications, if the shared variable in question is used for resource tracking, then resource consumption could occur. Other scenarios exist.
映射的分类名 | ImNode ID | Fit | Mapped Node Name |
---|---|---|---|
The CERT Oracle Secure Coding Standard for Java (2011) | VNA00-J | Ensure visibility when accessing shared primitive variables | |
The CERT Oracle Secure Coding Standard for Java (2011) | VNA02-J | Ensure that compound operations on shared variables are atomic | |
Software Fault Patterns | SFP19 | Missing Lock |