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
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
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?
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
Related CWEs
Written and reviewed by
Michel Chamberland - Founder & CEO, IntegSec
CISSP, OSCP, OSCE, CEH, GIAC, CCSK · 20+ years in offensive security
Michel has spent 20+ years on offensive security teams including IBM X-Force Red and Trustwave SpiderLabs, leading penetration tests, red team engagements, and breach response for Fortune 500 customers. He is the founder of IntegSec and the architect of TurboPentest.
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 pentest