Merge pull request #278 from hph86/prevent_dir_traversal_in_paths

prevent directory traversal in paths
This commit is contained in:
Michael Kaufmann
2016-01-29 07:43:22 +01:00

View File

@@ -26,15 +26,21 @@
*/
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(
'#/+#',
'#\.+#',
'#\0+#'
'#\.+#'
);
$replace = array(
'/',
'.',
''
'.'
);
$path = preg_replace($search, $replace, $path);
// 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);
// 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;
}