Category:OWASP Security Analysis of Core J2EE Design Patterns Project/EISTier

From OWASP

Jump to: navigation, search

Most if not all JEE applications require access to enterprise or business data from a persistent data store. Data, however, can reside in many different kinds of repositories, from relational databases to mainframe or legacy systems. Mixing application logic with persistence logic introduces tight coupling and creates a maintenance nightmare for an application. The Data Access Object (DAO) pattern allows for the encapsulation of all access to the persistent data store and manages connections to the data tier, while hiding the implementation details of the persistence API from the client. A DataAccessObject implements create, find, update, and delete operations. File:J2EEPatterns-Data Access Object.JPG

Analysis

Avoid

Interpreter Injection

DataAccessObjects (DAOs) interact with interpreters such as SQL-enabled databases or Lightweight Directory Access Protocol (LDAP) enabled repositories. DAOs are therefore susceptible to injection-style attacks such as SQL injection. Avoid SQL attacks by using properly constructed prepared statements or stored procedures. For other interpreters, such as LDAP or XML data stores, use appropriate encoding to escape potentially malicious characters such as LDAP encoding or XML encoding. Remember to use a whitelist approach for encoding rather than a blacklist approach.

You may not find encoding methods for some interpreters, leaving your code highly susceptible to interpreter injection. In these cases use strict whitelist input validation.

Improper Resource Closing

Developers often forget to properly close resources such as database connections. Always close resources in a finally block, check for null pointers before closing on an object, and catch and handle any possible exception that may occur during resource closing within the finally block.

Unencrypted Connection String Storage

In order to communicate with a database or other backend server, most applications use a connection string that includes a user name and password. Developers often store this connection string un-encrypted in server configuration files such as server.xml. Malicious insiders and external attackers who exploit path traversal vulnerabilities may be able to use a plaintext connection string to gain unauthorized access to the database.

Encrypt database and other server credentials during storage. Unfortunately, any method you use to encrypt the connection string has weaknesses. For instance, WebLogic provides an encrypt utility to encrypt any clear text property within a configuration file, but the utility relies on an encryption key stored on the application server. Other methods, such as Jasypt’s password based encryption mechanisms require either manual intervention or remote server communication during startup to implement securely. Nevertheless, storing a password plaintext is the least secure option so always use some form of encryption.

Exposing Implementation-specific Exceptions

A DataAccessObject makes a direct connection to the persistence layer and executes queries against it, returning data to the client. Such access requires correct handling and translation of exceptions that stem from the data tier. Ensure that exceptions that are thrown from implementation-specific packages, such as java.sql.* or javax.sql.* are handled and logged appropriately in the DataAccessObject and are not simply propagated to the client. One popular strategy is to log the exception and throw a custom-made exception to the client, such as a DAOException.


This category currently contains no pages or media.

Personal tools
Language