mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
SECURITY: Remove event handlers from SVG files
This commit is contained in:
parent
adfa793731
commit
4e130f1e03
|
@ -277,6 +277,7 @@ class UploadCreator
|
|||
def whitelist_svg!
|
||||
doc = Nokogiri::XML(@file)
|
||||
doc.xpath(svg_whitelist_xpath).remove
|
||||
doc.xpath("//@*[starts-with(name(), 'on')]").remove
|
||||
File.write(@file.path, doc.to_s)
|
||||
@file.rewind
|
||||
end
|
||||
|
|
|
@ -247,4 +247,26 @@ RSpec.describe UploadCreator do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#whitelist_svg!' do
|
||||
let(:file) do
|
||||
file = Tempfile.new
|
||||
file.write(<<~XML)
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="200px" height="200px" onload="alert(location)">
|
||||
</svg>
|
||||
XML
|
||||
file.rewind
|
||||
file
|
||||
end
|
||||
|
||||
it 'removes event handlers' do
|
||||
begin
|
||||
UploadCreator.new(file, 'file.svg').whitelist_svg!
|
||||
expect(file.read).not_to include('onload')
|
||||
ensure
|
||||
file.unlink
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user