Skip to content

Commit 640ba55

Browse files
committed
Security: Prevents not allowed wrapper issue when loading images
See: - mpdf/mpdf#949 - https://github.com/mpdf/mpdf/pull/950/files
1 parent ab5ce13 commit 640ba55

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

main/inc/lib/api.lib.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10197,3 +10197,22 @@ function api_protect_webservices()
1019710197
exit;
1019810198
}
1019910199
}
10200+
10201+
function api_filename_has_blacklisted_stream_wrapper(string $filename) {
10202+
if (strpos($filename, '://') > 0) {
10203+
$wrappers = stream_get_wrappers();
10204+
$allowedWrappers = ['http', 'https', 'file'];
10205+
10206+
foreach ($wrappers as $wrapper) {
10207+
if (in_array($wrapper, $allowedWrappers)) {
10208+
continue;
10209+
}
10210+
10211+
if (stripos($filename, $wrapper . '://') === 0) {
10212+
return true;
10213+
}
10214+
}
10215+
}
10216+
10217+
return false;
10218+
}

main/inc/lib/pdf.lib.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,11 +973,25 @@ private static function fixImagesPaths($documentHtml, array $courseInfo, $dirNam
973973

974974
$documentPath = $courseInfo ? $sysCoursePath.$courseInfo['path'].'/document/' : '';
975975

976+
$notFoundImagePath = Display::return_icon(
977+
'closed-circle.png',
978+
get_lang('FileNotFound'),
979+
[],
980+
ICON_SIZE_TINY,
981+
false,
982+
true
983+
);
984+
976985
/** @var \DOMElement $element */
977986
foreach ($elements as $element) {
978987
$src = $element->getAttribute('src');
979988
$src = trim($src);
980989

990+
if (api_filename_has_blacklisted_stream_wrapper($src)) {
991+
$element->setAttribute('src', $notFoundImagePath);
992+
continue;
993+
}
994+
981995
if (strpos($src, $protocol) !== false) {
982996
continue;
983997
}

0 commit comments

Comments
 (0)