28.10.2014 Views

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

368 Chapter 8 • Code-Level <strong>Defense</strong>s<br />

H<strong>and</strong>ling Sensitive Data<br />

A final technique for mitigating the seriousness of <strong>SQL</strong> injection is to consider the storage<br />

<strong>and</strong> access of sensitive information within the database. One of the goals of an attacker is to<br />

gain access to the data that is held within the database—often because that data will have<br />

some form of monetary value. Examples of the types of information an attacker may be<br />

interested in obtaining may include usernames <strong>and</strong> passwords, personal information,<br />

or financial information such as credit card details. Because of this, it is worth considering<br />

additional controls over sensitive information. Some example controls or design decisions to<br />

consider might be the following:<br />

■■<br />

■■<br />

■■<br />

Passwords Where possible, you should not store users’ passwords within the<br />

database. A more secure alternative is to store a salted one-way hash (using a secure<br />

hash algorithm such as SHA256) of each user’s password instead of the password<br />

itself. The salt, which is an additional small piece of r<strong>and</strong>om data, should then<br />

ideally be stored separately from the password hash. In this case, instead of<br />

comparing a user’s password to the one in the database during the login process,<br />

you would compare the salted hash calculated from the details supplied by the<br />

user to the value stored in the database. Note that this will prevent the application<br />

from being able to e-mail the user his password when he forgets it; in this case,<br />

it would be necessary to generate a new, secure password for the user <strong>and</strong> provide<br />

that to him instead.<br />

Credit card <strong>and</strong> other financial information You should store details such as<br />

credit cards encrypted with an approved (i.e., FIPS-certified) encryption algorithm.<br />

This is a requirement of the Payment Card Industry Data Security St<strong>and</strong>ards<br />

(PCI-DSS) for credit card information. However, you should also consider<br />

encrypting other financial information that may be in the application, such as<br />

bank account details.<br />

Archiving Where an application is not required to maintain a full history of all<br />

of the sensitive information that is submitted to it (e.g., personally identifiable<br />

information), you should consider archiving or removing the unneeded information<br />

after a reasonable period of time. Where the application does not require this<br />

information after initial processing, you should archive or remove unneeded<br />

information immediately. In this case, removing information where the exposure<br />

would be a major privacy breach may reduce the impact of any future security<br />

breach by reducing the amount of customer information to which an attacker<br />

can gain access.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!