Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Allow only web images (#12175)

Damian Kaczmarczykb6a861116943
diff --git a/core/app/models/spree/image/configuration/active_storage.rb b/core/app/models/spree/image/configuration/active_storage.rb
index ccb4ea7da7..963cefead6 100644
--- a/core/app/models/spree/image/configuration/active_storage.rb
+++ b/core/app/models/spree/image/configuration/active_storage.rb
@@ -5,7 +5,7 @@ module Spree
extend ActiveSupport::Concern
included do
- validates :attachment, attached: true, content_type: /\Aimage\/.*\z/
+ validates :attachment, attached: true, content_type: Rails.application.config.active_storage.web_image_content_types
def self.styles
@styles ||= {
diff --git a/core/app/models/spree/taxon_image/configuration/active_storage.rb b/core/app/models/spree/taxon_image/configuration/active_storage.rb
index 868014c7c7..dfcb16d972 100644
--- a/core/app/models/spree/taxon_image/configuration/active_storage.rb
+++ b/core/app/models/spree/taxon_image/configuration/active_storage.rb
@@ -5,7 +5,7 @@ module Spree
extend ActiveSupport::Concern
included do
- validates :attachment, content_type: /\Aimage\/.*\z/
+ validates :attachment, content_type: Rails.application.config.active_storage.web_image_content_types
default_scope { includes(attachment_attachment: :blob) }
diff --git a/core/spec/models/spree/image_spec.rb b/core/spec/models/spree/image_spec.rb
index c401035841..590eafeed7 100644
--- a/core/spec/models/spree/image_spec.rb
+++ b/core/spec/models/spree/image_spec.rb
@@ -16,12 +16,12 @@ describe Spree::Image, type: :model do
expect(spree_image).not_to be_valid
end
- it 'has allowed attachment content type' do
+ it 'allows only web image content types' do
spree_image.attachment.attach(io: image_file, filename: 'thinking-cat.jpg', content_type: 'image/jpeg')
expect(spree_image).to be_valid
end
- it 'has no allowed attachment content type' do
+ it 'does not allow non-web image content types' do
spree_image.attachment.attach(io: text_file, filename: 'text-file.txt', content_type: 'text/plain')
expect(spree_image).not_to be_valid
end