Solved

Escaping characters to stop SQL injection, ASP

Posted on 2010-11-14
9
599 Views
Last Modified: 2012-06-27
Hi Guys and Gals,
I have an ASP site in which users are adding items to the DB (login, password, and a little bit of other info).  I am looking for a way to stop the chance of SQL injections from happening.

I also use Dreamweaver to build the site and to make the majority of the DB connections and inserts/updates, etc.

My idea is to remove possible characters from the user generated form data before it hit the sql string.  Here is a list of character I was thinking of removing or not allowing: =, <, >, /-+*, ', "

My idea was to build a function that would remove all of the characters listed above.

Would that stop SQL injection attacks?

Thanks,
Slim
0
Comment
Question by:Slim81
9 Comments
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34131764
That will stop names like Jean-luc and comments like
O'brian said, "30+ only please"
It makes sense in some limited uses, but generally you should look at using parameters to state exactly what input matches what parts of the query, letting parameterization take care of protection
0
 
LVL 77

Expert Comment

by:arnold
ID: 34131847
The best way is to validate the data  being provided to match the input being expected and not passing the input data directly to the sql.

http://forums.asp.net/t/1254125.aspx

http://msdn.microsoft.com/en-us/library/ff648339.aspx
0
 
LVL 30

Accepted Solution

by:
Wayne Barron earned 500 total points
ID: 34131951
See if this will give you what you are wanting.

http://www.experts-exchange.com/A_3626.html


Good Luck
Carrzkiss
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 6

Expert Comment

by:YohanF
ID: 34132144
I am not sure how to do this, but if you use prepared statements, or as they call parameterised queries.
0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 34133580
@YohanF
Yes, it is called that, and it listed in the article that I wrote of which I provided the link for.
Which gives you everything that you need to learn how to do it.

Have a good one.
Carrzkiss
0
 
LVL 6

Expert Comment

by:YohanF
ID: 34136119
@carrzkiss, good one.. I havent done ASP my self, its just the prepared statements is whats called in java.. ;)
0
 
LVL 7

Expert Comment

by:rmm2001
ID: 34140000
One thing that you need to add too is to stop "1=1" / n=n requests in your query statement.
0
 
LVL 4

Author Closing Comment

by:Slim81
ID: 34148550
Thanks for pointing me to the article you have written carrzkiss.   That information is going to help me greatly....
0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 34148707
You are most welcome Slim.
I learned how to do the Parameterized queries the beginning of 2009
And would not change the way I code today for nothing in this world.

If you jump over and do any VB.NET programming, then it is changed up slightly
But not much, I am still learning it, but is not at the top of my priority list at the moment.

Take care and have a good one.
Carrzkiss
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL View Syntax case etc 5 35
SQL Server syntax question 13 32
Loops and updating in SQL Query 9 29
SQL Use Distinct with two fields 3 11
Provide an easy one stop to quickly get the relevant information on common asked question on Ransomware in Expert Exchange.
This story has been written with permission from the scammed victim, a valued client of mine – identity protected by request.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question