11.07.2015 Views

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

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.

374 Part III: Building Secure <strong>Web</strong> <strong>Application</strong>sProtect Sensitive Data in StorageIdentify stored data that requires guaranteed privacy <strong>and</strong> integrity. If you storepasswords in database solely for the purposes of verification, consider using a onewayhash. If the table of passwords is compromised, the hashes cannot be used toobtain the clear text password.If you store sensitive user-supplied data such as credit card numbers, use a strongsymmetric encryption algorithm such as Triple DES (3DES) to encrypt the data.Encrypt the 3DES encryption key using the Win32 Data Protection API (DPAPI), <strong>and</strong>store the encrypted key in a registry key with a restricted ACL that onlyadministrators <strong>and</strong> your application process account can use.Why not DPAPI?While DPAPI is recommended for encrypting connection strings <strong>and</strong> other secretssuch as account credentials that can be manually recovered <strong>and</strong> reconstructed in theevent of machine failure, it is less suited to storing data like credit card numbers. Thisis because of recoverability issues (if the keys are lost, there is no way to recover theencrypted data) <strong>and</strong> <strong>Web</strong> farm issues. Instead, you should use a symmetricencryption algorithm such as 3DES <strong>and</strong> encrypt the encryption key using DPAPI.The main issues that make DPAPI less suited for storing sensitive data in thedatabase are summarized below:● If DPAPI is used with the machine key <strong>and</strong> you passCRYPTPROTECT_LOCAL_MACHINE to the CryptProtectData <strong>and</strong>CryptUnprotectData functions, the machine account generates the encryptionkeys. This means that each server in a <strong>Web</strong> farm has a different key, whichprevents one server from being able to access data encrypted by another server.Also, if the <strong>Web</strong> server machine is destroyed, the key is lost, <strong>and</strong> the encrypteddata cannot be recovered from the database.● If you use the machine key approach, any user on that computer can decrypt thedata (unless you use additional encryption mechanisms).● If you use DPAPI with a user key <strong>and</strong> use local user accounts, each local accounton each <strong>Web</strong> server has a different security identifier (SID) <strong>and</strong> a different key isgenerated, which prevents one server from being able to access data encrypted byanother server.● If you use DPAPI with a user key <strong>and</strong> you use a roaming user profile across themachines in the <strong>Web</strong> farm, all data will share the same encryption/decryption key.However, if the domain controller responsible for the roaming user profile accountis damaged or destroyed, a user account with the same SID cannot be recreated,<strong>and</strong> you cannot recover the encrypted data from the database.Also, with a roaming user profile, if someone manages to retrieve the data, it canbe decrypted on any machine in the network, provided that the attacker can runcode under the specific user account. This increases the area for potential attack,<strong>and</strong> is not recommended.

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

Saved successfully!

Ooh no, something went wrong!