Skip to content

Commit d48c647

Browse files
kergomardfwolf-ilias
authored andcommitted
FileUpload: Prohibit Inclusion of Foreign Objects
Signed-off-by: Releasemanager <webmaster@ilias.de>
1 parent 9b92451 commit d48c647

5 files changed

Lines changed: 17 additions & 4 deletions

File tree

components/ILIAS/FileUpload/src/Processor/SVGBlacklistPreProcessor.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ final class SVGBlacklistPreProcessor implements PreProcessor
3535

3636
private const SVG_MIME_TYPE = 'image/svg+xml';
3737
private const REGEX_SCRIPT = '/<script/m';
38+
private const REGEX_FOREIGN_OBJECT = '/<foreignObject/m';
3839
private const REGEX_BASE64 = '/data:.*;base64/m';
3940
private const SVG = 'svg';
4041
private string $rejection_message = 'The SVG file contains possibily malicious code.';
4142
private string $rejection_message_script;
4243
private string $rejection_message_base64;
44+
private string $rejection_message_foreign_object;
4345
private string $rejection_message_elements;
4446
private string $ok_message = 'SVG OK';
4547
/**
@@ -124,11 +126,13 @@ public function __construct(
124126
?string $rejection_message = null,
125127
?string $additional_message_script = null,
126128
?string $additional_message_base64 = null,
127-
?string $additional_message_elements = null,
129+
?string $additional_message_foreign_object = null,
130+
?string $additional_message_elements = null
128131
) {
129132
$this->rejection_message = $rejection_message ?? $this->rejection_message;
130133
$this->rejection_message_script = $additional_message_script ?? 'contains script tags';
131134
$this->rejection_message_base64 = $additional_message_base64 ?? 'contains base64 encoded content';
135+
$this->rejection_message_foreign_object = $additional_message_foreign_object ?? 'contains foreign object';
132136
$this->rejection_message_elements = $additional_message_elements ?? 'contains not allowed or unknown elements or attributes';
133137
}
134138

@@ -209,6 +213,12 @@ private function hasContentScriptTag(string $raw_svg_content): bool
209213
return true;
210214
}
211215

216+
// Check for script tags directly
217+
if (preg_match(self::REGEX_FOREIGN_OBJECT, $raw_svg_content)) {
218+
$this->rejection_message .= ' ' . $this->rejection_message_foreign_object;
219+
return true;
220+
}
221+
212222
return false;
213223
}
214224

@@ -227,7 +237,7 @@ protected function getDOMAttributesLooper(): \Closure
227237
}
228238
foreach ($node->childNodes as $child) {
229239
if ($child instanceof \DOMElement) {
230-
if(!$attributes_looper($child, $closure)) {
240+
if (!$attributes_looper($child, $closure)) {
231241
return false;
232242
}
233243
}

components/ILIAS/FileUpload/tests/Processor/SVGPreProcessorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function getPreProcessor(): SVGBlacklistPreProcessor
3939
'The SVG file contains malicious code.',
4040
'(script)',
4141
'(base64)',
42-
''
42+
'(foreignObject)',
4343
);
4444
}
4545

@@ -60,7 +60,7 @@ public static function maliciousSVGProvider(): array
6060
6161
</foreignObject>
6262
</svg>',
63-
'onclick'
63+
'foreignObject'
6464
],
6565
[
6666
'<svg version="1.1" baseProfile="full"

components/ILIAS/Init/classes/class.ilInitialisation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ public static function initFileUploadService(\ILIAS\DI\Container $dic): void
341341
$c->language()->txt("upload_svg_rejection_message"),
342342
$c->language()->txt("upload_svg_rejection_message_script"),
343343
$c->language()->txt("upload_svg_rejection_message_base64"),
344+
$c->language()->txt("upload_svg_rejection_message_foreign_object"),
344345
$c->language()->txt("upload_svg_rejection_message_elements")
345346
));
346347

lang/ilias_de.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5896,6 +5896,7 @@ common#:#upload_settings#:#Upload-Einstellungen
58965896
common#:#upload_svg_rejection_message#:#Eine hochgeladene SVG-Datei enthält möglicherweise bösartigen Code und kann nicht verarbeitet werden.
58975897
common#:#upload_svg_rejection_message_base64#:#Die Datei enthält base64 kodierten Inhalt.
58985898
common#:#upload_svg_rejection_message_elements#:#Die Datei enthält Elemente oder Attribute, die nicht erlaubt oder bekannt sind.
5899+
common#:#upload_svg_rejection_message_foreign_object#:#Die Datei bindet externe Objekte ein.
58995900
common#:#upload_svg_rejection_message_script#:#Die Datei enthält Skript-Elemente.
59005901
common#:#uploaded_and_checked#:#Die Datei wurde hochgeladen und überprüft, Sie können sie nun importieren.
59015902
common#:#uploading#:#Hochladen...

lang/ilias_en.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5897,6 +5897,7 @@ common#:#upload_settings#:#Upload Settings
58975897
common#:#upload_svg_rejection_message#:#An uploaded SVG file contains possibily malicious code and cannot be processed.
58985898
common#:#upload_svg_rejection_message_base64#:#The file contains base64 encoded content.
58995899
common#:#upload_svg_rejection_message_elements#:#The file contains elements or attributes which are not allowed or known.
5900+
common#:#upload_svg_rejection_message_foreign_object#:#The file contains foreign objects.
59005901
common#:#upload_svg_rejection_message_script#:#The file contains script-Elements.
59015902
common#:#uploaded_and_checked#:#The file has been uploaded and checked, you can now start to import it.
59025903
common#:#uploading#:#Uploading...

0 commit comments

Comments
 (0)