mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
fix incorrect ^$ usage leading to XSS in sanitize_css [CVE-2013-1855]
This commit is contained in:
parent
5dc2e3531b
commit
8be6913990
2 changed files with 8 additions and 3 deletions
|
@ -121,8 +121,8 @@ module HTML
|
|||
style = style.to_s.gsub(/url\s*\(\s*[^\s)]+?\s*\)\s*/, ' ')
|
||||
|
||||
# gauntlet
|
||||
if style !~ /^([:,;#%.\sa-zA-Z0-9!]|\w-\w|\'[\s\w]+\'|\"[\s\w]+\"|\([\d,\s]+\))*$/ ||
|
||||
style !~ /^(\s*[-\w]+\s*:\s*[^:;]*(;|$)\s*)*$/
|
||||
if style !~ /\A([:,;#%.\sa-zA-Z0-9!]|\w-\w|\'[\s\w]+\'|\"[\s\w]+\"|\([\d,\s]+\))*\z/ ||
|
||||
style !~ /\A(\s*[-\w]+\s*:\s*[^:;]*(;|$)\s*)*\z/
|
||||
return ''
|
||||
end
|
||||
|
||||
|
@ -133,7 +133,7 @@ module HTML
|
|||
elsif shorthand_css_properties.include?(prop.split('-')[0].downcase)
|
||||
unless val.split().any? do |keyword|
|
||||
!allowed_css_keywords.include?(keyword) &&
|
||||
keyword !~ /^(#[0-9a-f]+|rgb\(\d+%?,\d*%?,?\d*%?\)?|\d{0,2}\.?\d{0,2}(cm|em|ex|in|mm|pc|pt|px|%|,|\))?)$/
|
||||
keyword !~ /\A(#[0-9a-f]+|rgb\(\d+%?,\d*%?,?\d*%?\)?|\d{0,2}\.?\d{0,2}(cm|em|ex|in|mm|pc|pt|px|%|,|\))?)\z/
|
||||
end
|
||||
clean << prop + ': ' + val + ';'
|
||||
end
|
||||
|
|
|
@ -279,6 +279,11 @@ class SanitizerTest < ActionController::TestCase
|
|||
assert_equal '', sanitize_css(raw)
|
||||
end
|
||||
|
||||
def test_should_sanitize_across_newlines
|
||||
raw = %(\nwidth:\nexpression(alert('XSS'));\n)
|
||||
assert_equal '', sanitize_css(raw)
|
||||
end
|
||||
|
||||
def test_should_sanitize_img_vbscript
|
||||
assert_sanitized %(<img src='vbscript:msgbox("XSS")' />), '<img />'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue