Skip to content

Commit 0c6617a

Browse files
committed
mitigate XSS vulnerability in SVG animate attributes
this addresses CVE-2019-15587 see #171 for more information #171
1 parent a5bd819 commit 0c6617a

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

lib/loofah/html5/safelist.rb

-3
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ module SafeList
360360
"baseProfile",
361361
"bbox",
362362
"begin",
363-
"by",
364363
"calcMode",
365364
"cap-height",
366365
"class",
@@ -467,7 +466,6 @@ module SafeList
467466
"systemLanguage",
468467
"target",
469468
"text-anchor",
470-
"to",
471469
"transform",
472470
"type",
473471
"u1",
@@ -477,7 +475,6 @@ module SafeList
477475
"unicode",
478476
"unicode-range",
479477
"units-per-em",
480-
"values",
481478
"version",
482479
"viewBox",
483480
"visibility",

test/integration/test_ad_hoc.rb

+24-6
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,32 @@ def test_dont_remove_whitespace_between_tags
188188
end
189189
end
190190

191-
# see:
192-
# - https://github.com/flavorjones/loofah/issues/154
193-
# - https://hackerone.com/reports/429267
194-
context "xss protection from svg xmlns:xlink animate attribute" do
195-
it "sanitizes appropriate attributes" do
196-
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>}
191+
context "xss protection from svg animate attributes" do
192+
# see recommendation from https://html5sec.org/#137
193+
# to sanitize "to", "from", "values", and "by" attributes
194+
195+
it "sanitizes 'from', 'to', and 'by' attributes" do
196+
# for CVE-2018-16468
197+
# see:
198+
# - https://github.com/flavorjones/loofah/issues/154
199+
# - https://hackerone.com/reports/429267
200+
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>}
201+
197202
sanitized = Loofah.scrub_fragment(html, :escape)
198203
assert_nil sanitized.at_css("animate")["from"]
204+
assert_nil sanitized.at_css("animate")["to"]
205+
assert_nil sanitized.at_css("animate")["by"]
206+
end
207+
208+
it "sanitizes 'values' attribute" do
209+
# for CVE-2019-15587
210+
# see:
211+
# - https://github.com/flavorjones/loofah/issues/171
212+
# - https://hackerone.com/reports/709009
213+
html = %Q{<svg> <animate href="#foo" attributeName="href" values="javascript:alert('xss')"/> <a id="foo"> <circle r=400 /> </a> </svg>}
214+
215+
sanitized = Loofah.scrub_fragment(html, :escape)
216+
assert_nil sanitized.at_css("animate")["values"]
199217
end
200218
end
201219
end

0 commit comments

Comments
 (0)