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 January 12th, 2006, 05:10 PM
minus4's Avatar
minus4 minus4 is offline
short arse brainiac
ASP Free Novice (500 - 999 posts)
 
Join Date: Jun 2005
Location: Leeds UK
Posts: 577 minus4 User rank is Sergeant Major (2000 - 5000 Reputation Level)minus4 User rank is Sergeant Major (2000 - 5000 Reputation Level)minus4 User rank is Sergeant Major (2000 - 5000 Reputation Level)minus4 User rank is Sergeant Major (2000 - 5000 Reputation Level)minus4 User rank is Sergeant Major (2000 - 5000 Reputation Level)minus4 User rank is Sergeant Major (2000 - 5000 Reputation Level)  Folding Points: 800 Folding Title: Novice Folder
Time spent in forums: 4 Days 1 h 39 m 38 sec
Reputation Power: 30
Send a message via MSN to minus4
Cross site scripting prevention and security

Cross site scripting is a big problem on any dynamic page that sends data back to the user.

can reult in cookie and session data been stolen, and other things.
prevention is cheaper than the cure with this function.

Code:

function getUserInput(input, stringLength)

 dim newString, regEx
 Set regEx = New RegExp
 
 ' only specified length
 newString = left(trim(input),stringLength)   
 
 if pFilteringLevel=1 then  
 
  regEx.Pattern 	= "([^A-Za-z0-9@=:/*|' _-]+.%)"
  regEx.IgnoreCase 	= True
  regEx.Global 		= True
  newString 		= regEx.Replace(newString, "")
  Set regEx 		= nothing   
  
  newString		= replace(newString,"--","")
  newString		= replace(newString,";","")      
  newString	        = replace(newString,"'","'") 
  newString	        = replace(newString,"<script>","[script]") 
  
 end if
 
 if pFilteringLevel=2 then
    
  newString	= replace(newString,"--","")
  newString	= replace(newString,";",";") 
  newString	= replace(newString,"=","=") 
  newString	= replace(newString,"(","(") 
  newString	= replace(newString,")",")")   
  newString	= replace(newString,"'","'") 
  newString	= replace(newString,"""",""") 
  newString	= replace(newString,"<script>","[script]") 
 
 end if


to use this here is an example

Code:
Firstname = getUserInput(request.Form("fname"))


thats it, and you can add anything you dont want in your site, including swear words, certain comments, email address, links to other sites etc.

enjoy
Comments on this post
nofriends agrees!

Reply With Quote
  #2  
Old April 19th, 2006, 05:02 PM
Oracle.Of.All Oracle.Of.All is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 3 Oracle.Of.All User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 50 sec
Reputation Power: 0
Could you please explain to me how this code works?

i understand the replacing, but not quite the regex and pFilteringLevel stuff, and the trim function is also new to me.

Reply With Quote
  #3  
Old April 19th, 2006, 05:58 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,764 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 6 h 8 m 20 sec
Reputation Power: 452
Just a note:

1) You forgot the "End Function" statement.

2) This line isn't formatted properly
Code:
newString = replace(newString,"""",""")


3) Where does the "pFilteringLevel" variable come from, where is it being assigned?

4) Your function doesn't return a value

5) The validation can be bypassed by changing the case of the text from <script> to <SCRIPT>

6) The best way to prevent XSS attacks is to not allow these types of characters, and if you must allow them then replace them with their html equivalent character...

Code:
Function CleanUserData(strValue)
   Make everything uppercase, so you don't have to worry about case sensitivity
   strValue = UCase(strValue)

   Replace the values with their HTML counterpart
   strValue = Replace(strValue, "<SCRIPT>", "& # 60 ; script & # 62 ;")
   strValue = Replace(strValue, "</SCRIPT>", "& # 60 ; & # 47 ;script & # 62 ;") Formatted this way because the browser will read it as html if I didn't separate it.
  
   Continue for all characters you want to clean, or you could even store the values you want replaced in a database along with their "clean" counterpart

   CleanUserData = strValue
End Function
Comments on this post
Shadow Wizard agrees: good points.
minus4 agrees: but point 5 is not true

Last edited by Memnoch : April 19th, 2006 at 06:01 PM.

Reply With Quote
  #4  
Old April 24th, 2006, 08:14 AM
minus4's Avatar
minus4 minus4 is offline
short arse brainiac
ASP Free Novice (500 - 999 posts)
 
Join Date: Jun 2005
Location: Leeds UK
Posts: 577 minus4 User rank is Sergeant Major (2000 - 5000 Reputation Level)minus4 User rank is Sergeant Major (2000 - 5000 Reputation Level)minus4 User rank is Sergeant Major (2000 - 5000 Reputation Level)minus4 User rank is Sergeant Major (2000 - 5000 Reputation Level)minus4 User rank is Sergeant Major (2000 - 5000 Reputation Level)minus4 User rank is Sergeant Major (2000 - 5000 Reputation Level)  Folding Points: 800 Folding Title: Novice Folder
Time spent in forums: 4 Days 1 h 39 m 38 sec
Reputation Power: 30
Send a message via MSN to minus4
okay me bad, sorry i just took it out of my code, the filter level is a setting i have, depending what part of the site i want it for.
hence no end function, as it goes on and on for a while, for my xml feed, and changing the text around and stuff.

so below is corrected, and a few valid points taken.

Code:

function getUserInput(input, stringLength)

 dim newString, regEx
 Set regEx = New RegExp
 
 ' only specified length
 
 newString = left(trim(input),stringLength)   


  regEx.Pattern 	= "([^A-Za-z0-9@=:/*|' _-]+.%)<>()"
  regEx.IgnoreCase 	= True
  regEx.Global 		= True
  newString 		= regEx.Replace(newString, "")
  Set regEx 		= nothing   
  
  newString	= replace(newString,"--","")
  newString	= replace(newString,";","")      
  newString	= replace(newString,"'","'") 
  newString	= replace(newString,"=","=") 
  newString	= replace(newString,"(","[") 
  newString	= replace(newString,")","]")
  newString = replace(newString,"'","''")
  newString = replace(newString,"<","[")
  newString = replace(newString,">,"]")

getUserInput = newString
 
 end function


have not capitolized, as the output would be formatted, not filtered. and also i have asked it to ignor case with this line here:

regEx.ignorCase (as it was before)

have taken out script, and just filtered < >( )for [ [ ] ]

how this work:

StrfirstName = GetUserInput(Trim(request.Form("firstName"),20)

simply it takes the string and the max lenght you want it to be ie 20, and then filters. it first checks that it meets are pattern ie A-Z a-z ? . < > ( ) rather than chinese or anything else.

the trim is just to drop any extra spaces after or before the string, once these basic settings are set it will then (if found) replace the charactor in the first " " with what is in the second

so if you wanted to ban the word tickle but have it say wiggle

you would add this:

newString=Replace(newString,"tickle","wiggle")

the data stored would be the data with the new changes applied.

can also be used to format for database to stop single ' etc
__________________
A girl's best asset is her 'lie'ability.

For Sale: Parachute. Only used once, never opened, small stain.

that fold thing

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Cross site scripting prevention and security


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 1 hosted by Hostway
Stay green...Green IT