Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8222: sanitize_ie_for_edge_cases.diff

File sanitize_ie_for_edge_cases.diff, 2.4 kB (added by wycats, 1 year ago)
  • actionpack/test/template/text_helper_test.rb

    old new  
    279279    assert_equal %{src="javascript:bang" <img width="5">foo</img>, <span>bar</span>}, result 
    280280  end 
    281281   
     282  def test_sanitize_behavior 
     283    raw = %{style="behavior: url(foo.htc)" <div style="behavior: url(foo.htc)">foo</div>} 
     284    result = sanitize(raw) 
     285    assert_equal %{style="behavior: url(foo.htc)" <div>foo</div>}, result 
     286    raw = %{style="_beHaVior : url ( foo.htc)" <div style="_beHaVior : url ( foo.htc)">foo</div>} 
     287    result = sanitize(raw) 
     288    assert_equal %{style="_beHaVior : url ( foo.htc)" <div>foo</div>}, result 
     289  end 
     290   
     291  def test_sanitize_expression 
     292    raw = %{style="expression(evilJS)" <div style="width: expression(evilJS)">foo</div>} 
     293    result = sanitize(raw) 
     294    assert_equal %{style="expression(evilJS)" <div>foo</div>}, result 
     295    raw = %{style="_eXpressiOn ( evilJS)" <div style="width: _eXpressiOn ( evilJS)">foo</div>} 
     296    result = sanitize(raw) 
     297    assert_equal %{style="_eXpressiOn ( evilJS)" <div>foo</div>}, result     
     298  end 
     299   
    282300  def test_cycle_class 
    283301    value = Cycle.new("one", 2, "3") 
    284302    assert_equal("one", value.to_s) 
  • actionpack/lib/action_view/helpers/text_helper.rb

    old new  
    202202 
    203203      VERBOTEN_TAGS = %w(form script plaintext) unless defined?(VERBOTEN_TAGS) 
    204204      VERBOTEN_ATTRS = /^on/i unless defined?(VERBOTEN_ATTRS) 
     205      VERBOTEN_STYLE = /(expression|behavior)/i unless defined?(VERBOTEN_STYLE) 
    205206 
    206207      # Sanitizes the +html+ by converting <form> and <script> tags into regular 
    207208      # text, and removing all "onxxx" attributes (so that arbitrary Javascript 
     
    228229                else 
    229230                  if node.closing != :close 
    230231                    node.attributes.delete_if { |attr,v| attr =~ VERBOTEN_ATTRS } 
     232                    node.attributes.delete_if { |attr,v| attr == "style" && v =~ VERBOTEN_STYLE } 
    231233                    %w(href src).each do |attr| 
    232234                      node.attributes.delete attr if node.attributes[attr] =~ /^javascript:/i 
    233235                    end