CWE-576 Variante Borrador

EJB Bad Practices: Use of Java I/O

This vulnerability occurs when an Enterprise JavaBeans (EJB) component incorrectly uses Java I/O (java.io) operations to access the file system, violating the EJB specification's design principles.

Definición

What is CWE-576?

This vulnerability occurs when an Enterprise JavaBeans (EJB) component incorrectly uses Java I/O (java.io) operations to access the file system, violating the EJB specification's design principles.
The EJB specification explicitly prohibits the use of java.io package file system access within enterprise beans. This restriction exists because EJB components are designed as portable business logic units that should remain independent of the server's underlying file structure. Using standard file I/O ties your component to a specific server environment, breaking portability and creating inconsistent behavior across different EJB containers. Instead of file system access, EJB components should interact with data through managed resource APIs like JDBC for databases or JMS for messaging. These standardized interfaces ensure proper transaction management, security, and scalability within the container's managed environment. Following this practice maintains the component's portability and leverages the container's built-in services for reliable data handling.
Impacto en el mundo real

Real-world CVEs caused by CWE-576

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

    The following Java example is a simple stateless Enterprise JavaBean that retrieves the interest rate for the number of points for a mortgage. In this example, the interest rates for various points are retrieved from an XML document on the local file system, and the EJB uses the Java I/O API to retrieve the XML document from the local file system.

  2. 2

    This use of the Java I/O API within any kind of Enterprise JavaBean violates the EJB specification by using the java.io package for accessing files within the local filesystem.

  3. 3

    An Enterprise JavaBean should use a resource manager API for storing and accessing data. In the following example, the private member function getInterestRateFromXMLParser uses an XML parser API to retrieve the interest rates.

Ejemplo de código vulnerable

Vulnerable Java

The following Java example is a simple stateless Enterprise JavaBean that retrieves the interest rate for the number of points for a mortgage. In this example, the interest rates for various points are retrieved from an XML document on the local file system, and the EJB uses the Java I/O API to retrieve the XML document from the local file system.

Vulnerable Java
@Stateless
  public class InterestRateBean implements InterestRateRemote {
  		private Document interestRateXMLDocument = null;
  		private File interestRateFile = null;
  		public InterestRateBean() {
  				try {
```
/* get XML document from the local filesystem */* 
  						interestRateFile = new File(Constants.INTEREST_RATE_FILE);
  						
  						if (interestRateFile.exists())
  						{
  						```
  							DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  							DocumentBuilder db = dbf.newDocumentBuilder();
  							interestRateXMLDocument = db.parse(interestRateFile);
  						}
  				} catch (IOException ex) {...}
  		}
  		public BigDecimal getInterestRate(Integer points) {
  			return getInterestRateFromXML(points);
  		}
```
/* member function to retrieve interest rate from XML document on the local file system */* 
  		
  		private BigDecimal getInterestRateFromXML(Integer points) {...}}
Ejemplo de código seguro

Secure Java

An Enterprise JavaBean should use a resource manager API for storing and accessing data. In the following example, the private member function getInterestRateFromXMLParser uses an XML parser API to retrieve the interest rates.

Seguro Java
@Stateless
  public class InterestRateBean implements InterestRateRemote {
  		public InterestRateBean() {
  		}
  		public BigDecimal getInterestRate(Integer points) {
  			return getInterestRateFromXMLParser(points);
  		}
```
/* member function to retrieve interest rate from XML document using an XML parser API */* 
  		
  		private BigDecimal getInterestRateFromXMLParser(Integer points) {...}}
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-576

  • Implementation Do not use Java I/O when writing EJBs.
Señales de detección

How to detect CWE-576

SAST High

Ejecuta análisis estático (SAST) sobre el código buscando el patrón inseguro en el flujo de datos.

DAST Moderate

Ejecuta pruebas dinámicas de seguridad de aplicaciones (DAST) contra el endpoint en vivo.

Runtime Moderate

Vigila los logs en tiempo de ejecución para detectar trazas de excepción inusuales, entradas malformadas o intentos de bypass de autorización.

Code review Moderate

Revisión de código: marca cualquier código nuevo que maneje entrada desde esta superficie sin usar los helpers validados del framework.

Auto-corrección de Plexicus

Plexicus detecta automáticamente CWE-576 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-576?

This vulnerability occurs when an Enterprise JavaBeans (EJB) component incorrectly uses Java I/O (java.io) operations to access the file system, violating the EJB specification's design principles.

¿Qué gravedad tiene CWE-576?

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-576?

MITRE lists the following affected platforms: Java.

¿Cómo puedo prevenir CWE-576?

Do not use Java I/O when writing EJBs.

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

El motor SAST de Plexicus detecta la firma de flujo de datos para CWE-576 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-576?

MITRE publica la definición canónica en https://cwe.mitre.org/data/definitions/576.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.