note 108886 modified in security.filesystem by danbrown

From: Date: Fri, 01 Jun 2012 15:28:01 +0000
Subject: note 108886 modified in security.filesystem by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-188361@lists.php.net to get a copy of this message
you should check requested file name for back path.a person can delete your code file by going back to root directory.

for ex:- deletefile.php?file=../index.php

if no proper check for / or \\ any user can delete your index page or any usefull file.

you may use following function to check for back path.

<?php
function existBackPath($file){ 
	$file=str_replace("\\\\","/",$file);
 return preg_match('[\\/]', $file);
}
?>

if existBackPath function returns 1.It means someone is trying to delete file which does not exist in his/her directory rather it exist in your root directory. --was-- you should check requested file name for back path.a person can delete your code file by going back to root directory. for ex:- deletefile.php?file=../index.php if no proper check for / or \ any user can delete your index page or any usefull file. you may use following function to check for back path. function existBackPath($file){ $file=str_replace("\\","/",$file); return preg_match('[\/]', $file); } if existBackPath function returns 1.It means someone is trying to delete file which does not exist in his/her directory rather it exist in your root directory. http://php.net/manual/en/security.filesystem.php

« previous php.notes (#188361) next »