浏览代码

Sanitize user-supplied attachment filename [CVE-2018-8741]

pdontthink 7 年之前
父节点
当前提交
c2e0b060df
共有 2 个文件被更改,包括 20 次插入2 次删除
  1. 1 0
      doc/ChangeLog
  2. 19 2
      src/compose.php

+ 1 - 0
doc/ChangeLog

@@ -417,6 +417,7 @@ Version 1.5.2 - SVN
     as replied or forwarded when the draft is finally sent
   - Added option to allow returning to the message one had been
     replying to after sending 
+  - Sanitize user-supplied attachment filenames [CVE-2017-7692]
 
 Version 1.5.1 (branched on 2006-02-12)
 --------------------------------------

+ 19 - 2
src/compose.php

@@ -405,8 +405,25 @@ if (!empty($compose_messages[$session])) {
 // should never directly manipulate an object like this
 if (!empty($attachments)) {
     $attachments = unserialize(urldecode($attachments));
-    if (!empty($attachments) && is_array($attachments))
-        $composeMessage->entities = $attachments;
+    if (!empty($attachments) && is_array($attachments)) {
+        // sanitize the "att_local_name" since it is user-supplied and used to access the file system
+        // it must be alpha-numeric and 32 characters long (see the use of GenerateRandomString() below)
+        foreach ($attachments as $i => $attachment) {
+            if (empty($attachment->att_local_name) || strlen($attachment->att_local_name) !== 32) {
+                unset($attachments[$i]);
+                continue;
+            }
+            // probably marginal difference between (ctype_alnum + function_exists) and preg_match
+            if (function_exists('ctype_alnum')) {
+                if (!ctype_alnum($attachment->att_local_name))
+                    unset($attachments[$i]);
+            }
+            else if (preg_match('/[^0-9a-zA-Z]/', $attachment->att_local_name))
+                unset($attachments[$i]);
+        }
+        if (!empty($attachments))
+            $composeMessage->entities = $attachments;
+    }
 }
 
 if (empty($mailbox)) {