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.

88 Part II: Designing Secure <strong>Web</strong> <strong>Application</strong>sDo Not Store Secrets if You Can Avoid ItStoring secrets in software in a completely secure fashion is not possible. Anadministrator, who has physical access to the server, can access the data. For example,it is not necessary to store a secret when all you need to do is verify whether a userknows the secret. In this case, you can store a hash value that represents the secret<strong>and</strong> compute the hash using the user-supplied value to verify whether the userknows the secret.Do Not Store Secrets in CodeDo not hard code secrets in code. Even if the source code is not exposed on the <strong>Web</strong>server, it is possible to extract string constants from compiled executable files. Aconfiguration vulnerability may allow an attacker to retrieve the executable.Do Not Store Database Connections, Passwords, or Keys in PlaintextAvoid storing secrets such as database connection strings, passwords, <strong>and</strong> keys inplaintext. Use encryption <strong>and</strong> store encrypted strings.Avoid Storing Secrets in the LSAAvoid the LSA because your application requires administration privileges to accessit. This violates the core security principle of running with least privilege. Also, theLSA can store secrets in only a restricted number of slots. A better approach is to useDPAPI, available on Microsoft Windows® 2000 <strong>and</strong> later operating systems.Use DPAPI for Encrypting SecretsTo store secrets such as database connection strings or service account credentials, useDPAPI. The main advantage to using DPAPI is that the platform system manages theencryption/decryption key <strong>and</strong> it is not an issue for the application. The key is eithertied to a Windows user account or to a specific computer, depending on flags passedto the DPAPI functions.DPAPI is best suited for encrypting information that can be manually recreated whenthe master keys are lost, for example, because a damaged server requires anoperating system re-install. Data that cannot be recovered because you do not knowthe plaintext value, for example, customer credit card details, require an alternateapproach that uses traditional symmetric key-based cryptography such as the use oftriple-DES.For more information about using DPAPI from <strong>Web</strong> applications, see Chapter 10,“Building Secure ASP.NET <strong>Web</strong> Pages <strong>and</strong> Controls.”

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

Saved successfully!

Ooh no, something went wrong!