mirror of
https://github.com/discourse/discourse.git
synced 2025-08-21 19:11:18 +08:00
SECURITY: fix XSS in excerpt parser
This commit is contained in:
parent
fbbd4999b6
commit
6e9f5f5584
3 changed files with 37 additions and 24 deletions
|
@ -23,8 +23,15 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
|||
me.excerpt
|
||||
end
|
||||
|
||||
def escape_attribute(v)
|
||||
v.gsub("&", "&")
|
||||
.gsub("\"", """)
|
||||
.gsub("<", "<")
|
||||
.gsub(">", ">")
|
||||
end
|
||||
|
||||
def include_tag(name, attributes)
|
||||
characters("<#{name} #{attributes.map{|k,v| "#{k}='#{v}'"}.join(' ')}>", false, false, false)
|
||||
characters("<#{name} #{attributes.map{|k,v| "#{k}=\"#{escape_attribute(v)}\""}.join(' ')}>", false, false, false)
|
||||
end
|
||||
|
||||
def start_element(name, attributes=[])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue