CWE-245 Variant Draft

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.

Definition

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.
Auswirkungen in der Praxis

Real-world CVEs caused by CWE-245

Bisher sind in MITREs Katalog keine öffentlichen CVE-Referenzen mit dieser CWE verknüpft.

Wie Angreifer es ausnutzen

Angreiferpfad Schritt für Schritt

  1. 1

    Identifiziere einen Codepfad, der nicht vertrauenswürdige Eingaben ohne Validierung verarbeitet.

  2. 2

    Erzeuge eine Payload, die das unsichere Verhalten auslöst — Injection, Traversal, Overflow oder Logik-Missbrauch.

  3. 3

    Liefere die Payload über einen normalen Request aus und beobachte die Reaktion der Anwendung.

  4. 4

    Iteriere, bis die Antwort Daten preisgibt, Angreifer-Code ausführt oder Berechtigungen eskaliert.

Verwundbares Codebeispiel

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.

Verwundbar 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
  		...
  }
Sicheres Codebeispiel

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.

Sicher 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.
Präventions-Checkliste

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

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

Plexicus Auto-Fix

Plexicus erkennt CWE-245 automatisch und öffnet in unter 60 Sekunden einen Fix-PR.

Codex Remedium scannt jeden Commit, identifiziert genau diese Schwachstelle und liefert einen reviewer-ready Pull Request mit dem Patch. Keine Tickets. Keine Hand-offs.

Häufig gestellte Fragen

Frequently asked questions

Was ist CWE-245?

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

Wie gravierend ist CWE-245?

MITRE hat für diese Schwachstelle keine Exploit-Wahrscheinlichkeit veröffentlicht. Behandle sie als mittlere Auswirkung, bis dein Threat Model anderes belegt.

Welche Sprachen oder Plattformen sind von CWE-245 betroffen?

MITRE lists the following affected platforms: Java.

Wie kann ich CWE-245 verhindern?

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.

Wie erkennt und behebt Plexicus CWE-245?

Die SAST-Engine von Plexicus erkennt die Datenfluss-Signatur von CWE-245 bei jedem Commit. Bei einem Treffer öffnet unser Codex-Remedium-Agent einen Fix-PR mit korrigiertem Code, Tests und einer einzeiligen Zusammenfassung für den Reviewer.

Wo erfahre ich mehr über CWE-245?

MITRE veröffentlicht die kanonische Definition unter https://cwe.mitre.org/data/definitions/245.html. Für ergänzende Hinweise kannst du auch die OWASP- und NIST-Dokumentation heranziehen.

Bereit, wenn du es bist

Schluss mit dem Bezahlen pro Entwickler.
Schließ den Kreislauf.

Plexicus ist die KI-native ASPM, die scannt, filtert, fixt, pentestet und erklärt — autonom. Unbegrenzte Entwickler, unbegrenzte Repos, Fair-Use-KI-Aktionen. Echter kostenloser Tarif, €269/mo jährlich, wenn du bereit bist.