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.

376 Part III: Building Secure <strong>Web</strong> <strong>Application</strong>sInput ValidationAside from the business need to ensure that your databases maintain valid <strong>and</strong>consistent data, you must validate data prior to submitting it to the database toprevent SQL injection. If your data access code receives its input from othercomponents inside the current trust boundary <strong>and</strong> you know the data has alreadybeen validated (for example, by an ASP.NET <strong>Web</strong> page or business component) thenyour data access code can omit extensive data validation. However, make sure youuse SQL parameters in your data access code. These parameters validate inputparameters for type <strong>and</strong> length. The next section discusses the use of SQLparameters.SQL InjectionSQL injection attacks can occur when your application uses input to constructdynamic SQL statements to access the database. SQL injection attacks can also occurif your code uses stored procedures that are passed strings which contain unfiltereduser input. SQL injection can result in attackers being able to execute comm<strong>and</strong>s inthe database using the application login. The issue is magnified if the applicationuses an overprivileged account to connect to the database.Note Conventional security measures, such as the use of SSL <strong>and</strong> IPSec, do not protect youagainst SQL injection attacks.Preventing SQL InjectionUse the following countermeasures to prevent SQL injection attacks:● Constrain input.●Use type safe SQL parameters.Constrain InputValidate input for type, length, format, <strong>and</strong> range. If you do not expect numericvalues, then do not accept them. Consider where the input comes from. If it is froma trusted source that you know has performed thorough input validation, you maychoose to omit data validation in your data access code. If the data is from anuntrusted source or for defense in depth, your data access methods <strong>and</strong> componentsshould validate input.

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

Saved successfully!

Ooh no, something went wrong!