prevent directory traversal in paths
This commit is contained in:
@@ -26,15 +26,21 @@
|
|||||||
*/
|
*/
|
||||||
function makeSecurePath($path) {
|
function makeSecurePath($path) {
|
||||||
|
|
||||||
|
// check for bad characters, some are allowed with escaping
|
||||||
|
// but we generally don't want them in our directory-names,
|
||||||
|
// thx to aaronmueller for this snipped
|
||||||
|
$badchars = array(':', ';', '|', '&', '>', '<', '`', '$', '~', '?', "\0");
|
||||||
|
foreach ($badchars as $bc) {
|
||||||
|
$path = str_replace($bc, "", $path);
|
||||||
|
}
|
||||||
|
|
||||||
$search = array(
|
$search = array(
|
||||||
'#/+#',
|
'#/+#',
|
||||||
'#\.+#',
|
'#\.+#'
|
||||||
'#\0+#'
|
|
||||||
);
|
);
|
||||||
$replace = array(
|
$replace = array(
|
||||||
'/',
|
'/',
|
||||||
'.',
|
'.'
|
||||||
''
|
|
||||||
);
|
);
|
||||||
$path = preg_replace($search, $replace, $path);
|
$path = preg_replace($search, $replace, $path);
|
||||||
// don't just replace a space with an escaped space
|
// don't just replace a space with an escaped space
|
||||||
@@ -42,13 +48,5 @@ function makeSecurePath($path) {
|
|||||||
$path = str_replace("\ ", " ", $path);
|
$path = str_replace("\ ", " ", $path);
|
||||||
$path = str_replace(" ", "\ ", $path);
|
$path = str_replace(" ", "\ ", $path);
|
||||||
|
|
||||||
// check for bad characters, some are allowed with escaping
|
|
||||||
// but we generally don't want them in our directory-names,
|
|
||||||
// thx to aaronmueller for this snipped
|
|
||||||
$badchars = array(':', ';', '|', '&', '>', '<', '`', '$', '~', '?');
|
|
||||||
foreach ($badchars as $bc) {
|
|
||||||
$path = str_replace($bc, "", $path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user