Fix XSS vulnerabilities in chunk-handling

This commit is contained in:
Jacques Distler 2007-09-23 19:30:39 +00:00
parent 36b86a9d41
commit a3d3f1c536
6 changed files with 55 additions and 3 deletions

View file

@ -16,7 +16,8 @@ class Category < Chunk::Abstract
def initialize(match_data, content)
super(match_data, content)
@hidden = match_data[1]
@list = match_data[2].split(',').map { |c| c.strip }
@list = match_data[2].split(',').map { |c| c.to_s.is_utf8? ? html_escape(c. strip) : nil }
@list.compact!
@unmask_text = ''
if @hidden
@unmask_text = ''
@ -28,6 +29,6 @@ def initialize(match_data, content)
# TODO move presentation of page metadata to controller/view
def url(category)
%{<a class="category_link" href="../list/?category=#{category}">#{category}</a>}
%{<a class="category_link" href="../list/#{category}">#{category}</a>}
end
end

View file

@ -74,6 +74,14 @@ module Chunk
@content.delete_chunk(self)
end
def html_escape(string)
string.gsub( /&/, "&amp;" ).
gsub( /</, "&lt;" ).
gsub( />/, "&gt;" ).
gsub( /'/, "&#39;" ).
gsub( /"/, "&quot;" )
end
end
end

View file

@ -13,6 +13,10 @@ require 'chunks/chunk'
#
# Author: Mark Reid <mark at threewordslong dot com>
# Created: 8th June 2004
require 'sanitize'
include Sanitize
class NoWiki < Chunk::Abstract
NOWIKI_PATTERN = Regexp.new('<nowiki>(.*?)</nowiki>', Regexp::MULTILINE)
@ -22,7 +26,7 @@ class NoWiki < Chunk::Abstract
def initialize(match_data, content)
super
@plain_text = @unmask_text = match_data[1]
@plain_text = @unmask_text = sanitize_html(match_data[1])
end
end