We have inherited an old website with almost 2000 different hand built SQL strings taking the variables directly from httprequests. The site is compromised by SQL injection attack regularly. Obviously this site should have been coded using SQL parameters to avoid this security nightmare, but due to the workload involved changing these we are looking for another way of 'cleaning' the incoming requests.
Main Clean Function :-
Public Function myRequest(ByRef Request As HttpRequest, ByVal param As String) As String
Return CleanRequest(Request(param))
End Function
Public Function CleanRequest(ByVal requestString As String) As String
Dim badChars() As String = {"select", "drop", ";", "--", "insert", "delete", "xp_", "update"}
Dim newChars As String = requestString
For i = 0 To UBound(badChars)
newChars = Replace(newChars, badChars(i), "", 1, -1, vbTextCompare)
Next
CleanRequest = Replace(newChars, "'", "''")
End Function
Called as so :-
Dim details As DataSet
detailsSQL = "select * from mytable where tableid = '" & myRequest(Request, "tableid") & "'"
details = sql.sqlSelect(detailsSQL)
Note that the code is structured and named as it is for easy find & replace. With this code in place though the site continues to be regularly compromised. Can anyone recommend additions to the main 'clean' function that will help stop these injection attacks?