@@ -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