jeudi 3 mai 2012
ASP: avoid SQL injections
Do you like this story?
If you work a lot with ASP and SQL, you might already know about SQL injections.
It's quite clear that every time we offer a visitor the possibility of filling a form (whatever its purpose may be), there's a security risk for our database. Basically, an attacker can insert some code in a form element, which will serve as a breach, allowing access to data stored in the database.
How that's done is not the main topic of this short post, however we should be aware of the fact that those threats are often used to update, delete and insert data, or in worst cases, they are used in order to gain access to reserved areas of a web site.
In this article, we are going to create a small VBScript function to avoid SQL injections.
query = "SELECT * FROM users WHERE username= '" & name & "';"If an attacker fills the form with something like:
' or '1'='1query = "SELECT * FROM users WHERE username ='' or '1'='1';So, we create a small function that will do that.
<%
Function CleanText(subText)  
  If Len(subText) > 0 Then
   subText= Replace(subText,"'","''")
   subText= Replace(subText, "*", "[*]")
   subText= Replace(subText, "%", "[%]")
  End If
CleanText=subText
End Function
%><%name = CleanText(Request.QueryString("name"))%>And that's all for today!

This post was written by: Franklin Manuel
Franklin Manuel is a professional blogger, web designer and front end web developer. Follow him on Twitter


0 Responses to “ASP: avoid SQL injections”
Enregistrer un commentaire