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

Ticket #8222: sanitize_ie_problems.diff

File sanitize_ie_problems.diff, 2.0 kB (added by wycats, 1 year ago)

Sanitize behaviors and expressions

  • 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\()/ 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 
  • 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(foo.htc)" <div style="width: behavior(foo.htc)">foo</div>} 
     284    result = sanitize(raw) 
     285    assert_equal %{style="behavior(foo.htc)" <div>foo</div>}, result 
     286  end 
     287   
     288  def test_sanitize_expression 
     289    raw = %{style="expression(evilJS)" <div style="width: expression(evilJS)">foo</div>} 
     290    result = sanitize(raw) 
     291    assert_equal %{style="expression(evilJS)" <div>foo</div>}, result 
     292  end 
     293   
    282294  def test_cycle_class 
    283295    value = Cycle.new("one", 2, "3") 
    284296    assert_equal("one", value.to_s)