Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 22nd, 2007, 03:46 PM
smiller71's Avatar
smiller71 smiller71 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 50 smiller71 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 47 m 38 sec
Reputation Power: 2
Send a message via AIM to smiller71 Send a message via Yahoo to smiller71
Smile Little snippet in ASP to protect from SQL Injections

[code]
<%
'Snippet to protect SQL database from common sql injections
'PLEASE THIS CODE ON THE FORM PROCESSING ASP PAGE OR PROCESS THIS AS A FUNCTION AT TIME OF FORM SUBMISSION
'this code disallows the following characters and phrases in all form fields
' *, ; , ' , \ , select, sys, exec, delete, update, insert
'I like to use this as my final validation. I use javascript validations to avoid blank entries, etc.. but this is great to use as a FINAL check before processing a form.
'Happy CODING!





response.Buffer = True

for each item in request.form
if Trim(Lcase(Instr(request.form(item),"*")))or Trim(Lcase(Instr(request.form(item),"'"))) or Trim(Lcase(Instr(request.form(item),";"))) or Trim(Lcase(Instr(request.form(item),"select"))) or Trim(Lcase(Instr(request.form(item),"sys"))) or Trim(Lcase(Instr(request.form(item),"exec"))) or Trim(Lcase(Instr(request.form(item),"delete"))) or Trim(Lcase(Instr(request.form(item),"update"))) or Trim(Lcase(Instr(request.form(item),"insert"))) or Trim(Lcase(Instr(request.form(item),"\"))) THEN
response.write"<BR>THERE WAS AN ERROR PROCESSING YOUR FORM<br><a href='javascript:history.go(-1)'>Go back to edit your form</a>"
'STOP PROCESSING THE FORM AND SEND ERROR MESSAGE ABOVE.. YOU CAN CUSTOMIZE THIS AREA
response.End()
else
End if
next
Response.write"YOUR FORM WAS SUBMITTED SUCCESSFULLY!"
'continue executing your form and insert/updates into database
%>

Last edited by smiller71 : May 23rd, 2007 at 03:26 PM. Reason: people who tag emails

Reply With Quote
  #2  
Old May 22nd, 2007, 07:22 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 22 h 9 m 49 sec
Reputation Power: 181
Well, I wouldn't use this code but each to their own ...
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #3  
Old May 23rd, 2007, 05:48 AM
degsy degsy is offline
Contributing User
ASP Free God 2nd Plane (6000 - 6499 posts)
 
Join Date: Aug 2005
Location: North East, UK
Posts: 6,191 degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 19 h 41 m 52 sec
Reputation Power: 121
That's alot of restriction of input especially if a user is submitting a message (memo or large text field)


The basics for SQL injection for ADO is to escape an apostrophe/single quote that encloses text/date fields.

You do this by Replacing one quote with two


For number fields you check if the parameter is a numerical value.
You can also do the quote replace but it's not essential if you have other sanitization and validation.
__________________
CyberTechHelp

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Little snippet in ASP to protect from SQL Injections


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT