This project is archived and is in readonly mode.
The Rails sanitizer incorrectly remove hrefs that contain capitalized URLs
Reported by Tom | November 23rd, 2010 @ 04:37 AM
[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 =~ /(^[^\/:]*):|(�*58)|(p)|(%|%)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
Comments and changes to this ticket
-
2kan November 23rd, 2010 @ 09:19 PM
- 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.
-
2kan November 23rd, 2010 @ 09:20 PM
- Tag changed from master, path, sanitize to master, patch, sanitize
-
Yaroslav Markin December 29th, 2010 @ 04:38 PM
- Assigned user set to Santiago Pastorino
-
Repository December 31st, 2010 @ 12:45 AM
- State changed from new to committed
(from [e5b84fd72358deddd29c515aacab7edf2643908e]) ActionController::Base.helpers.sanitize ignores case in protocol
[#6044 state:committed]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
https://github.com/rails/rails/commit/e5b84fd72358deddd29c515aacab7...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 6044 The Rails sanitizer incorrectly remove hrefs that contain capitalized URLs [#6044 state:committed]