spacepaste

  1.  
  2. --- before_compose.php 2018-03-15 14:46:42.000000000 +0200
  3. +++ after_compose.php 2018-03-15 14:46:38.000000000 +0200
  4. @@ -147,6 +147,62 @@
  5. /* --------------------- Specific Functions ------------------------------ */
  6. +/*
  7. +Validate the user input 'attachments'.
  8. +If the input is ok, don't do anything.
  9. +If the attachment's file name is in an unexpected format, empty the attachments.
  10. +*/
  11. +function validateAttachments() {
  12. +
  13. + global $username, $attachment_dir, $attachments;
  14. +
  15. + // no attachments - nothing to validate
  16. + if (empty($attachments))
  17. + {
  18. + return;
  19. + }
  20. +
  21. + // get the Messages array
  22. + $attach_arr = unserialize($attachments);
  23. +
  24. + if (empty($attach_arr) || !is_array($attach_arr))
  25. + {
  26. + return;
  27. + }
  28. +
  29. + $hashed_attachment_dir = realpath(getHashedDir($username, $attachment_dir));
  30. +
  31. + /*
  32. + For each attachment (of type Message), verify:
  33. + 1. That after calling realpath(), we are in the attachment directory.
  34. + 2. That the file name is 32 characters long (a fixed length used for attachments).
  35. + 3. That the file has no extension.
  36. +
  37. + Notes: The attachment file name is a random 32-long string.
  38. + The attachments directory contains other types of files as well,
  39. + but they either have an exention or are not 32-characters long.
  40. + */
  41. + foreach ($attach_arr as $attach_msg_obj)
  42. + {
  43. + $received_file_name = $attach_msg_obj->att_local_name;
  44. + $full_path = realpath($hashed_attachment_dir . '/' . $received_file_name);
  45. +
  46. + $path_parts = pathinfo($full_path);
  47. + $file_name = $path_parts['basename'];
  48. +
  49. + if ((substr($full_path, 0, strlen($hashed_attachment_dir)) != $hashed_attachment_dir) or
  50. + (strlen($file_name) != 32) or
  51. + ($path_parts['extension'] != ""))
  52. + {
  53. + $attachments = '';
  54. + return;
  55. + }
  56. + }
  57. +
  58. + return;
  59. +}
  60. +
  61. +
  62. function replyAllString($header) {
  63. global $include_self_reply_all, $username, $data_dir;
  64. $excl_ar = array();
  65. @@ -287,6 +343,8 @@
  66. }
  67. /* ----------------------------------------------------------------------- */
  68. +validateAttachments();
  69. +
  70. /*
  71. * If the session is expired during a post this restores the compose session
  72. * vars.
  73. @@ -1745,4 +1803,3 @@
  74. }
  75. return $succes;
  76. }
  77. -
  78.