diff --git a/includes/file.inc b/includes/file.inc index df7e3da..e2cdb1b 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -222,6 +222,9 @@ function file_check_path(&$path) { * @return 0 for invalid path or the real path of the source. */ function file_check_location($source, $directory = '') { + $org_source = $source; // These are the original paths (non-real) + $org_directory = $directory; + $check = realpath($source); if ($check) { $source = $check; @@ -231,8 +234,11 @@ function file_check_location($source, $directory = '') { $source = realpath(dirname($source)) .'/'. basename($source); } $directory = realpath($directory); + if ($directory && strpos($source, $directory) !== 0) { - return 0; + // Not a direct mapping...but lets allow for non-traversed paths to destination directory + $traversal = preg_match('@(\.\.|~)@', $org_source); + if($traversal || strpos($org_source,$org_directory) !==0) return 0; } return $source; }