Skip to content

Commit

Permalink
fixing strip tags vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Aug 16, 2011
1 parent 6b46d65 commit 60f783d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Expand Up @@ -162,7 +162,7 @@ def parse(parent, line, pos, content, strict=true)
end

closing = ( scanner.scan(/\//) ? :close : nil )
return Text.new(parent, line, pos, content) unless name = scanner.scan(/[-:\w\x00-\x09\x0b-\x0c\x0e-\x1f]+/)
return Text.new(parent, line, pos, content) unless name = scanner.scan(/[^\s!>\/]+/)
name.downcase!

unless closing
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/controller/html-scanner/sanitizer_test.rb
Expand Up @@ -5,6 +5,13 @@ def setup
@sanitizer = nil # used by assert_sanitizer
end

def test_strip_tags_with_quote
sanitizer = HTML::FullSanitizer.new
string = '<" <img src="trollface.gif" onload="alert(1)"> hi'

assert_equal ' hi', sanitizer.sanitize(string)
end

def test_strip_tags
sanitizer = HTML::FullSanitizer.new
assert_equal("<<<bad html", sanitizer.sanitize("<<<bad html"))
Expand Down

0 comments on commit 60f783d

Please sign in to comment.