CWE-245: J2EE Bad Practices: Direct Management of Connections
The J2EE application directly manages connections, instead of using the container's connection management facilities.
How it's found
J2EE Bad Practices: Direct Management of Connections is a specific, narrowly defined instance of a broader pattern. Testers confirm it with targeted code review and a proof-of-concept input that exercises the exact code path this weakness describes.
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.
Vulnerable vs. safe
conn = DriverManager.getConnection(CONNECT_STRING);try {} catch (SQLException ex) {...}private static final String CONNECT_STRING = "jdbc:mysql://localhost:3306/mysqldb";private Connection conn = null;public DatabaseConnection() {}public void openDatabaseConnection() {}// Member functions for retrieving database connection and accessing database...public class DatabaseConnection {}InitialContext ctx = new InitialContext();DataSource datasource = (DataSource) ctx.lookup(DB_DATASRC_REF);conn = datasource.getConnection();
try {} catch (NamingException ex) {...}} catch (SQLException ex) {...}private static final String DB_DATASRC_REF = "jdbc:mysql://localhost:3306/mysqldb";private Connection conn = null;public DatabaseConnection() {}public void openDatabaseConnection() {}// Member functions for retrieving database connection and accessing database...public class DatabaseConnection {}Consequences
- Quality Degradation
Where this fits in a TurboPentest engagement
TurboPentest's agentic pentest is powerful and covers a broad range of issues automatically. This particular class is best confirmed in a manual IntegSec engagement, where human pentesters apply deeper methodology and a larger context window than any automated pass.
Frequently asked questions
What is CWE-245?
The J2EE application directly manages connections, instead of using the container's connection management facilities.
How do you find J2EE Bad Practices: Direct Management of Connections?
J2EE Bad Practices: Direct Management of Connections is a specific, narrowly defined instance of a broader pattern. Testers confirm it with targeted code review and a proof-of-concept input that exercises the exact code path this weakness describes.
What is the impact of CWE-245?
Quality Degradation
Does TurboPentest test for J2EE Bad Practices: Direct Management of Connections?
TurboPentest's agentic pentest is powerful and covers a broad range of issues automatically. This particular class is best confirmed in a manual IntegSec engagement, where human pentesters apply deeper methodology and a larger context window than any automated pass.
Related CWEs
Find these issues before an attacker does
TurboPentest runs an agentic AI pentest against your target and reports findings with proof, from $99 per target.
Start a $99 pentest