39 private const SVG =
'svg';
134 return $this->isMimeTypeOrExtension(
137 [self::SVG_MIME_TYPE]
151 $dom = new \DOMDocument();
153 $dom->loadXML($raw_svg_content, LIBXML_NOWARNING | LIBXML_NOERROR);
166 $raw_svg_content = (string) $stream;
167 if (
false === $raw_svg_content) {
184 $prohibited_attributes =
function (
string $name) :
bool {
185 return in_array(strtolower(
$name), $this->svg_event_lists,
true);
187 if ($looper($dom, $prohibited_attributes) ===
false) {
197 if (preg_match(self::REGEX_BASE64, $raw_svg_content)) {
198 $this->rejection_message = $this->rejection_message
204 if (preg_match(self::REGEX_SCRIPT, $raw_svg_content)) {
205 $this->rejection_message = $this->rejection_message
215 return function (\DOMDocument $dom, \Closure $closure) :
bool {
216 $attributes_looper =
function (\DOMNode $node, \Closure $closure) use (&$attributes_looper) :
bool {
217 foreach ($node->attributes as $attribute) {
218 if ($closure($attribute->name)) {
219 $this->rejection_message = sprintf(
220 'The SVG file contains malicious code. (%s).',
226 foreach ($node->childNodes as $child) {
227 if ($child instanceof \DOMElement) {
228 $attributes_looper($child, $closure);
233 foreach ($dom->getElementsByTagName(
"*") as
$i => $element) {
234 if ($attributes_looper($element, $closure) ===
false) {
process(FileStream $stream, Metadata $metadata)
This method gets invoked by the file upload service to process the file with the help of the processo...
isSVG(Metadata $metadata)
Class SVGBlacklistPreProcessor.
getDomDocument(string $raw_svg_content)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
hasContentScriptTag(string $raw_svg_content)
const DENIED
Upload got denied by a processor, the upload will be removed immediately.
__construct(?string $rejection_message=null)
Interface FileStream The base interface for all filesystem streams.
checkStream(FileStream $stream)