MDL-72316 filelib: Add ability for modules to directly load SVG images
This also implements the functionality for SCORM packages, which may have SVG images embedded within their content which require loading directly (and are only created by users with appropriate risk flag).
This commit is contained in:
+6
-2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <img> 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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user