Home > Software Quality Tips > Application Security Strategies > SQL injection: Developers fight back
Software Quality Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

APPLICATION SECURITY STRATEGIES

SQL injection: Developers fight back


Anurag Agarwal
04.06.2006
Rating: -3.78- (out of 5)


Software quality news and advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


SQL injection is one of the newer attacks aimed at Web application security in the cybercrime world. It is targeted at your database, which stores sensitive information of your employees or customers. This type of attack exploits vulnerabilities in your application to access your database by manipulating the SQL queries in your application via the input boxes of your Web form.

A lot has already been written on how SQL injection attacks are done, so I am not going to go into that. I have some links at the bottom for you to get more information on how this attack works.

What I want to do is take a look at 10 steps you can take to prevent applications from being vulnerable to this type of attack.

Input validation
Let's explore input validation further. Usually, any Web application has some input boxes to collect data from the user. When a Web form is submitted, the input values are submitted to the application running at the server. The application should validate the input before processing it. Certain steps can be taken to protect the application from malicious input.

Authentication input: Authentication being the entry point of the system is a more sensitive area, and the likelihood of an attacker trying SQL injection here is extremely high. Moreover, if authentication is compromised, then the attacker has unauthorized entry into your system. Some of the techniques we can implement here include the following:

Other form field input: Let's take a look at some of the common form fields that are usually available before authentication and what can you do to prevent SQL injection attacks in those fields.

  • Registration page: This page usually consists of multiple fields. Apply the appropriate validation techniques for different fields based on the sample code below.

  • Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


    RELATED CONTENT
    Application Security Strategies
    Fixing four Web 2.0 input validation security mistakes
    Social engineering training could disrupt botnet growth
    Web security problems: Five ways to stop login weaknesses
    Common mistakes in real-time Java programming
    Preparing for testing applications in the cloud
    The role of quality assurance (QA) pros in software security
    Common software security risks and oversights
    Using the Firefox Web Developer extension to find security flaws
    Web application security testing checklist
    How to develop secure applications

    Building security into the SDLC (Software development life cycle)
    The role of quality assurance (QA) pros in software security
    Common software security risks and oversights
    Why the quality assurance department should be involved in testing
    How to develop secure applications
    Secure software development practices 'not rocket science'
    How to prevent HTTP response splitting
    Browser security a concern for website development
    Web application security and the PCI DSS
    PCI DSS compliance: Web application firewalls (WAFs)
    PCI DSS compliance: The basics

    Threat modeling
    Web application security and the PCI DSS
    The essentials of Web application threat modeling
    How to implement security in Java EE and Java ME
    Application security shouldn't involve duct tape, Band-Aids or bubble gum
    Stop SQL injection attacks on applications
    How to counter XSS attacks
    Breaking the same origin barrier of JavaScript
    Protection against "zero-minute" exploits
    Denial of service and Ajax
    CSRF attack vector with Ajax serialization

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary


    >

  • Feedback and suggestions: If this is stored in the database, then it should be stored as a CLOB. Using PreparedStatement and storing it as a CLOB will protect it from most types of attacks.
  • Contact Us: If there is no reporting or tracking requirement for this information, then architects should avoid storing this information in the database. Accept the form fields and send them as an e-mail. That gives you one less area to protect from SQL injection.
  • Input validation techniques
    Ideally, architects can define in the design phase what type of input is expected (alphabets, numeric, alphanumeric) and what characters are allowed for that type of input. Let's take a look at an example with sample code in Java.

    Username validation -- The following rules will apply:

    Sample code:

    For numeric input, convert it to integer as well before appending into your SQL query. If it throws a NumberFormatException, then it is not a valid input.

    It might get a little tedious to define rules for all the individual fields. In such scenarios, architects can divide the fields into multiple categories, such as single word, multiple words, multiple words with punctuations, e-mail address, numeric input, etc., and define rules for those categories.

    As you can see, by taking certain measures, you can avoid common vulnerabilities and create more secure Web applications. After all, every step, however small, is a step forward in securing your application.

    More information:
    List of SQL injection attacks by example

    List of escape characters

    -------------------------------
    About the author: Anurag Agarwal, CISSP, works for a leading software solutions provider where he addresses different aspects of application security. You may e-mail him at anurag.agarwal@yahoo.com.


    Rate this Tip
    To rate tips, you must be a member of SearchSoftwareQuality.com.
    Register now to start rating these tips. Log in if you are already a member.




    DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



    Software Design & Testing - Project Management
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




    All Rights Reserved, Copyright 2006 - 2009, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts