Anti-SQL Injection Function





4
Date Submitted Mon. Nov. 13th, 2006 8:58 AM
Revision 1 of 1
Beginner Mattkins
Tags SQL | VBSCRIPT
Comments 6 comments
This is a quick and dirty function for preventing SQL Injection, the function is designed to clean any variable that will be concatenated into an SQL query. Apostrophes and Double-Quotes are changed to entities in order to ensure that encoding does not become an issue when the content is pulled back into a page. I'm looking for criticism here, I want to know if this is secure or not.

Function mysql_escape(thisWord)
        Dim newWord
        If thisWord <> "" Then
        newWord = Replace(thisWord,"/*","")
        newWord = Replace(newWord,"*/","")
        newWord = Replace(newWord,"UNION","")
        newWord = Replace(newWord,";","\;")
        newWord = Replace(newWord,"'","&amp;rsquo;")
        newWord = Replace(newWord,"""","&amp;quot;")
        newWord = Replace(newWord,"\","\\")
        End If
        mysql_escape = newWord
End Function

Example Use:
sql = "
SELECT * FROM table WHERE key = '" & mysql_escape(Request.QueryString("value")) & "'"

...

 

Matt Atkins

Comments

Comments Dirty, yes
Mon. Nov. 13th, 2006 9:48 AM    Scripter SCoon
  Comments ?
Mon. Nov. 13th, 2006 11:29 AM    Beginner Mattkins
Comments FUBAR
Mon. Nov. 13th, 2006 9:00 AM    Beginner Mattkins
  Comments Use the download link
Mon. Nov. 13th, 2006 11:55 AM    Helper lgrover
Comments RTFM?
Mon. Nov. 13th, 2006 1:27 PM    Beginner elderfo
  Comments Yup
Tue. Nov. 14th, 2006 12:53 PM    Beginner Mattkins

Voting