vbscriptasp-classiccode-injectioninput-filtering

How to prevent injections in ASP/VBScript?


What are the best ways (or at least most common ways) in ASP (VBScript) for input handling? My main concerns are HTML/JavaScript injections & SQL injections. Is there some equivalent to PHP's htmlspecialchars or addslashes, et cetera? Or do I have to do it manually with something like string replace functions?


Solution

  • The bottom line is this:

    1. Always HTML-encode user input before you write it to your page. Server.HTMLEncode() does that for you.
    2. Always use parameterized queries to interface with a database. The ÀDODB.Command and ADODB.CommandParameter objects are the right choice here.
    3. Always use the URLScan utility and IIS lockdown on the IIS server that renders the page, unless they are version 6 and up, which do not require these tools anymore.

    If you stick to points 1 and 2 slavishly, I can't think of much that can go wrong.

    Most vulnerabilities come from not properly encoding user input or building SQL strings from it. If you for some reason come to the point where HTML-encoding user input stands in your way, you have found a design flaw in your application.