Skip to content

Commit 415677f

Browse files
committed
fix: do not allow "image/svg+xml" in data URIs
1 parent 84ca20c commit 415677f

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/loofah/html5/safelist.rb

-1
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,6 @@ module SafeList
999999
"image/gif",
10001000
"image/jpeg",
10011001
"image/png",
1002-
"image/svg+xml",
10031002
"text/css",
10041003
"text/plain",
10051004
])

test/html5/test_sanitizer.rb

+11-3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_should_allow_contenteditable
155155
end
156156
end
157157

158-
HTML5::SafeList::ALLOWED_URI_DATA_MEDIATYPES.each do |data_uri_type|
158+
["image/gif", "image/jpeg", "image/png", "text/css", "text/plain"].each do |data_uri_type|
159159
define_method "test_should_allow_data_#{data_uri_type}_uris" do
160160
input = %(<a href="data:#{data_uri_type}">foo</a>)
161161
output = "<a href='data:#{data_uri_type}'>foo</a>"
@@ -165,9 +165,7 @@ def test_should_allow_contenteditable
165165
output = "<a href='data:#{data_uri_type};base64,R0lGODlhAQABA'>foo</a>"
166166
check_sanitization(input, output, output, output)
167167
end
168-
end
169168

170-
HTML5::SafeList::ALLOWED_URI_DATA_MEDIATYPES.each do |data_uri_type|
171169
define_method "test_should_allow_uppercase_data_#{data_uri_type}_uris" do
172170
input = %(<a href="DATA:#{data_uri_type.upcase}">foo</a>)
173171
output = "<a href='DATA:#{data_uri_type.upcase}'>foo</a>"
@@ -187,6 +185,16 @@ def test_should_disallow_other_uri_mediatypes
187185
input = %(<a href="data:image/xxx;base64,R0lGODlhAQABA">foo</a>)
188186
output = "<a>foo</a>"
189187
check_sanitization(input, output, output, output)
188+
189+
input = %(<a href="data:text/html;base64,R0lGODlhAQABA">foo</a>)
190+
output = "<a>foo</a>"
191+
check_sanitization(input, output, output, output)
192+
193+
# https://hackerone.com/bugs?report_id=1694173
194+
# https://github.com/w3c/svgwg/issues/266
195+
input = %(<svg><use href="data:image/svg+xml;base64,PHN2ZyBpZD0neCcgeG1s"/></svg>)
196+
output = "<svg><use></use></svg>"
197+
check_sanitization(input, output, output, output)
190198
end
191199

192200
HTML5::SafeList::SVG_ALLOW_LOCAL_HREF.each do |tag_name|

0 commit comments

Comments
 (0)