File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -146,9 +146,11 @@ def scrub_attribute(node, attr_node)
146146 attr_node . remove
147147 end
148148 end
149+
149150 if Loofah ::HTML5 ::SafeList ::SVG_ATTR_VAL_ALLOWS_REF . include? ( attr_name )
150- attr_node . value = attr_node . value . gsub ( /url \s * \( \s *[^# \s ][^)]+? \) /m , ' ' ) if attr_node . value
151+ Loofah :: HTML5 :: Scrub . scrub_attribute_that_allows_local_ref ( attr_node )
151152 end
153+
152154 if Loofah ::HTML5 ::SafeList ::SVG_ALLOW_LOCAL_HREF . include? ( node . name ) && attr_name == 'xlink:href' && attr_node . value =~ /^\s *[^#\s ].*/m
153155 attr_node . remove
154156 end
Original file line number Diff line number Diff line change @@ -606,6 +606,16 @@ def test_disallow_the_dangerous_safelist_combination_of_select_and_style
606606 refute_includes ( sanitized , "style" )
607607 end
608608
609+ def test_scrubbing_svg_attr_values_that_allow_ref
610+ input = %Q(<div fill="yellow url(http://bad.com/) #fff">hey</div>)
611+ expected = %Q(<div fill="yellow #fff">hey</div>)
612+ actual = scope_allowed_attributes %w( fill ) do
613+ safe_list_sanitize ( input )
614+ end
615+
616+ assert_equal ( expected , actual )
617+ end
618+
609619protected
610620
611621 def xpath_sanitize ( input , options = { } )
You can’t perform that action at this time.
0 commit comments