Skip to content

Commit

Permalink
mitigate XSS vulnerability in SVG animate attributes
Browse files Browse the repository at this point in the history
this addresses CVE-2019-15587

see #171 for more information

#171
  • Loading branch information
flavorjones committed Oct 22, 2019
1 parent a5bd819 commit 0c6617a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
3 changes: 0 additions & 3 deletions lib/loofah/html5/safelist.rb
Expand Up @@ -360,7 +360,6 @@ module SafeList
"baseProfile",
"bbox",
"begin",
"by",
"calcMode",
"cap-height",
"class",
Expand Down Expand Up @@ -467,7 +466,6 @@ module SafeList
"systemLanguage",
"target",
"text-anchor",
"to",
"transform",
"type",
"u1",
Expand All @@ -477,7 +475,6 @@ module SafeList
"unicode",
"unicode-range",
"units-per-em",
"values",
"version",
"viewBox",
"visibility",
Expand Down
30 changes: 24 additions & 6 deletions test/integration/test_ad_hoc.rb
Expand Up @@ -188,14 +188,32 @@ def test_dont_remove_whitespace_between_tags
end
end

# see:
# - https://github.com/flavorjones/loofah/issues/154
# - https://hackerone.com/reports/429267
context "xss protection from svg xmlns:xlink animate attribute" do
it "sanitizes appropriate attributes" do
html = %Q{<svg><a xmlns:xlink=http://www.w3.org/1999/xlink xlink:href=?><circle r=400 /><animate attributeName=xlink:href begin=0 from=javascript:alert(1) to=%26>}
context "xss protection from svg animate attributes" do
# see recommendation from https://html5sec.org/#137
# to sanitize "to", "from", "values", and "by" attributes

it "sanitizes 'from', 'to', and 'by' attributes" do
# for CVE-2018-16468
# see:
# - https://github.com/flavorjones/loofah/issues/154
# - https://hackerone.com/reports/429267
html = %Q{<svg><a xmlns:xlink=http://www.w3.org/1999/xlink xlink:href=?><circle r=400 /><animate attributeName=xlink:href begin=0 from=javascript:alert(1) to=%26 by=5>}

sanitized = Loofah.scrub_fragment(html, :escape)
assert_nil sanitized.at_css("animate")["from"]
assert_nil sanitized.at_css("animate")["to"]
assert_nil sanitized.at_css("animate")["by"]
end

it "sanitizes 'values' attribute" do
# for CVE-2019-15587
# see:
# - https://github.com/flavorjones/loofah/issues/171
# - https://hackerone.com/reports/709009
html = %Q{<svg> <animate href="#foo" attributeName="href" values="javascript:alert('xss')"/> <a id="foo"> <circle r=400 /> </a> </svg>}

sanitized = Loofah.scrub_fragment(html, :escape)
assert_nil sanitized.at_css("animate")["values"]
end
end
end
Expand Down

0 comments on commit 0c6617a

Please sign in to comment.