Skip to content

Commit 2a70939

Browse files
committed
Fixed SQL injection vulnerability in Opportunity
1 parent d855678 commit 2a70939

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

app/models/opportunity.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class Opportunity < ActiveRecord::Base
5757
after_create :pay_for_it!
5858

5959
scope :valid, where(deleted: false).where('expires_at > ?', Time.now).order('created_at DESC')
60-
scope :by_city, lambda { |city| where("LOWER(location_city) LIKE '%#{city.try(:downcase)}%'") }
61-
scope :by_tag, lambda { |tag| where("LOWER(cached_tags) LIKE '%#{tag}%'") unless tag.nil? }
60+
scope :by_city, lambda { |city| where('LOWER(location_city) LIKE ?', "%#{city.try(:downcase)}%") }
61+
scope :by_tag, lambda { |tag| where('LOWER(cached_tags) LIKE ?', "%#{tag}%") unless tag.nil? }
6262
default_scope valid
6363

6464
attr_accessor :title
@@ -318,8 +318,8 @@ def set_location_city
318318

319319
def add_opportunity_locations_to_team
320320
geocoded_all = true
321-
self.location.split("|").each do |location_string|
322-
geocoded_all &&= self.team.team_locations.where("address LIKE '%#{location_string}%'").exists? or anywhere?(location_string) ? false : self.team.team_locations.build(address: location_string, name: location_string).geocode
321+
self.location.split('|').each do |location_string|
322+
geocoded_all &&= self.team.team_locations.where(conditions: ['address LIKE ?', "%#{location_string}%"]).exists? or anywhere?(location_string) ? false : self.team.team_locations.build(address: location_string, name: location_string).geocode
323323
end
324324
geocoded_all || nil
325325
end

0 commit comments

Comments
 (0)