Author |
Topic |
holster100
Starting Member
13 Posts |
Posted - 2008-06-25 : 15:14:21
|
I wonder if anyone can help. My ASP site is always getting SQL injection attack attempts, so I've decided to parameterize my queries in the code: Set cmd = Server.CreateObject("ADODB.Command") Set cmd.ActiveConnection = objConn 'insert your stored procedure or SQL here cmd.CommandText = "stored_mysp" cmd.CommandType = adCmdStoredProc cmd.Parameters.Append cmd.CreateParameter("firstrecord", adSmallint, _ adParamInput,50, firstrecord)The problem is that if (for whatever reason) the "firstrecord" variable is passed, and it's not an integer, it causes a "parameter not supplied" error (which I get via email).This is often the case during an attempted SQL attack. I know the stored procedure is not being executed, but how do I safely check the parameters and redirect the user away before I even open a connection?Is there a verify parameter command?Thanks! |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-06-25 : 15:31:57
|
Are you assiging the value to the variable firstrecord?Then why not to check it before you open a connection?MadhivananFailing to plan is Planning to fail |
|
|
holster100
Starting Member
13 Posts |
Posted - 2008-06-25 : 16:30:17
|
Yes, good idea madhivanan. What would be the best way of checking a varchar parameter? Is there a command prompt to do it? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-06-25 : 16:35:43
|
What is the datatype of the variable firstrecord?If it is smallint/int, you cant obviously assign any varchar dataMadhivananFailing to plan is Planning to fail |
|
|
holster100
Starting Member
13 Posts |
Posted - 2008-06-25 : 16:43:03
|
Sorry, I was talking about another parameter, which is varchar:Set cmd = Server.CreateObject("ADODB.Command") Set cmd.ActiveConnection = objConn cmd.CommandText = "stored_mysp" cmd.CommandType = adCmdStoredProc cmd.Parameters.Append cmd.CreateParameter("strinst", adVarChar, _ adParamInput,50, inst) |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-06-25 : 16:46:21
|
quote: Originally posted by holster100 Sorry, I was talking about another parameter, which is varchar:Set cmd = Server.CreateObject("ADODB.Command") Set cmd.ActiveConnection = objConn cmd.CommandText = "stored_mysp" cmd.CommandType = adCmdStoredProc cmd.Parameters.Append cmd.CreateParameter("strinst", adVarChar, _ adParamInput,50, inst)
So, what do you want to check on inst?MadhivananFailing to plan is Planning to fail |
|
|
holster100
Starting Member
13 Posts |
Posted - 2008-06-25 : 16:49:34
|
i want to check that inst is a varchar of less than 50 characters, so I can redirect before it goes into the SP and doesn't cause an error. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-06-25 : 16:57:28
|
If LEN(inst)<50--Do task1--else--Do task2End ifMadhivananFailing to plan is Planning to fail |
|
|
|