]> BookStack Code Mirror - bookstack/commitdiff
Widened svg content attribute xss filtering
authorDan Brown <redacted>
Tue, 6 Sep 2022 16:01:56 +0000 (17:01 +0100)
committerDan Brown <redacted>
Tue, 6 Sep 2022 16:01:56 +0000 (17:01 +0100)
Takes care of additional cases that can occur.
Closes #3705

app/Util/HtmlContentFilter.php
tests/Entity/PageContentTest.php

index 182f6e63529a3e283330b39a6fd35203eccbedef..5e3c4822c2e16a43c48da4c6f8a0edcbcf618746 100644 (file)
@@ -45,10 +45,11 @@ class HtmlContentFilter
         $badIframes = $xPath->query('//*[' . static::xpathContains('@src', 'data:') . '] | //*[' . static::xpathContains('@src', 'javascript:') . '] | //*[@srcdoc]');
         static::removeNodes($badIframes);
 
-        // Remove tags hiding JavaScript or data uris in values attribute.
+        // Remove attributes, within svg children, hiding JavaScript or data uris.
+        // A bunch of svg element and attribute combinations expose xss possibilities.
         // For example, SVG animate tag can exploit javascript in values.
-        $badValuesTags = $xPath->query('//*[' . static::xpathContains('@values', 'data:') . '] | //*[' . static::xpathContains('@values', 'javascript:') . ']');
-        static::removeNodes($badValuesTags);
+        $badValuesAttrs = $xPath->query('//svg//@*[' . static::xpathContains('.', 'data:') . '] | //svg//@*[' . static::xpathContains('.', 'javascript:') . ']');
+        static::removeAttributes($badValuesAttrs);
 
         // Remove elements with a xlink:href attribute
         // Used in SVG but deprecated anyway, so we'll be a bit more heavy-handed here.
index f88e4d513f02d5ce9f188025834b8387551b97ef..1c0519586306c1eae66f0f0ee8cfc6b390cfd2f5 100644 (file)
@@ -333,6 +333,9 @@ class PageContentTest extends TestCase
             '<svg><animate href=#xss attributeName=href values=javascript:alert(1) /></svg>',
             '<svg><animate href="#xss" attributeName="href" values="a;javascript:alert(1)" /></svg>',
             '<svg><animate href="#xss" attributeName="href" values="a;data:alert(1)" /></svg>',
+            '<svg><animate href=#xss attributeName=href from=javascript:alert(1) to=1 /><a id=xss><text x=20 y=20>XSS</text></a>',
+            '<svg><set href=#xss attributeName=href from=? to=javascript:alert(1) /><a id=xss><text x=20 y=20>XSS</text></a>',
+            '<svg><g><g><g><animate href=#xss attributeName=href values=javascript:alert(1) /></g></g></g></svg>',
         ];
 
         $this->asEditor();