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.

Chapter 4: Design Guidelines for Secure <strong>Web</strong> <strong>Application</strong>s 79In PracticeThe following are examples applied to common input fields, using the precedingapproaches:● Last Name field. This is a good example where constraining input is appropriateIn this case, you might allow string data in the range ASCII A–Z <strong>and</strong> a–z, <strong>and</strong> alsohyphens <strong>and</strong> curly apostrophes (curly apostrophes have no significance to SQL) toh<strong>and</strong>le names such as O’Dell. You would also limit the length to your longestexpected value.● Quantity field. This is another case where constraining input works well. In thisexample, you might use a simple type <strong>and</strong> range restriction. For example, theinput data may need to be a positive integer between 0 <strong>and</strong> 1000.●●Free-text field. Examples include comment fields on discussion boards. In thiscase, you might allow letters <strong>and</strong> spaces, <strong>and</strong> also common characters such asapostrophes, commas, <strong>and</strong> hyphens. The set that is allowed does not include lessthan <strong>and</strong> greater than signs, brackets, <strong>and</strong> braces.Some applications might allow users to mark up their text using a finite set ofscript characters, such as bold ““, italic ““, or even include a link to theirfavorite URL. In the case of a URL, your validation should encode the value sothat it is treated as a URL.For more information about validating free text fields, see “Input Validation” inChapter 10, “Building Secure ASP.NET Pages <strong>and</strong> Controls.”An existing <strong>Web</strong> application that does not validate user input. In an idealscenario, the application checks for acceptable input for each field or entry point.However, if you have an existing <strong>Web</strong> application that does not validate userinput, you need a stopgap approach to mitigate risk until you can improve yourapplication’s input validation strategy. While neither of the following approachesensures safe h<strong>and</strong>ling of input, because that is dependent on where the inputcomes from <strong>and</strong> how it is used in your application, they are in practice today asquick fixes for short-term security improvement:●●HTML-encoding <strong>and</strong> URL-encoding user input when writing back to theclient. In this case, the assumption is that no input is treated as HTML <strong>and</strong> alloutput is written back in a protected form. This is sanitization in action.Rejecting malicious script characters. This is a case of rejecting known badinput. In this case, a configurable set of malicious characters is used to reject theinput. As described earlier, the problem with this approach is that bad data is amatter of context.For more information <strong>and</strong> examples of input coding, using regular expressions, <strong>and</strong>ASP.NET validation controls, see “Input Validation” in Chapter 10, “Building SecureASP.NET Pages <strong>and</strong> Controls.”

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

Saved successfully!

Ooh no, something went wrong!