A platform for community discussion. Free, open, simple.
FIX: Stop category logo + background being marked secure (#10513)
Martin Brennane8a842ab8cbb
diff --git a/lib/upload_security.rb b/lib/upload_security.rbindex 887644699f3..52da01b712a 100644--- a/lib/upload_security.rb+++ b/lib/upload_security.rb@@ -14,7 +14,10 @@# on the current secure? status, otherwise there would be a lot of additional# complex queries and joins to perform.class UploadSecurity- PUBLIC_TYPES = %w[avatar custom_emoji profile_background card_background]+ PUBLIC_TYPES = %w[+ avatar custom_emoji profile_background card_background category_logo category_background+ ]+def initialize(upload, opts = {})@upload = upload@opts = opts@@ -30,7 +33,12 @@ class UploadSecurityprivatedef uploading_in_public_context?- @upload.for_theme || @upload.for_site_setting || @upload.for_gravatar || public_type? || used_for_custom_emoji? || based_on_regular_emoji?+ @upload.for_theme ||+ @upload.for_site_setting ||+ @upload.for_gravatar ||+ public_type? ||+ used_for_custom_emoji? ||+ based_on_regular_emoji?enddef uploading_in_secure_context?diff --git a/spec/lib/upload_security_spec.rb b/spec/lib/upload_security_spec.rbindex 8f99025df2c..faba025d0c8 100644--- a/spec/lib/upload_security_spec.rb+++ b/spec/lib/upload_security_spec.rb@@ -10,73 +10,6 @@ RSpec.describe UploadSecurity dolet(:opts) { { type: type } }subject { described_class.new(upload, opts) }- context "when uploading in public context" do- describe "for a public type avatar" do- let(:type) { 'avatar' }- it "returns false" do- expect(subject.should_be_secure?).to eq(false)- end- end- describe "for a public type custom_emoji" do- let(:type) { 'custom_emoji' }- it "returns false" do- expect(subject.should_be_secure?).to eq(false)- end- end- describe "for a public type profile_background" do- let(:type) { 'profile_background' }- it "returns false" do- expect(subject.should_be_secure?).to eq(false)- end- end- describe "for a public type avatar" do- let(:type) { 'avatar' }- it "returns false" do- expect(subject.should_be_secure?).to eq(false)- end- end-- describe "for_theme" do- before do- upload.stubs(:for_theme).returns(true)- end- it "returns false" do- expect(subject.should_be_secure?).to eq(false)- end- end- describe "for_site_setting" do- before do- upload.stubs(:for_site_setting).returns(true)- end- it "returns false" do- expect(subject.should_be_secure?).to eq(false)- end- end- describe "for_gravatar" do- before do- upload.stubs(:for_gravatar).returns(true)- end- it "returns false" do- expect(subject.should_be_secure?).to eq(false)- end- end-- describe "when the upload is used for a custom emoji" do- it "returns false" do- CustomEmoji.create(name: 'meme', upload: upload)- expect(subject.should_be_secure?).to eq(false)- end- end-- describe "when it is based on a regular emoji" do- it "returns false" do- falafel = Emoji.all.find { |e| e.url == '/images/emoji/twitter/falafel.png?v=9' }- upload.update!(origin: "http://localhost:3000#{falafel.url}")- expect(subject.should_be_secure?).to eq(false)- end- end- end-context "when secure media is enabled" dobefore doSiteSetting.enable_s3_uploads = true@@ -86,13 +19,91 @@ RSpec.describe UploadSecurity doSiteSetting.secure_media = trueend- context "when login_required" do+ context "when login_required (everything should be secure except public context items)" dobefore doSiteSetting.login_required = trueendit "returns true" doexpect(subject.should_be_secure?).to eq(true)end++ context "when uploading in public context" do+ describe "for a public type avatar" do+ let(:type) { 'avatar' }+ it "returns false" do+ expect(subject.should_be_secure?).to eq(false)+ end+ end+ describe "for a public type custom_emoji" do+ let(:type) { 'custom_emoji' }+ it "returns false" do+ expect(subject.should_be_secure?).to eq(false)+ end+ end+ describe "for a public type profile_background" do+ let(:type) { 'profile_background' }+ it "returns false" do+ expect(subject.should_be_secure?).to eq(false)+ end+ end+ describe "for a public type avatar" do+ let(:type) { 'avatar' }+ it "returns false" do+ expect(subject.should_be_secure?).to eq(false)+ end+ end+ describe "for a public type category_logo" do+ let(:type) { 'category_logo' }+ it "returns false" do+ expect(subject.should_be_secure?).to eq(false)+ end+ end+ describe "for a public type category_background" do+ let(:type) { 'category_background' }+ it "returns false" do+ expect(subject.should_be_secure?).to eq(false)+ end+ end+ describe "for_theme" do+ before do+ upload.stubs(:for_theme).returns(true)+ end+ it "returns false" do+ expect(subject.should_be_secure?).to eq(false)+ end+ end+ describe "for_site_setting" do+ before do+ upload.stubs(:for_site_setting).returns(true)+ end+ it "returns false" do+ expect(subject.should_be_secure?).to eq(false)+ end+ end+ describe "for_gravatar" do+ before do+ upload.stubs(:for_gravatar).returns(true)+ end+ it "returns false" do+ expect(subject.should_be_secure?).to eq(false)+ end+ end++ describe "when the upload is used for a custom emoji" do+ it "returns false" do+ CustomEmoji.create(name: 'meme', upload: upload)+ expect(subject.should_be_secure?).to eq(false)+ end+ end++ describe "when it is based on a regular emoji" do+ it "returns false" do+ falafel = Emoji.all.find { |e| e.url == '/images/emoji/twitter/falafel.png?v=9' }+ upload.update!(origin: "http://localhost:3000#{falafel.url}")+ expect(subject.should_be_secure?).to eq(false)+ end+ end+ endendcontext "when the access control post has_secure_media?" do