21use PHPUnit\Framework\Attributes\DataProvider;
23require_once(
'./vendor/composer/vendor/autoload.php');
25use PHPUnit\Framework\TestCase;
41 'The SVG file contains malicious code.',
51 '<svg width="100" height="100">
52 <foreignObject width="100%" height="100%">
53 <script>alert(document.domain);</script>
59 '<svg width="100" height="100">
60 <foreignObject width="100%" height="100%" onclick="alert(document.domain);">
67 '<svg version="1.1" baseProfile="full"
68xmlns="http://www.w3.org/2000/svg">
69<rect width="100" height="100" style="fill:rgb(0,0,255);" />
70<script type="text/javascript">
71alert("XSS in SVG on " + document.domain );
77 '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
78<use xlink:href="data:application/xml;base64 ,
79PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5r
80PSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIj4KPGRlZnM+CjxjaXJjbGUgaWQ9InRlc3QiIHI9I
81jUwIiBjeD0iMTAwIiBjeT0iMTAwIiBzdHlsZT0iZmlsbDogI0YwMCI+CjxzZXQgYXR0cmlidXRlTm
82FtZT0iZmlsbCIgYXR0cmlidXRlVHlwZT0iQ1NTIiBvbmJlZ2luPSdhbGVydChkb2N1bWVudC5jb29r
83aWUpJwpvbmVuZD0nYWxlcnQoIm9uZW5kIiknIHRvPSIjMDBGIiBiZWdpbj0iMXMiIGR1cj0iNXMiIC
848+CjwvY2lyY2xlPgo8L2RlZnM+Cjx1c2UgeGxpbms6aHJlZj0iI3Rlc3QiLz4KPC9zdmc+#test"/>
90 #[DataProvider('maliciousSVGProvider')]
95 $metadata =
new Metadata(
'test.svg', 100,
'image/svg+xml');
97 $result = $preProcessor->process($stream, $metadata);
101 $this->assertSame(
'The SVG file contains malicious code. (' . $type .
')', $result->getMessage());
106 $svg =
'<svg version="1.1" baseProfile="full"
107xmlns="http://www.w3.org/2000/svg">
108<rect width="100" height="100" style="fill:rgb(0,0,255);" />
113 $metadata =
new Metadata(
'test.svg', 100,
'image/svg+xml');
115 $result = $preProcessor->process($stream, $metadata);
119 $this->assertSame(
'SVG OK', $result->getMessage());
124 yield [__DIR__ .
'/../../../../../components/ILIAS/UI/resources/images/media/bigplay.svg'];
125 yield [__DIR__ .
'/../../../../../components/ILIAS/UI/resources/images/nav/jstree.svg'];
126 yield [__DIR__ .
'/../../../../../components/ILIAS/UI/resources/images/media/loader.svg'];
127 yield [__DIR__ .
'/../../../../../components/ILIAS/UI/resources/images/object/col.svg'];
128 yield [__DIR__ .
'/../../../../../components/ILIAS/UI/resources/images/logo/HeaderIcon.svg'];
129 yield [__DIR__ .
'/../../../../../components/ILIAS/UI/resources/images/object/answered_not.svg'];
132 #[DataProvider('provideSomeComplexSaneSVG')]
135 $this->assertFileExists(
$path);
136 $svg = file_get_contents(
$path);
140 $metadata =
new Metadata(
'media/bigplay.svg', 100,
'image/svg+xml');
142 $result = $preProcessor->process($stream, $metadata);
144 $this->assertSame(
'SVG OK', $result->getMessage());
Class SVGBlacklistPreProcessor.
Class SVGPreProcessorTest.
static provideSomeComplexSaneSVG()
static maliciousSVGProvider()
testMaliciousSVG(string $malicious_svg, string $type)
testSomeComplexSaneSVG(string $path)
Stream factory which enables the user to create streams without the knowledge of the concrete class.
static ofString(string $string)
Creates a new stream with an initial value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...