diff --git a/lib/filelib.php b/lib/filelib.php index 20378198cc6..6a430e02796 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -2499,6 +2499,9 @@ function file_safe_save_content($content, $destination) { * @param array $options An array of options, currently accepts: * - (string) cacheability: public, or private. * - (string|null) immutable + * - (bool) dontforcesvgdownload: true if force download should be disabled on SVGs. + * Note: This overrides a security feature, so should only be applied to "trusted" content + * (eg module content that is created using an XSS risk flagged capability, such as SCORM). * @return null script execution stopped unless $dontdie is true */ function send_file($path, $filename, $lifetime = null , $filter=0, $pathisstring=false, $forcedownload=false, $mimetype='', @@ -2529,8 +2532,9 @@ function send_file($path, $filename, $lifetime = null , $filter=0, $pathisstring $filename = rawurlencode($filename); } - // Make sure we force download of SVG files for security reasons (https://digi.ninja/blog/svg_xss.php). - if (file_is_svg_image_from_mimetype($mimetype)) { + // Make sure we force download of SVG files, unless the module explicitly allows them (eg within SCORM content). + // This is for security reasons (https://digi.ninja/blog/svg_xss.php). + if (file_is_svg_image_from_mimetype($mimetype) && empty($options['dontforcesvgdownload'])) { $forcedownload = true; } diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 311f9226db0..583be381d2b 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -1,6 +1,12 @@ This files describes API changes in core libraries and APIs, information provided here is intended especially for developers. +=== 3.10.8 === +* A new option dontforcesvgdownload has been added to the $options parameter of the send_file() function. + Note: This option overrides the forced download of directly accessed SVGs, so should only be used where the calling method is + rendering SVGs directly for content created using XSS risk flagged capabilities (such as creating a SCORM activity). + This is also not necessary where SVGs are already being safely loaded into tags by Moodle (eg within forum posts). + === 3.10.7 === * The signature of the get_name() function for grade_category and grade_item has been extended. The new parameter allows callers to get the name without escaped characters. diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 2b6160d5a98..0e0fb3469ba 100644 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -1008,6 +1008,9 @@ function scorm_pluginfile($course, $cm, $context, $filearea, $args, $forcedownlo return false; } + // Allow SVG files to be loaded within SCORM content, instead of forcing download. + $options['dontforcesvgdownload'] = true; + // Finally send the file. send_stored_file($file, $lifetime, 0, false, $options); }