593
The J2EE application directly manages connections, instead of using the container's connection
management facilities.
Extended Description
The J2EE standard forbids the direct management of connections. It requires that applications
use the container's resource management facilities to obtain connections to resources. Every
major web application container provides pooled database connection management as part of its
resource management framework. Duplicating this functionality in an application is difficult and
error prone, which is part of the reason it is forbidden under the J2EE standard.
Relationships
The table(s) below shows the weaknesses and high level categories that are related to this
weakness. These relationships are defined as ChildOf, ParentOf, MemberOr and give insight to
similar items that may exist at higher and lower levels of abstraction. In addition, relationships such
as PeerOf and CanAlsoBe are defined to show similar weaknesses that may want to be explored.
Relevant to the view "Research Concepts" (CWE-1000)
Nature Type ID Name Page
ChildOf 695 Use of Low-Level Functionality 1524
Weakness Ordinalities
Primary :
Applicable Platforms
Language : Java (Prevalence = Undetermined)
Common Consequences
Scope Impact Likelihood
Other Quality Degradation
Detection Methods
Automated Static Analysis
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.)
Effectiveness = High
Demonstrative Examples
Example 1:
In the following example, the class DatabaseConnection opens and manages a connection to a
database for a J2EE application. The method openDatabaseConnection opens a connection to the
database using a DriverManager to create the Connection object conn to the database specified in
the string constant CONNECT_STRING.
Example Language: Java (Bad)
public class DatabaseConnection {
private static final String CONNECT_STRING = "jdbc:mysql://localhost:3306/mysqldb";
private Connection conn = null;
public DatabaseConnection() {
}
public void openDatabaseConnection() {
try {
conn = DriverManager.getConnection(CONNECT_STRING);
CWE Version 4.14
CWE-246: J2EE Bad Practices: Direct Use of Sockets
CWE-246: J2EE Bad Practices: Direct Use of Sockets