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.

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.rb
index 594b57df82..05e8804b68 100644
--- a/core/app/models/spree/variant.rb
+++ b/core/app/models/spree/variant.rb
@@ -128,13 +128,18 @@ module Spree
self.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))
end
end