TBDev Forum
Programming board
Main Page Forum Rules Privacy Policy Members Contact Us
Welcome Guest (Login | Register)
TBDev Forum TBDev.net - Mods & hacks Mods In Progress Verify strings (security)

Verify strings (security)

2007-01-28 21:16:00
Group: Member
Posts: 11
Topics participated: 9
Topics started: 2
First post: 2006-10-16 00:17:00
Last post: 2007-08-29 15:24:00
This mod is supposed to be a security enhancement and verifies if the supplied strings really contain what they should contain. For example it verifies if a string *really* contains a number but not something else in addition. It is very good to use such caution if you are dealing with user input that can influence SQL statements or can cause critical damage.

In my opinion mysql_real_escape_string is not enough as it only escapes certain characters and there are still possibilites a string is sent with a SQL statement that is not as intended (like normal alphabet where there should be only a number). Note that this function is useful however in certain cases but not all. The verifystring function verifies roughly if certain formats are kept and executes the die command if it finds anything that's not supposed to be there.

Guide to where this function should and should not be placed:
- Should be used on the line before the command that uses that variable.
- If that variable is changed or could be changed, place after the command but before it is used again. If not used again, no need to use it again.
- Not to be used for functions that use data straight from integer columns in SQL unless it's used to calculate or change other variables (like math formulas and "id" column data).
- Should not be used for big text fields with no special restrictions of certain characters, like forum posts. Use mysql_real_escape_string instead.

This function is supposed to be as secure as possible but I'm not perfect. Therefore, I place it under your review so you can check it out and/or maybe help make it better as there could be something I have forgotten or not bothered to do.

Notes:
1. I did not use any of the regular expressions codes because I would like to keep this code as PHP-module independent as possible.
2. Some places do have "older functions" rather than the new ones so it can be used in older PHP versions (the aim was PHP 4 although I use PHP 5 myself).
3. The e-mail domain-part verification (checkdnsrr) depends on functions not compatible with the Windows versions of PHP. You might want to leave them out or change them for code that works on the Windows platform if you are aiming to use that on Windows.
4. The "die()" functions are not executed inside the verifystring function as that would just stop the function and not the whole code and therefore still execute the rest of it.
5. Don't know exactly why I developed the md5 function but I figured some people would like to have it.
6. If you really don't want the whole script to die, you can change "die($verifystring);" for "bark($verifystring);" but that is not recommended. (if somebody is really breaking into your site, you don't really need them to finish executing the PHP code).

This snippet can be placed anywhere in include/bittorrent.php but I suggest right below the line "" at the top.
/*
$verifystring = verifystring($string_to_verify,$type);
if($verifystring !== TRUE)
 

Similar threads

Topic Posts Last post
Security 5 2008-03-19 00:05:00
security 2 2008-02-24 01:08:00
More security 11 2008-08-11 01:12:00
Best Security 1 2007-11-18 15:19:00
even more security 13 2008-12-14 22:56:00