Fixed images with relative path / SVG from being proxied
authorAlexander Ebert <ebert@woltlab.com>
Thu, 5 Jan 2017 17:17:21 +0000 (18:17 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 5 Jan 2017 17:17:21 +0000 (18:17 +0100)
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php

index 607e258670a15b1e0c6ca9c3e38bedbe07649e8f..9ee8fb1b67f194c7704c254725a32a5b73b9fc36 100644 (file)
@@ -59,6 +59,25 @@ class HtmlOutputNodeImg extends AbstractHtmlOutputNode {
                                        continue;
                                }
                                
+                               $urlComponents = parse_url($src);
+                               if ($urlComponents === false) {
+                                       // not a valid URL, discard it
+                                       DOMUtil::removeNode($element);
+                                       continue;
+                               }
+                               
+                               if (empty($urlComponents['host'])) {
+                                       // relative URL, ignore it
+                                       continue;
+                               }
+                               
+                               $element->setAttribute('data-valid', 'true');
+                               
+                               if (!empty($urlComponents['path']) && preg_match('~\.svg~', basename($urlComponents['path']))) {
+                                       // we can't proxy SVG, ignore it
+                                       continue;
+                               }
+                               
                                $element->setAttribute('src', $this->getProxyLink($src));
                                
                                $srcset = $element->getAttribute('srcset');