From: Brion Vibber Date: Mon, 1 Feb 2010 16:48:31 +0000 (-0800) Subject: Improve name validation checks on local File references X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6159edcebbcb1c230113e18788a676035979a4c8;p=quix0rs-gnu-social.git Improve name validation checks on local File references --- diff --git a/actions/getfile.php b/actions/getfile.php index cd327e4100..9cbe8e1d99 100644 --- a/actions/getfile.php +++ b/actions/getfile.php @@ -71,7 +71,7 @@ class GetfileAction extends Action $filename = $this->trimmed('filename'); $path = null; - if ($filename) { + if ($filename && File::validFilename($filename)) { $path = File::path($filename); } diff --git a/classes/File.php b/classes/File.php index c527c4ffe9..6dd9e0c06e 100644 --- a/classes/File.php +++ b/classes/File.php @@ -176,8 +176,22 @@ class File extends Memcached_DataObject return "$nickname-$datestamp-$random.$ext"; } + /** + * Validation for as-saved base filenames + */ + static function validFilename($filename) + { + return preg_match('^/[A-Za-z0-9._-]+$/', $filename); + } + + /** + * @throws ClientException on invalid filename + */ static function path($filename) { + if (!self::validFilename($filename)) { + throw new ClientException("Invalid filename"); + } $dir = common_config('attachments', 'dir'); if ($dir[strlen($dir)-1] != '/') { @@ -189,6 +203,9 @@ class File extends Memcached_DataObject static function url($filename) { + if (!self::validFilename($filename)) { + throw new ClientException("Invalid filename"); + } if(common_config('site','private')) { return common_local_url('getfile',