@@ -188,14 +188,32 @@ def test_dont_remove_whitespace_between_tags
188
188
end
189
189
end
190
190
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
+
197
202
sanitized = Loofah . scrub_fragment ( html , :escape )
198
203
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" ]
199
217
end
200
218
end
201
219
end
0 commit comments