Home > Articles > Security > Network Security

  • Print
  • + Share This
This chapter is from the book

3.3 Database Server

The storage of data and user-specific information by the Web system requires that safeguards be in place to protect this information. Database servers, although typically not directly visible to a client computer, must be secured as if the Web server has been compromised. Securing the site's database is not limited to the database host itself; any Web system components or other data retrieval mechanisms that operate on the data residing in the database must be properly designed and implemented to protect against database content attacks.

As discussed earlier in the chapter, all servers on the site's network must be properly secured from the operating system and commercial software perspectives. Any server can possibly be used to gain an administrative foothold on the network. This, of course, applies to the database server as well. User accounts, file systems, and server software running on the database server must be properly configured to prevent unauthorized access by an intruder. This section assumes that the computer on which the database is running—either standalone or colocated with the Web server—has been properly secured from the perspective of user accounts, file systems, and server software.

This section focuses on the following aspects of securing the site's database:

  • Database overview. Some of the more common ways that databases are implemented for Web systems are described.

  • Security of content stored in the database. Properly securing sensitive data stored in an Internet-accessible database is possibly the most important security concern for a Web system. As suggested throughout this chapter, one must assume that the servers supporting a Web system will be compromised. Depending on the knowledge level of the attacker, this compromise very possibly could include unauthorized access to data in the site's database. Another consideration is the temporary storage of private user data during processing, either before or after it is stored in the database, in plaintext files on a server's file system (Sullivan 2000).

  • Database access from the Web server. Web system components typically provide access to data stored in the Web site's database. With this access mechanism comes additional security concerns over the handling of database schema and connection information (Rahmel 1997).

Database Overview

In general, a database that supports a Web application can have three configurations:

  • A file-based database usually residing on the Web server machine. The Web system components use an API, such as Active Data Objects (ADO), to access the file directly. The file must be secured like any other in the file system, to prevent it from being downloaded, accessed, or manipulated by an intruder. Examples of this kind of database are Microsoft Access on Windows platforms and mySQL on UNIX platforms.

  • A mainstream relational database management system (RDBMS) such as Microsoft SQL Server or Oracle colocated with the Web server, meaning that it is on the same machine.

  • A mainstream RDBMS running on its own server and accessed over a network by the Web server machine. The addition of a second firewall between the Web server machine and the database machine make this the most secure configuration and is the most common one for large Web applications.

One of these general configurations will be selected and implemented for a Web system, based on defined system requirements and the available development budget. Although these three approaches are quite different from a deployment standpoint, they have several similar aspects that must be considered for proper security administration of the database and access to the data it contains.

Many Web systems will be set up to access the database as a single, privileged user, as it is generally easier to configure. It is easier to set up all the Web system components to connect to the database as the same user—with the same ID and password—rather than have several different users and maintain the ID and password in many different scripts.

Additionally, accessing the database as a single user can offer better performance on Microsoft Windows NT/2000 systems, because of connection pooling, which allows the operating system to keep database connections open even though they are not currently in use, by placing them into a "pool" of open, ready-to-use connections. As a result, the next time the program requires a connection, one is instantly provided from the pool, without the normal start-up overhead. This is worthwhile, as creating and opening the connection to the database can be expensive in terms of performance.

Security in this case is enforced at the Web server component level rather than at the database level. For example, a component will first make sure that the user who connected to the Web server has the appropriate level of access to perform a particular operation. After it is determined that the user is authorized to perform the action, the component will then access the database as a highly privileged user. If the component didn't perform this check, lower-level users could execute database operations outside their level of access. A single database user is also a bit more secure from the database perspective, as fewer users are defined in the database itself, which can be a potential source for intrusions.

Database Content

Data Privacy

Maintaining the confidentiality of Web system data must be a top priority, particularly for e-commerce systems. When customers make a purchase from an e-commerce site, they are placing a significant amount of trust in the Web system to safeguard their personal data and to ensure that this personal information will not be further distributed to external parties that could cause them harm, financially or otherwise. To this end, when dealing with sensitive user information, such as names, addresses, telephone numbers, and credit card numbers, the Web system's primary concern should be the privacy of the end user.

However, merchants are usually obligated to retain certain information after a payment transaction has been processed, for a period of time known as the dispute period. Because a customer may dispute a credit card charge for various reasons, including fraud, the merchant must be able to audit the transaction back to the payment information used during the transaction. Keep in mind that this type of payment transaction history is quite different from the storage of personal user data used to increase the user's experience of the Web site. Payment transaction history data is used for internal purposes by the merchant and should not be readily accessible by any means to an end user. In fact, it is recommended that transaction history information be stored in encrypted form in a separate, write-only database.

A Web site can facilitate the secure storage of payment transaction history data by creating a separate database, possibly on a separate server, for this purpose. The following steps demonstrate the configuration of a transaction history database on Microsoft SQL Server.

  1. Create a new database on the desired machine.

  2. Create a database user account that will be used by the components that need to store payment transaction history information, such as PaymentHistoryUser.

  3. Create a table (or tables if necessary) that will store the necessary pieces of information for the transaction history.

  4. Remove all permissions on this table from all database users and roles; in other words, do not allow select, insert, update, delete, or any other operations on this table to any users of the database, including PaymentHistoryUser.

  5. Create a stored procedure to insert the customer and payment information into the transaction history table. This stored procedure will be able to access the table even though the PaymentHistoryUser cannot directly access the table itself.

  6. Grant execute access on the stored procedure to the PaymentHistoryUser account.

  7. In the components that need to store transaction history information, invoke the stored procedure to insert the data into the table.

  8. As an added security measure, encrypt all information, as discussed in the next section, prior to passing it to the stored procedure.

The architecture depicted in Figure 3-7 ensures that the database containing the sensitive payment transaction history data will remain isolated from the rest of the Web site's data and will be less susceptible to attack, owing to the write-only nature of the database.

Figure 3-7 Write-Only Database for Payment Transaction History

Data Encryption

The safest way to avoid problems with unauthorized access to site data is to encrypt the data while it is stored in the database. When it must be accessed for processing, the data is read from the database and then decrypted in memory. Web system components can make use of certain operating system functions to encrypt important data prior to performing insertions or updates to the database.

Encryption of the data ensures that whenever an attacker finds a way to access the system database or, in the case of a file-based database, simply downloads it, the data will be unreadable.

For example, consider a customer service facility that allows customers to view their account information, including full names, addresses, and phone numbers. This sensitive information is encrypted and stored in a database table. When the system invokes a component to view user information, the component reads the encrypted data from the database, decrypts the data in memory, and forwards the data to the client computer over a secured HTTP (SSL) connection. In this way, the data cannot be viewed by hacking into the database—owing to the encryption on the stored data—or intercepted by a third party during transmission—owing to the secured connection.3

Encrypting/decrypting information on the fly can be performed with certain APIs available on most operating systems and through the use of some scripting languages:

  • CryptoAPI, available from Microsoft: a set of Win32-style API calls

  • The crypt function available on most UNIX systems

  • ::Crypt modules for Perl scripts

These APIs require the use of an encryption key, which is used as the basis for encrypting the data. Deciding where to store the key, however, is a somewhat complicated issue. If an intruder manages to get the encryption key, the data in the database will then be compromised. For some Web systems, storing the key in a compiled, binary component is enough, relying on the fact that the key is somewhat hidden since it is not easily viewable. However, the reality is that a knowledgeable intruder will probably be able to extract the key from a binary component, thus rendering this approach useless. Unfortunately, there is no absolute solution to this problem, only somewhat stronger alternatives:

  • Store the key in a file and rely on operating system security to protect the contents of the file, meaning, only give read permission on this file to the user identity that the Web system server components execute under. If the server is properly secured, this file should not be accessible by other users—including intruders—with access to the server's file system.

  • Create a binary component that programmatically creates the encryption key, rather than storing it as a string in source code. This will make it impossible for the encryption key to be discovered by simply dumping the strings from the binary component.

Temporary and Log Files

Encrypting the data stored in the database is a critical step in securing private user data. However, Web system components accessing this data may inadvertently place the unencrypted form of this data into a temporary file or a log file on the Web server's disk. This can happen either before the data is encrypted and stored in the database or after the data is retrieved from the database and decrypted. The latter case may not occur until long after the user has departed, such as in after-hours batch processing or reports. Because the temporary and log files are often stored in obscure directories, they can remain unnoticed from a security perspective. If the directories containing temporary and log files are not tightly controlled and maintained, an unauthorized user may gain access to them. Log file entries should not include sensitive data. Because some third-party applications may also log data, it is important to inspect all third-party software logging functionality to ensure that sensitive data is not logged.

In most cases, it is better to avoid the use of temporary files in a Web system. From a security perspective, it is not sufficient to assume that Web system components will remove temporary files after they are finished using them. A Web system component may crash, either inadvertently or maliciously when manipulated by an attacker, leaving the temporary file "orphaned" on the server's file system. Another possibility is that the temporary file may be accessed by an attacker at the same time that it is being used by the Web system component: a race condition. Because of these problems, avoid the use of temporary files from Web system components. When the use of a temporary file cannot be avoided, make sure that sensitive data placed in a temporary file is encrypted. If the encryption of the data in the temporary file is not possible, consider an alternative approach to processing the data that does not involve the use of temporary files.

Access to Database Objects

As described earlier, many Web systems make use of a single log-on technique for accessing data stored in the database. The reasons for using a single log-on technique are ease of administration—no need to add accounts for each user—better performance—connections can be reused—and simplicity—less work to determine which credentials to use. Web systems that use a single log-on technique typically enforce access control at the "boundaries" of the system, meaning that the Web system components verify that the user has permission to access the specified content.

Although the system's components are performing access checks prior to accessing the database, it should not be assumed that the data in the database can be left wide open, accessible to any database user. Access to tables, views, and other database objects should be granted only to the privileged Web access account(s) and should not be viewable to other database users, when they exist.

Database Access

Web system components access the database through an API such as ODBC (Open Database Connectivity), JDBC (Java Database Connectivity), or ADO. In order to interact with the database through such APIs, the back-end components must be able to connect to the database as users and to construct queries against tables and other objects in the database. Two security concerns arise from this situation.

Database User ID and Password

Web system components need to be able to connect to the database and typically have a predetermined user ID and password hard coded in their source code or possibly even in a configuration file. This is largely because of the widespread use of the single database user approach, as outlined earlier. It is important to secure the user ID and password information so that it cannot be retrieved by an intruder and then used to access the database.

Note that the discussion presented applies only to architectures that store a text user ID and password for connecting to the database from the Web system components. Some architectures, such as one that makes use of Microsoft's IIS and SQL Server, can use an integrated security technique, whereby the database connection information is not stored in the component but instead is taken from the identity of the Web server process or the user connecting to the Web server.

In nonintegrated security Web architectures, the user ID and password data can be stored for later use in several ways. The login data may be placed directly into the script or component source code and used when needed.

Alternatively, components may store the password outside of the executable files or scripts, within a configuration file or within the registry on Windows NT/2000 machines. Because components need the database user ID and password in order to establish connection with the database, the storage of this information for ready access by a component is a necessity. Care must be taken, however, to store the data for back-end components and, through encryption, still make it difficult for an intruder to access the login data, if an intruder is able to gain access to the system.

One approach is to store the user ID and password outside the component source code through the use of a configuration file, and rely on operating system security on the file to keep the information safe. If the configuration file is compromised, however, the user ID and password information are easily viewable.

Another approach is to store the user ID and a password in component source code, in a configuration file, in the registry, in an encrypted form. For a further discussion on encryption techniques, refer to the "Data Encryption" section earlier in this chapter.

Database Schema Information

In order to access data from the system database, Web system components will need to possess knowledge of the database schema: database, table and column names, data types, and so on. Schema information is used to build queries against the database, such as retrieving and updating records.

At times, it may seem beneficial for the Web system to store database schema information or even entire queries within hidden form fields on a Web page or in cookies, which are sent back to the server automatically when the user submits a form or accesses a different Web page. This practice, however, may expose the system's database to intrusion, allowing an attacker to learn the structure of the database and possibly to modify the database query to be able to operate against a different part of the database. Therefore, all database schema–related information must remain private to Web system components and should not be sent to the client browser.

A related issue is the storage of schema information or queries within HTML comments. Sometimes, this type of storage is used to support debugging and tracing, but doing so in a production environment needlessly exposes the system's database schema to unauthorized users.

  • + Share This
  • 🔖 Save To Your Account