]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Improve name validation checks on local File references
authorBrion Vibber <brion@pobox.com>
Mon, 1 Feb 2010 16:48:31 +0000 (08:48 -0800)
committerBrion Vibber <brion@pobox.com>
Mon, 1 Feb 2010 16:48:31 +0000 (08:48 -0800)
actions/getfile.php
classes/File.php

index cd327e41007e43b25fd26db97c25d26145e040f5..9cbe8e1d993526cb2c1690c540e31efc40d99254 100644 (file)
@@ -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);
         }
 
index 34e4632a8c2760d12e9fc876437db256caf4a1b4..8d91ce50094222117edad8913ac4a1190e0a26c7 100644 (file)
@@ -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',