Skip to content

Commit

Permalink
Widened svg content attribute xss filtering
Browse files Browse the repository at this point in the history
Takes care of additional cases that can occur.
Closes #3705
  • Loading branch information
ssddanbrown committed Sep 6, 2022
1 parent 24f8274 commit 6955b2f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/Util/HtmlContentFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ public static function removeScripts(string $html): string
$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.
Expand Down
3 changes: 3 additions & 0 deletions tests/Entity/PageContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ public function test_svg_script_usage_is_removed()
'<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();
Expand Down

0 comments on commit 6955b2f

Please sign in to comment.