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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 4: Design Guidelines for Secure <strong>Web</strong> <strong>Application</strong>s 77Constrain, Reject, <strong>and</strong> Sanitize Your InputThe preferred approach to validating input is to constrain what you allow from thebeginning. It is much easier to validate data for known valid types, patterns, <strong>and</strong>ranges than it is to validate data by looking for known bad characters. When youdesign your application, you know what your application expects. The range of validdata is generally a more finite set than potentially malicious input. However, fordefense in depth you may also want to reject known bad input <strong>and</strong> then sanitize theinput. The recommended strategy is shown in Figure 4.4.Allow knowngood dataReject knownbad dataMakepotentiallymalicious datasafeInputConstrainRejectSanitizeValidate type, format,length <strong>and</strong> range(Use regular expressionsfor string data)For example, strippingNull characters orspacesFigure 4.4Input validation strategy: constrain, reject, <strong>and</strong> sanitize inputTo create an effective input validation strategy, be aware of the following approaches<strong>and</strong> their tradeoffs:● Constrain input.●●●Validate data for type, length, format, <strong>and</strong> range.Reject known bad input.Sanitize input.Constrain InputConstraining input is about allowing good data. This is the preferred approach. Theidea here is to define a filter of acceptable input by using type, length, format, <strong>and</strong>range. Define what is acceptable input for your application fields <strong>and</strong> enforce it.Reject everything else as bad data.Constraining input may involve setting character sets on the server so that you canestablish the canonical form of the input in a localized way.

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

Saved successfully!

Ooh no, something went wrong!