51 private const SVG =
'svg';
136 ?
string $rejection_message =
null,
137 ?
string $additional_message_script =
null,
138 ?
string $additional_message_base64 =
null,
139 ?
string $additional_message_elements =
null,
142 $this->rejection_message_script = $additional_message_script ??
'contains script tags';
143 $this->rejection_message_base64 = $additional_message_base64 ??
'contains base64 encoded content';
144 $this->rejection_message_elements = $additional_message_elements ??
'contains not allowed or unknown elements or attributes';
149 return $this->isMimeTypeOrExtension(
152 [self::SVG_MIME_TYPE]
166 $dom = new \DOMDocument();
168 $dom->loadXML($raw_svg_content, LIBXML_NOWARNING | LIBXML_NOERROR);
172 $errors = libxml_get_errors();
173 if ($errors !== []) {
181 $raw_svg_content = (string) $stream;
182 if (
false === $raw_svg_content) {
200 $prohibited_attributes = (fn(
string $name):
bool => in_array(strtolower($name), $this->svg_event_lists,
true));
201 return $looper($dom, $prohibited_attributes) !==
false;
207 if (preg_match(self::REGEX_BASE64, $raw_svg_content)) {
213 if (preg_match(self::REGEX_SCRIPT, $raw_svg_content)) {
223 return function (\DOMDocument $dom, \Closure $closure):
bool {
224 $attributes_looper =
function (\DOMNode $node, \Closure $closure) use (&$attributes_looper):
bool {
225 foreach ($node->attributes as $attribute) {
226 if ($closure($attribute->name)) {
227 $this->rejection_message .= sprintf(
228 $this->rejection_message_elements .
' (%s)',
234 foreach ($node->childNodes as $child) {
235 if ($child instanceof \DOMElement && !$attributes_looper($child, $closure)) {
241 foreach ($dom->getElementsByTagName(
"*") as $i => $element) {
242 if ($attributes_looper($element, $closure) ===
false) {
string $rejection_message_base64
string $rejection_message_script
string $rejection_message_elements
Class SVGBlacklistPreProcessor.
process(FileStream $stream, Metadata $metadata)
This method gets invoked by the file upload service to process the file with the help of the processo...
checkStream(FileStream $stream)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
hasContentScriptTag(string $raw_svg_content)
isSVG(Metadata $metadata)
getDomDocument(string $raw_svg_content)
__construct(?string $rejection_message=null, ?string $additional_message_script=null, ?string $additional_message_base64=null, ?string $additional_message_elements=null,)
string $rejection_message