diff options
author | Robert Speicher <robert@gitlab.com> | 2017-02-14 01:42:46 +0300 |
---|---|---|
committer | Ruben Davila <rdavila84@gmail.com> | 2017-02-14 02:15:03 +0300 |
commit | 78d9c07c696f065ba062f94e9efabf9e99d10cc8 (patch) | |
tree | 0975e9c33d2b689e0910231260a54339d767c2a6 /spec | |
parent | 89fd8c3984ae1e437b316acb787364e4369d016e (diff) |
Merge branch 'svg-xss-fix' into 'security'
Fix for XSS vulnerability in SVG attachments
See https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/2059
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/uploads_controller_spec.rb | 22 | ||||
-rw-r--r-- | spec/factories/notes.rb | 6 |
2 files changed, 27 insertions, 1 deletions
diff --git a/spec/controllers/uploads_controller_spec.rb b/spec/controllers/uploads_controller_spec.rb index 69124ab06bf..8ea9c71e4af 100644 --- a/spec/controllers/uploads_controller_spec.rb +++ b/spec/controllers/uploads_controller_spec.rb @@ -4,6 +4,28 @@ describe UploadsController do let!(:user) { create(:user, avatar: fixture_file_upload(Rails.root + "spec/fixtures/dk.png", "image/png")) } describe "GET show" do + context 'Content-Disposition security measures' do + let(:project) { create(:empty_project, :public) } + + context 'for PNG files' do + it 'returns Content-Disposition: inline' do + note = create(:note, :with_attachment, project: project) + get :show, model: 'note', mounted_as: 'attachment', id: note.id, filename: 'image.png' + + expect(response['Content-Disposition']).to start_with('inline;') + end + end + + context 'for SVG files' do + it 'returns Content-Disposition: attachment' do + note = create(:note, :with_svg_attachment, project: project) + get :show, model: 'note', mounted_as: 'attachment', id: note.id, filename: 'image.svg' + + expect(response['Content-Disposition']).to start_with('attachment;') + end + end + end + context "when viewing a user avatar" do context "when signed in" do before do diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb index a10ba629760..b60b9f605c2 100644 --- a/spec/factories/notes.rb +++ b/spec/factories/notes.rb @@ -83,7 +83,11 @@ FactoryGirl.define do end trait :with_attachment do - attachment { fixture_file_upload(Rails.root + "spec/fixtures/dk.png", "`/png") } + attachment { fixture_file_upload(Rails.root + "spec/fixtures/dk.png", "image/png") } + end + + trait :with_svg_attachment do + attachment { fixture_file_upload(Rails.root + "spec/fixtures/unsanitized.svg", "image/svg+xml") } end end end |