MDL-33741 file_info: check capability when serving file in coursecat description
authorMarina Glancy <marina@moodle.com>
Fri, 19 Jul 2013 07:02:33 +0000 (17:02 +1000)
committerMarina Glancy <marina@moodle.com>
Mon, 1 Aug 2016 01:12:18 +0000 (09:12 +0800)
lib/filelib.php

index 6bd5a85..e23467a 100644 (file)
@@ -4182,6 +4182,14 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) {
                 require_login();
             }
 
+            // Check if user can view this category.
+            if (!has_capability('moodle/category:viewhiddencategories', $context)) {
+                $coursecatvisible = $DB->get_field('course_categories', 'visible', array('id' => $context->instanceid));
+                if (!$coursecatvisible) {
+                    send_file_not_found();
+                }
+            }
+
             $filename = array_pop($args);
             $filepath = $args ? '/'.implode('/', $args).'/' : '/';
             if (!$file = $fs->get_file($context->id, 'coursecat', 'description', 0, $filepath, $filename) or $file->is_directory()) {