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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fixed possible (weak) SQL injection reported by brakeman (#12143)
Damian Legawieca7ebfa5e98e2
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rbindex 594b57df82..05e8804b68 100644--- a/core/app/models/spree/variant.rb+++ b/core/app/models/spree/variant.rb@@ -128,13 +128,18 @@ module Spreeself.whitelisted_ransackable_scopes = %i(product_name_or_sku_cont search_by_product_name_or_sku)def self.product_name_or_sku_cont(query)+ sanitized_query = ActiveRecord::Base.sanitize_sql_like(query.to_s.downcase.strip)+ query_pattern = "%#{sanitized_query}%"+ sku_condition = arel_table[:sku].lower.matches(query_pattern)+if Spree.use_translations?+ product_name_condition = Product.translation_table[:name].lower.matches(query_pattern)joins(:product).join_translation_table(Product).- where("LOWER(#{Product.translation_table_alias}.name) LIKE LOWER(:query)- OR LOWER(sku) LIKE LOWER(:query)", query: "%#{query}%")+ where(product_name_condition.or(sku_condition))else- joins(:product).where("LOWER(#{Product.table_name}.name) LIKE LOWER(:query) OR LOWER(sku) LIKE LOWER(:query)", query: "%#{query}%")+ product_name_condition = Product.arel_table[:name].lower.matches(query_pattern)+ joins(:product).where(product_name_condition.or(sku_condition))endend