Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

The Rails sanitizer incorrectly remove hrefs that contain capitalized URLs

#6044

[Dev]> ActionController::Base.helpers.sanitize('test')

=> '<a href="http://google.com">test</a>'
[Dev]>   ActionController::Base.helpers.sanitize('<a href="Http://google.com">test</a>')
=> '<a>test</a>'

This seems to be a bug in the method contains_bad_protocols? in action_controller/vendor/html-scanner/html/sanitizer.rb. This method is defined as:

def contains_bad_protocols?(attr_name, value)
    uri_attributes.include?(attr_name) && 
    (value =~ /(^[^\/:]*):|(&#0*58)|(&#x70)|(%|&#37;)3A/ 
        && !allowed_protocols.include?(value.split(protocol_separator).first))
end

And allowed_protocols as:

self.allowed_protocols = Set.new(%w(ed2k ftp http https irc mailto news gopher nntp
    telnet webcal xmpp callto feed svn urn aim rsync tag ssh sftp rtsp afs))

Thus:

allowed_protocols.include? 'http' => true
allowed_protocols.include? 'Http' => false

SEE ALSO: http://stackoverflow.com/posts/4240994

Reported by Tom · November 23rd, 2010 @ 04:37 AM

State: committed
Milestone: none
Assigned to: Santiago Pastorino Santiago Pastorino
Importance: none

Activity

  1. 2kan
    2kan
    • Tag changed from sanitize to master, path, sanitize

    Looks like a bug for me. But fix is very simple, we need just to call downcase when checking a protocol. Patch for master with test assigned.

    November 23rd, 2010 @ 09:19 PM

  2. 2kan
    2kan
    • Tag changed from master, path, sanitize to master, patch, sanitize

    November 23rd, 2010 @ 09:20 PM

  3. Yaroslav Markin
    Yaroslav Markin
    • Assigned user set to Santiago Pastorino

    December 29th, 2010 @ 04:38 PM

  4. Repository