Filter image tags everywhere except in custom pages

Allowing image tags everywhere makes us vulnerable to CSRF attacks.
This commit is contained in:
Javi Martín
2018-09-07 14:13:48 +02:00
parent 5faeefab2c
commit f917f5eed9
5 changed files with 44 additions and 4 deletions

View File

@@ -0,0 +1,12 @@
require 'rails_helper'
describe AdminWYSIWYGSanitizer do
let(:sanitizer) { AdminWYSIWYGSanitizer.new }
describe '#sanitize' do
it 'allows images' do
html = 'Dangerous<img src="/smile.png" alt="Smile" style="width: 10px;"> image'
expect(sanitizer.sanitize(html)).to eq(html)
end
end
end

View File

@@ -15,10 +15,25 @@ describe WYSIWYGSanitizer do
expect(subject.sanitize(html)).to eq(html)
end
it 'allows links' do
html = '<p><a href="/">Home</a></p>'
expect(subject.sanitize(html)).to eq(html)
end
it 'allows headings' do
html = '<h2>Objectives</h2><p>Fix flaky specs</p><h3>Explain why the test is flaky</h3>'
expect(subject.sanitize(html)).to eq(html)
end
it 'filters out dangerous tags' do
html = '<p>This is <script>alert("dangerous");</script></p>'
expect(subject.sanitize(html)).to eq('<p>This is alert("dangerous");</p>')
end
it 'filters images' do
html = 'Dangerous<img src="/smile.png" alt="Smile" style="width: 10px";> image'
expect(subject.sanitize(html)).to eq('Dangerous image')
end
end
end