Skip to content

Commit 5b9a68b

Browse files
committed
Security: Filter SVG files uploaded from social network
See advisory GHSA-2vq2-826h-6hp6
1 parent 8c74517 commit 5b9a68b

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

main/inc/lib/document.lib.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/* For licensing terms, see /license.txt */
44

55
use ChamiloSession as Session;
6+
use enshrined\svgSanitize\Sanitizer;
67

78
/**
89
* Class DocumentManager
@@ -486,6 +487,13 @@ public static function file_send_for_download(
486487
}
487488
echo $content;
488489
} else {
490+
if ('image/svg+xml' === $contentType) {
491+
$svgContent = file_get_contents($full_file_name);
492+
493+
echo (new Sanitizer())->sanitize($svgContent);
494+
return true;
495+
}
496+
489497
if (isset($enableMathJaxScript) && $enableMathJaxScript === true) {
490498
$content = file_get_contents($full_file_name);
491499
$content = self::includeMathJaxScript($content);

main/inc/lib/message.lib.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,10 @@ public static function saveMessageAttachmentFile(
10971097
$fileCopied = true;
10981098
}
10991099
}
1100+
1101+
if ('image/svg+xml' === $type) {
1102+
sanitizeSvgFile($new_path);
1103+
}
11001104
}
11011105

11021106
if ($fileCopied) {

main/social/download.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*
1010
* @package chamilo.messages
1111
*/
12+
13+
use Symfony\Component\HttpFoundation\Request as HttpRequest;
14+
1215
session_cache_limiter('public');
1316

1417
require_once __DIR__.'/../inc/global.inc.php';
@@ -20,8 +23,10 @@
2023
header('Cache-Control: public');
2124
header('Pragma: no-cache');
2225

23-
$messageId = isset($_GET['message_id']) ? $_GET['message_id'] : 0;
24-
$attachmentId = isset($_GET['attachment_id']) ? $_GET['attachment_id'] : 0;
26+
$httpRequest = HttpRequest::createFromGlobals();
27+
28+
$messageId = $httpRequest->query->getInt('message_id');
29+
$attachmentId = $httpRequest->query->getInt('attachment_id');
2530

2631
$messageInfo = MessageManager::get_message_by_id($messageId);
2732
$attachmentInfo = MessageManager::getAttachment($attachmentId);

0 commit comments

Comments
 (0)