mirror of
https://github.com/github/rails.git
synced 2026-01-09 14:48:01 -05:00
fix protocol checking in sanitization [CVE-2013-1857]
Conflicts: actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb
This commit is contained in:
@@ -66,7 +66,7 @@ module HTML
|
||||
|
||||
# A regular expression of the valid characters used to separate protocols like
|
||||
# the ':' in 'http://foo.com'
|
||||
self.protocol_separator = /:|(�*58)|(p)|(%|%)3A/
|
||||
self.protocol_separator = /:|(�*58)|(p)|(�*3a)|(%|%)3A/i
|
||||
|
||||
# Specifies a Set of HTML attributes that can have URIs.
|
||||
self.uri_attributes = Set.new(%w(href src cite action longdesc xlink:href lowsrc))
|
||||
@@ -171,7 +171,7 @@ module HTML
|
||||
|
||||
def contains_bad_protocols?(attr_name, value)
|
||||
uri_attributes.include?(attr_name) &&
|
||||
(value =~ /(^[^\/:]*):|(�*58)|(p)|(%|%)3A/ && !allowed_protocols.include?(value.split(protocol_separator).first.downcase))
|
||||
(value =~ /(^[^\/:]*):|(�*58)|(p)|(�*3a)|(%|%)3A/i && !allowed_protocols.include?(value.split(protocol_separator).first.downcase.strip))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -176,6 +176,7 @@ class SanitizerTest < ActionController::TestCase
|
||||
%(<IMG SRC="jav
ascript:alert('XSS');">),
|
||||
%(<IMG SRC="jav
ascript:alert('XSS');">),
|
||||
%(<IMG SRC="  javascript:alert('XSS');">),
|
||||
%(<IMG SRC="javascript:alert('XSS');">),
|
||||
%(<IMG SRC=`javascript:alert("RSnake says, 'XSS'")`>)].each_with_index do |img_hack, i|
|
||||
define_method "test_should_not_fall_for_xss_image_hack_#{i+1}" do
|
||||
assert_sanitized img_hack, "<img>"
|
||||
@@ -281,6 +282,15 @@ class SanitizerTest < ActionController::TestCase
|
||||
assert_sanitized "<span class=\"\\", "<span class=\"\\\">"
|
||||
end
|
||||
|
||||
def test_x03a
|
||||
assert_sanitized %(<a href="javascript:alert('XSS');">), "<a>"
|
||||
assert_sanitized %(<a href="javascript:alert('XSS');">), "<a>"
|
||||
assert_sanitized %(<a href="http://legit">), %(<a href="http://legit">)
|
||||
assert_sanitized %(<a href="javascript:alert('XSS');">), "<a>"
|
||||
assert_sanitized %(<a href="javascript:alert('XSS');">), "<a>"
|
||||
assert_sanitized %(<a href="http://legit">), %(<a href="http://legit">)
|
||||
end
|
||||
|
||||
protected
|
||||
def assert_sanitized(input, expected = nil)
|
||||
@sanitizer ||= HTML::WhiteListSanitizer.new
|
||||
|
||||
Reference in New Issue
Block a user