note 48286 added to function.trim

From: Date: Fri, 17 Dec 2004 20:16:40 +0000
Subject: note 48286 added to function.trim
Groups: php.notes 
Request: Send a blank email to php-notes+get-81940@lists.php.net to get a copy of this message
Hi! I think this could help programmers they want to be sure that when they receive the variables by GET,POST or in another way that they can't be attacked or make the server in a security problem, as it happens in the PhpBB bug (all version before 2.0.11). Imagine you have 2 variables you get them by GET or POST, we will assume that you have global ON in the php.ini setup working with apache: $page and $domain <?php require("security.php"); // at the beginning $page = protect($page); $domain= protect($domain); // ... now you can use the variables without any problem... ... ?> And the security.php include the secure next code: <?php function protect($cadena) { $cadena2= ""; $posi=0; // normally only a-z,A-Z,0-9 allowed. // modify it as you could need... while ( ($cadena[$posi]>='a' && $cadena[$posi]<='z') || ($cadena[$posi]>='A' && $cadena[$posi]<='Z') || ($cadena[$posi]>='0' && $cadena[$posi]<='9') ){ $cadena2[$posi]= $cadena[$posi]; $posi++; // block MAX SIZE for string. // don't use STRLEN or // they could run commands as system() if the php/apache hasn't this command or other exec disabled functions... if($posi>500) return join($cadena2,""); } return join($cadena2,""); } ?> I hope this help to program better and increase the security programming your apps. If you need more info don't hesitate contact me raul@navenetworks.com. I speak english, french and spanish. Raul Mate Galan Ceo Navenetworks www.navenetworks.com www.buenhospedaje.com ---- Manual Page -- http://www.php.net/manual/en/function.trim.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48286 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48286&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48286&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48286&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48286&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48286&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48286&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48286&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81940) next »