Sanitize HTML output.
This commit is contained in:
+41
-1
@@ -1,6 +1,7 @@
|
||||
# external
|
||||
require 'grit'
|
||||
require 'github/markup'
|
||||
require 'sanitize'
|
||||
|
||||
# internal
|
||||
require 'gollum/pagination'
|
||||
@@ -12,4 +13,43 @@ require 'gollum/albino'
|
||||
|
||||
module Gollum
|
||||
VERSION = '0.0.1'
|
||||
end
|
||||
|
||||
SANITIZATION_OPTIONS = {
|
||||
:elements => [
|
||||
'a', 'abbr', 'acronym', 'address', 'area', 'b', 'big',
|
||||
'blockquote', 'br', 'button', 'caption', 'center', 'cite',
|
||||
'code', 'col', 'colgroup', 'dd', 'del', 'dfn', 'dir',
|
||||
'div', 'dl', 'dt', 'em', 'fieldset', 'font', 'form', 'h1',
|
||||
'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'input',
|
||||
'ins', 'kbd', 'label', 'legend', 'li', 'map', 'menu',
|
||||
'ol', 'optgroup', 'option', 'p', 'pre', 'q', 's', 'samp',
|
||||
'select', 'small', 'span', 'strike', 'strong', 'sub',
|
||||
'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th',
|
||||
'thead', 'tr', 'tt', 'u', 'ul', 'var'
|
||||
],
|
||||
:attributes => {
|
||||
:all => ['abbr', 'accept', 'accept-charset',
|
||||
'accesskey', 'action', 'align', 'alt', 'axis',
|
||||
'border', 'cellpadding', 'cellspacing', 'char',
|
||||
'charoff', 'charset', 'checked', 'cite',
|
||||
'class', 'clear', 'cols', 'colspan', 'color',
|
||||
'compact', 'coords', 'datetime', 'dir',
|
||||
'disabled', 'enctype', 'for', 'frame',
|
||||
'headers', 'height', 'href', 'hreflang',
|
||||
'hspace', 'id', 'ismap', 'label', 'lang',
|
||||
'longdesc', 'maxlength', 'media', 'method',
|
||||
'multiple', 'name', 'nohref', 'noshade',
|
||||
'nowrap', 'prompt', 'readonly', 'rel', 'rev',
|
||||
'rows', 'rowspan', 'rules', 'scope',
|
||||
'selected', 'shape', 'size', 'span', 'src',
|
||||
'start', 'summary', 'tabindex', 'target',
|
||||
'title', 'type', 'usemap', 'valign', 'value',
|
||||
'vspace', 'width']
|
||||
},
|
||||
:protocols => {
|
||||
'a' => {'href' => ['http', 'https', 'mailto', :relative]},
|
||||
'img' => {'href' => ['http', 'https', :relative]}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
+7
-10
@@ -27,6 +27,9 @@ module Gollum
|
||||
data = GitHub::Markup.render(@name, data) rescue ''
|
||||
data = process_tags(data)
|
||||
data = process_code(data)
|
||||
data = Sanitize.clean(data, SANITIZATION_OPTIONS)
|
||||
data = data.gsub(/<p><\/p>/, '')
|
||||
data
|
||||
end
|
||||
|
||||
#########################################################################
|
||||
@@ -100,7 +103,6 @@ module Gollum
|
||||
|
||||
classes = [] # applied to whatever the outermost container is
|
||||
attrs = [] # applied to the image
|
||||
styles = [] # applied to the image
|
||||
|
||||
align = opts['align']
|
||||
if opts['float']
|
||||
@@ -120,13 +122,13 @@ module Gollum
|
||||
|
||||
if width = opts['width']
|
||||
if width =~ /^\d+(\.\d+)?(em|px)$/
|
||||
styles << "max-width: #{width};"
|
||||
attrs << %{width="#{width}"}
|
||||
end
|
||||
end
|
||||
|
||||
if height = opts['height']
|
||||
if height =~ /^\d+(\.\d+)?(em|px)$/
|
||||
styles << "max-height: #{height};"
|
||||
attrs << %{height="#{height}"}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -136,21 +138,16 @@ module Gollum
|
||||
|
||||
attr_string = attrs.size > 0 ? attrs.join(' ') + ' ' : ''
|
||||
|
||||
style_string = ''
|
||||
unless styles.empty?
|
||||
style_string = %{ style="#{styles.join(' ')}"}
|
||||
end
|
||||
|
||||
if opts['frame'] || containered
|
||||
classes << 'frame' if opts['frame']
|
||||
%{<span class="#{classes.join(' ')}">} +
|
||||
%{<span>} +
|
||||
%{<img src="/#{file.path}"#{style_string} #{attr_string}/>} +
|
||||
%{<img src="/#{file.path}" #{attr_string}/>} +
|
||||
(alt ? %{<span>#{alt}</span>} : '') +
|
||||
%{</span>} +
|
||||
%{</span>}
|
||||
else
|
||||
%{<img src="#{path}"#{style_string} #{attr_string}/>}
|
||||
%{<img src="#{path}" #{attr_string}/>}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user