Current location: Hot Scripts Forums » Programming Languages » PHP » EndUsers data sanitizing script


EndUsers data sanitizing script

Reply
  #1 (permalink)  
Old 06-02-09, 12:33 PM
raydawg raydawg is offline
New Member
 
Join Date: Jun 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
EndUsers data sanitizing script

http://www.hotscripts.com/forums/lou...ly-simple.html

ok i found this data santizing script by EndUser but i can for the life of me figure out how to send PM's on this forum....so anyways!!

when i try to use it do something simple like this

Code:
echo sanitize(4,0,"testing");
and this is my result

Code:
tes;tin;g
im not sure what the problem is. the 4 should allow all alpha characters, 0 for no length requirements. is there an updated version of this script floating around, mabye the one i grabbed is bugged?

thanks
-Ray
Reply With Quote
  #2 (permalink)  
Old 06-02-09, 02:48 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
I ran it, both on the command line and through a browser, and it displayed "testing" - correctly.

Might be a character encoding issue?

Also - check your version of the sanitize code for line breaks that shouldn't be there.
Reply With Quote
  #3 (permalink)  
Old 06-02-09, 03:29 PM
raydawg raydawg is offline
New Member
 
Join Date: Jun 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
thank you for your response. after digging around in the code i found this exact line is the one thats causing the issues

Code:
// URL Decode
// Just in case stuff like this is submitted:
// <a href="http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D">Google</a>
// Note: Normally urldecode() would be easier but it removes plus signs
    $data = preg_replace("/([a-z0-9]{3})/i", "&#x\\1;", $data);
if i comment out that line everything works fine.

there is a line right before that almost identical that does this
Code:
$data = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $data);
and that works, its just that first one that screws everything up. and honestly im not familiar enough with what he is trying to accomplish to really debug that. any ideas?
Reply With Quote
  #4 (permalink)  
Old 06-02-09, 04:22 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
PHP Code:

preg_replace("/([a-z0-9]{3})/i""&#x\\1;"$data); 

Would replace all sequences of 3 or more lowercase letters and numbers with &#x(sequence);

For example:

testing would become tes;tin;g

If you put the % in, then only those strings that begin with % will match and function as the comment describes.

This is the code I have:


// URL Decode
// Just in case stuff like this is submitted:
// <a href="http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D">Google </a>
// Note: Normally urldecode() would be easier but it removes plus signs
$data = preg_replace("/%u0([a-z0-9]{3})/i", "&#x\\1;", $data);
$data = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $data);


As I posted this, I can see what happened. The php, code, and quote tags stripped out the %u0 - probably as part of their sanitize processing.

Last edited by wirehopper; 06-02-09 at 04:27 PM.
Reply With Quote
  #5 (permalink)  
Old 06-02-09, 04:58 PM
phpdoctor's Avatar
phpdoctor phpdoctor is offline
Code Guru
 
Join Date: Feb 2007
Location: New Zealand
Posts: 767
Thanks: 4
Thanked 2 Times in 2 Posts
Lol i had this problem too.
Thanks wirehooper for the fix
__________________
01010000 01001000 01010000
Reply With Quote
  #6 (permalink)  
Old 06-02-09, 05:27 PM
raydawg raydawg is offline
New Member
 
Join Date: Jun 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
awesome thanks it works
Reply With Quote
  #7 (permalink)  
Old 06-03-09, 08:58 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by wirehopper View Post
As I posted this, I can see what happened. The php, code, and quote tags stripped out the %u0 - probably as part of their sanitize processing.
Yep- posting it to the board apparently mangled it a little bit. I didn't notice that when I posted the code. That puzzled me for a bit, since I use the script extensively and have never seen the problem mentioned in this thread.

Note: I can't take full credit for the script- some of it was borrowed from a Code Ignitor module, some of it I added, expanded, or refined myself. In any case, I hope it works for you.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]

Last edited by End User; 06-03-09 at 09:03 AM.
Reply With Quote
  #8 (permalink)  
Old 06-03-09, 11:00 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
I think the issue is related to the new skin on the forum, because I copied the code from the forum a few months ago.
Reply With Quote
  #9 (permalink)  
Old 06-03-09, 12:42 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
In my opinion, sanitizing input data is the single most important thing you can do when writing a web app these days. The hackers have gotten extremely aggressive, very crafty, and they let bots do most of their dirty work so they run 24/7, searching for forms to exploit.

If you don't sanitize your input data, you WILL be hacked. It's no longer a question of "if", it's a question of "when". The bots neither know nor care whether your site is big or small, busy or not, or what it does. It doesn't matter to them. All they want is to compromise your site so they can use your server as a platform for spamming, storing warez/kiddie porn, and/or using it as a source to infect visitor's browsers.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #10 (permalink)  
Old 06-03-09, 12:43 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by wirehopper View Post
I think the issue is related to the new skin on the forum, because I copied the code from the forum a few months ago.
Ahh, well, that could be why I didn't notice it, lol.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Eliminating HTML element ben777 PHP 2 04-17-09 08:02 PM
Raffle/Lottery Script (Very profitable!), Coded it myself. Voltaire General Advertisements 6 03-16-09 07:15 AM
3 Column CSS Fluid Layout (IE 6 Problem) Heidenreich12 CSS 9 10-04-06 03:22 PM
CSS Border Width Question. nova912 CSS 6 09-07-06 09:13 AM


All times are GMT -5. The time now is 08:37 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.