34 use IsMimeTypeOrExtension;
40 private const SVG =
'svg';
127 ?
string $additional_message_script =
null,
128 ?
string $additional_message_base64 =
null,
129 ?
string $additional_message_foreign_object =
null,
130 ?
string $additional_message_elements =
null
133 $this->rejection_message_script = $additional_message_script ??
'contains script tags';
134 $this->rejection_message_base64 = $additional_message_base64 ??
'contains base64 encoded content';
135 $this->rejection_message_foreign_object = $additional_message_foreign_object ??
'contains foreign object';
136 $this->rejection_message_elements = $additional_message_elements ??
'contains not allowed or unknown elements or attributes';
141 return $this->isMimeTypeOrExtension(
144 [self::SVG_MIME_TYPE]
158 $dom = new \DOMDocument();
160 $dom->loadXML($raw_svg_content, LIBXML_NOWARNING | LIBXML_NOERROR);
161 }
catch (\Exception
$e) {
173 $raw_svg_content = (string) $stream;
174 if (
false === $raw_svg_content) {
192 $prohibited_attributes =
function (
string $name):
bool {
193 return in_array(strtolower(
$name), $this->svg_event_lists,
true);
195 if ($looper($dom, $prohibited_attributes) ===
false) {
205 if (preg_match(self::REGEX_BASE64, $raw_svg_content)) {
211 if (preg_match(self::REGEX_SCRIPT, $raw_svg_content)) {
217 if (preg_match(self::REGEX_FOREIGN_OBJECT, $raw_svg_content)) {
227 return function (\DOMDocument $dom, \Closure $closure):
bool {
228 $attributes_looper =
function (\DOMNode $node, \Closure $closure) use (&$attributes_looper):
bool {
229 foreach ($node->attributes as $attribute) {
230 if ($closure($attribute->name)) {
231 $this->rejection_message .= sprintf(
232 $this->rejection_message_elements .
' (%s)',
238 foreach ($node->childNodes as $child) {
239 if ($child instanceof \DOMElement) {
240 if (!$attributes_looper($child, $closure)) {
247 foreach ($dom->getElementsByTagName(
"*") as
$i => $element) {
248 if ($attributes_looper($element, $closure) ===
false) {
const DENIED
Upload got denied by a processor, the upload will be removed immediately.
Class SVGBlacklistPreProcessor.
string $rejection_message
string $rejection_message_elements
checkStream(FileStream $stream)
string $rejection_message_base64
__construct(?string $rejection_message=null, ?string $additional_message_script=null, ?string $additional_message_base64=null, ?string $additional_message_foreign_object=null, ?string $additional_message_elements=null)
string $rejection_message_foreign_object
process(FileStream $stream, Metadata $metadata)
This method gets invoked by the file upload service to process the file with the help of the processo...
getDomDocument(string $raw_svg_content)
const REGEX_FOREIGN_OBJECT
hasContentScriptTag(string $raw_svg_content)
string $rejection_message_script
isSVG(Metadata $metadata)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...