Skip to content

Commit

Permalink
Merge branch '127-nested-script-tags'
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Nov 13, 2017
2 parents ef01eb5 + 3f21dcd commit daf854a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/loofah/scrubbers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ def initialize

def scrub(node)
return CONTINUE if html5lib_sanitize(node) == CONTINUE
node.before node.children
if node.children.length == 1 && node.children.first.cdata?
sanitized_text = Loofah.fragment(node.children.first.to_html).scrub!(:strip).to_html
node.before Nokogiri::XML::Text.new(sanitized_text, node.document)
else
node.before node.children
end
node.remove
end
end
Expand Down
14 changes: 14 additions & 0 deletions test/integration/test_ad_hoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ def test_return_empty_string_when_nothing_left
assert_equal "", Loofah.scrub_document('<script>test</script>', :prune).text
end

def test_nested_script_cdata_tags_should_be_scrubbed
html = "<script><script src='malicious.js'></script>"
stripped = Loofah.fragment(html).scrub!(:strip)
assert_empty stripped.xpath("//script")
refute_match("<script", stripped.to_html)
end

def test_nested_script_cdata_tags_should_be_scrubbed_2
html = "<script><script>alert('a');</script></script>"
stripped = Loofah.fragment(html).scrub!(:strip)
assert_empty stripped.xpath("//script")
refute_match("<script", stripped.to_html)
end

def test_removal_of_all_tags
html = <<-HTML
What's up <strong>doc</strong>?
Expand Down

0 comments on commit daf854a

Please sign in to comment.