note 84799 added to function.preg-replace

From: Date: Wed, 30 Jul 2008 16:21:31 +0000
Subject: note 84799 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-142933@lists.php.net to get a copy of this message
People using functions like scandir with user input and protecting against "../" by using preg_replace make sure you run ir recursivly untill preg_match no-long finds it, because if you don't the following can happen. If a user gives the path: "./....//....//....//....//....//....//....//" then your script detects every "../" and removes them leaving: "./../../../../../../../" Which is proberly going back enough times to show root. I just found this vunrability in an old script of mine, which was written several years ago. Always do: <?php while( preg_match( [expression], $input ) ) { $input = preg_replace( [expression], "", $input ); } ?> ---- Server IP: 92.48.74.199 Probable Submitter: 82.70.146.13 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/84799 Del: integrated -- https://master.php.net/note/delete/84799/integrated Del: useless -- https://master.php.net/note/delete/84799/useless Del: bad code -- https://master.php.net/note/delete/84799/bad+code Del: spam -- https://master.php.net/note/delete/84799/spam Del: non-english -- https://master.php.net/note/delete/84799/non-english Del: in docs -- https://master.php.net/note/delete/84799/in+docs Del: other reasons-- https://master.php.net/note/delete/84799 Reject -- https://master.php.net/note/reject/84799 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#142933) next »