CWE-245 Variante Borrador

J2EE Bad Practices: Direct Management of Connections

This vulnerability occurs when a J2EE application handles database connections directly instead of using the container's built-in connection management system.

Definición

What is CWE-245?

This vulnerability occurs when a J2EE application handles database connections directly instead of using the container's built-in connection management system.
J2EE standards explicitly prohibit applications from managing their own database connections. Instead, developers must use the container's resource management facilities to obtain connections. Every major J2EE container provides robust, pooled connection management as part of its core framework—bypassing this system violates the platform's fundamental architecture. Recreating connection pooling within an application is both complex and prone to critical errors like connection leaks, improper cleanup, and performance bottlenecks. Using the container's proven management layer eliminates these risks while ensuring optimal resource utilization, which is precisely why direct connection management is considered a bad practice and security vulnerability.
Impacto en el mundo real

Real-world CVEs caused by CWE-245

Todavía no hay CVEs públicos enlazados a esta CWE en el catálogo de MITRE.

Cómo lo explotan los atacantes

Ruta del atacante paso a paso

  1. 1

    Identifica una ruta de código que maneje entrada no confiable sin validación.

  2. 2

    Crea un payload que ejercite el comportamiento inseguro — inyección, traversal, overflow o abuso de lógica.

  3. 3

    Envía el payload a través de una solicitud normal y observa la reacción de la aplicación.

  4. 4

    Itera hasta que la respuesta filtre datos, ejecute código del atacante o escale privilegios.

Ejemplo de código vulnerable

Vulnerable Java

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.

Vulnerable Java
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);
  			} catch (SQLException ex) {...}
  		}
  		// Member functions for retrieving database connection and accessing database
  		...
  }
Ejemplo de código seguro

Secure Java

The use of the DriverManager class to directly manage the connection to the database violates the J2EE restriction against the direct management of connections. The J2EE application should use the web application container's resource management facilities to obtain a connection to the database as shown in the following example.

Seguro Java
public class DatabaseConnection {
  		private static final String DB_DATASRC_REF = "jdbc:mysql://localhost:3306/mysqldb";
  		private Connection conn = null;
  		public DatabaseConnection() {
  		}
  		public void openDatabaseConnection() {
  				try {
  						InitialContext ctx = new InitialContext();
  						DataSource datasource = (DataSource) ctx.lookup(DB_DATASRC_REF);
  						conn = datasource.getConnection();
  				} catch (NamingException ex) {...}
  				} catch (SQLException ex) {...}
  		}
  		// Member functions for retrieving database connection and accessing database
  		...
  }
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Lista de prevención

How to prevent CWE-245

  • Architecture Use safe-by-default frameworks and APIs that prevent the unsafe pattern from being expressible.
  • Implementation Validate input at trust boundaries; use allowlists, not denylists.
  • Implementation Apply the principle of least privilege to credentials, file paths, and runtime permissions.
  • Testing Cover this weakness in CI: SAST rules + targeted unit tests for the data flow.
  • Operation Monitor logs for the runtime signals listed in the next section.
Señales de detección

How to detect CWE-245

Automated Static Analysis High

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

Auto-corrección de Plexicus

Plexicus detecta automáticamente CWE-245 y abre un PR de corrección en menos de 60 segundos.

Codex Remedium escanea cada commit, identifica esta debilidad concreta y entrega un pull request listo para revisión con el parche. Sin tickets. Sin traspasos.

Preguntas frecuentes

Frequently asked questions

¿Qué es CWE-245?

This vulnerability occurs when a J2EE application handles database connections directly instead of using the container's built-in connection management system.

¿Qué gravedad tiene CWE-245?

MITRE no ha publicado una calificación de probabilidad de explotación para esta debilidad. Trátala como de impacto medio hasta que tu modelo de amenazas demuestre lo contrario.

¿Qué lenguajes o plataformas se ven afectados por CWE-245?

MITRE lists the following affected platforms: Java.

¿Cómo puedo prevenir CWE-245?

Use safe-by-default frameworks, validate untrusted input at trust boundaries, and apply the principle of least privilege. Cover the data-flow signature in CI with SAST.

¿Cómo detecta y corrige Plexicus CWE-245?

El motor SAST de Plexicus detecta la firma de flujo de datos para CWE-245 en cada commit. Cuando hay coincidencia, nuestro agente Codex Remedium abre un PR de corrección con el código corregido, las pruebas y un resumen de una línea para el revisor.

¿Dónde puedo aprender más sobre CWE-245?

MITRE publica la definición canónica en https://cwe.mitre.org/data/definitions/245.html. También puedes consultar la documentación de OWASP y NIST para guías relacionadas.

Listo cuando tú lo estés

Deja de pagar por desarrollador.
Empieza a cerrar el bucle.

Plexicus es el ASPM nativo de IA que escanea, filtra, corrige, pentestea y explica — de forma autónoma. Desarrolladores ilimitados, repos ilimitados, acciones de IA de uso justo. Nivel gratuito real, €269/mo anual cuando estés listo.