diff options
author | Brion Vibber <brion@pobox.com> | 2010-02-01 08:48:31 -0800 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2010-02-01 08:48:31 -0800 |
commit | 84ab0156b415a405704784dfc19b59ebd3a1d1ee (patch) | |
tree | 748c6dbd38073e7aaf31fae5b860285512cb1534 /classes | |
parent | 779204b194447397d0770d96e291d9491fd731b9 (diff) |
Improve name validation checks on local File references
Diffstat (limited to 'classes')
-rw-r--r-- | classes/File.php | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/classes/File.php b/classes/File.php index 34e4632a8..8d91ce500 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', |