Home > Ask the Security Experts > Expert Archive: Information Security Threats Questions & Answers > What software development practices prevent input validation attacks?
Ask The Security Expert: Questions & Answers
EMAIL THIS

What software development practices prevent input validation attacks?

Ed Skoudis, past SearchSecurity.com expert EXPERT RESPONSE FROM: Ed Skoudis, past SearchSecurity.com expert

Pose a Question
Other Security Categories
Meet all Security Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 30 November 2007
Are there countermeasures that can prevent input-validation attacks? Can you offer any advice for writing input-validation code for application development?


BROWSE BY TAG
Application and Platform Security,   Software Development Methodology,   Application Attacks (Buffer Overflows, Cross-Site Scripting),   Expert Archive: Information Security Threats,   VIEW ALL TAGS

Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
Software Development Methodology
nCircle statistics show rising Web application vulnerabilities
Common PCI questions: Web application firewalls or source code review?
Juniper pulls ATM hacking presentation from Black Hat
V.i Labs integrates Google maps to track software piracy
Software Piracy pandemic needs government role, better vendor antipiracy plans
Software piracy losses total $53 billion, study finds
Google study backs browser silent auto update feature
Secure software development starts before coding begins
Security budget issues to resonate at RSA Conference
Twitter worm attack highlights social network flaws

Application Attacks (Buffer Overflows, Cross-Site Scripting)
Adobe ColdFusion websites being compromised
PCI management: The case for Web application firewalls
Month of Twitter Bugs project to document Twitter flaws
Adobe issues first quarterly patch release fixing 13 flaws
Balancing security and performance: Protecting layer 7 on the network
Adobe issues Reader update fixing zero-day flaw
The Pipe Dream of No More Free Bugs
Security Squad: Federal cybersecurity defenses
Oracle issues 43 updates, fixes serious database flaws
Attackers target new Microsoft PowerPoint zero-day flaw
Application Attacks (Buffer Overflows, Cross-Site Scripting) Research

Expert Archive: Information Security Threats
The telltale signs of a network attack
Will Google Chrome enhance overall browser security?
Are there antivirus suites that pick up more than just run-of-the-mill viruses?
What tools can a hacker use to crack a laptop password?
Are social networking sites an easy target for malicious hackers?
What are the dangers of cross-site request forgery attacks (CSRF)?
Should social engineering tests be included in penetration testing?
What kind of data is compromised during a Google hack?
Best practices for using restriction policy whitelists
Defining mobile device security concerns

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
bypass  (SearchSecurity.com)
Common Weakness Enumeration  (SearchSecurity.com)
debugging  (SearchSoftwareQuality.com)
fuzz testing  (SearchSecurity.com)
heuristics  (SearchSoftwareQuality.com)
sandbox  (SearchSecurity.com)
threat modeling  (SearchSecurity.com)
trigraph  (SearchSecurity.com)

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


This question is extremely important, as improper input validation leads to numerous kinds of attacks, including cross-site scripting, SQL injection, command injection, buffer overflows and many others.

Most applications only need to accept a limited set of characters as input, typically plain old alpha and numeric. If an app needs to get a specific name and age, for example, one alpha field and one numeric field will suffice. Without proper filtering, however, attackers might be able to use other characters, including semicolons, greater-than or less-than symbols, and quotation marks to exploit the application. If a software developer does not properly screen all forms of user input to remove unusual characters, the software may be exploitable in countless different ways. Software's input-validation function removes these characters, acting as a shield.

Unfortunately, some software developers either leave out input-validation code altogether, or they implement weak input validation that might not filter out a truly comprehensive set of characters. Also, there are dozens of ways to alter or encode data to dodge validation filters: UTF-8, Hex, Unicode, mixed case and many more. There's a great article by RSnake that shows some different encoding tricks designed to slip cross-site scripting attacks past weak input-validation code.

With that overview in mind, let's turn to your question: how can you prevent input-validation attacks? This is really an issue for software developers, and there isn't much that users can do to prevent these attacks. For software developers that want to make sure that their input-validation code is up to snuff, use the following as a checklist:

  • Specify variable types: Use the type enforcement capabilities of your development environment to limit the kind of data that can be entered into some fields. In particular, if you only need to accept an integer in a field, define that variable as an integer (if your development environment and language allow you do that) so that your software will reject any entered strings.
  • Don't define all possible badness; instead only accept goodness: Trying to create a comprehensive list of all bad characters for all the different kinds of attacks is next to impossible. Thus, when creating validation code, define what characters are acceptable, such as A-Z, a-z, and 0-9, and filter out everything else. Such a "deny-all-except-for-certain-allowable-characters" approach is a far stronger way to write filtering code.
  • Limit size of input: If you ask for someone's age, keeping it to a three-digit field will cover every reasonable case, even the centenarians in your user population. If you ask for someone's name, a hundred or so characters are reasonable. That way, even if you aren't properly filtering for characters appropriately, you are still limiting the real estate that the attacker has to pull off an attack.
  • Canonicalize before filtering: If user input is encoded in a fashion that the filters aren't designed to handle, you very well might get hacked. Thus, whenever you receive user input, convert it to a standard encoding scheme, such as plain ASCII, before applying your filters. This process is known as canonicalization, and it converts character streams of different encoding patterns to a single format that is compatible with your filtering code.
  • Filter all input: Filter every form of input to your application, including data that comes in via the network, the GUI, files read from the file system and so on. Don't assume that one of your fields or input vectors isn't important. Attackers will hunt for weaknesses and exploit them, so cover all of your bases.
  • Filter on the server side: In many applications, attackers might be able to control clients, such as browsers or thick-client GUIs, tweaking their functionality to bypass filtering done at the client. Thus, filter on the server side to protect all back-end functionality.
  • Don't worry about multiple layers of filtering: Sometimes, a single application will include multiple modules, each of which filters input that flows through that mod. This architecture could result in a single set of input getting filtered multiple times as it snakes its way through the application. While that might be a performance concern, it's actually a good thing from a security perspective. The layers of filtering act like belts and suspenders to keep the overall application secure.
  • Use tried-and-true filters if available: Rather than rolling your own code for user input validation, use filters that have been carefully developed and rigorously tested by others, if you have access to such code. Some software development firms and large enterprises doing in-house development have defined reusable input validation code for all software they create. Find out if your organization has such code, learn how it works, and then use it. If you don't have such code in-house, you can adapt user input-validation code snippets from a variety of free sources. One of my favorites is the user input-validation code for PHP called Inspekt, funded by the OWASP project. Even if you don't use PHP, the concepts in the Inspekt project can be leveraged in other languages.
  • Get a penetration test: To make sure your code is secure, subject it to a controlled penetration test to see if flaws can be identified.

More information:

  • Learn more about canonicalization, one particular type of input validation attack.
  • A SearchSecurity.com reader asks expert Ed Skoudis, "What new tactics can enterprise security professionals use to protect against cross-site scripting?"




  • Search and Browse the Expert Answer Center
    Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
    Browse our Expert Advice



    Find Security Solutions for Your Business
    Targeted Security Channel Tips for Resellers, Integrators and Consultants
    TechTarget Security Media
    Information Security View this month\\'s issue and subscribe today.
    Information Security Decisions Apply online for free conference admission.
    SearchSecurity.com
    HomeNewsMagazineMultimediaWhite PapersLearningAdviceTopicsEventsAbout Us

    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    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 2003 - 2009, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts