From 3859c13ffda6930cb65f2d6dd2f09085266d9bee Mon Sep 17 00:00:00 2001 From: fiveNinePlusR Date: Sun, 29 Sep 2024 19:58:37 -0700 Subject: [PATCH] add some security fixes for brakeman --- .../v1/location_machine_xrefs_controller.rb | 4 +- .../v1/location_picture_xrefs_controller.rb | 2 +- app/models/location.rb | 4 +- app/models/machine_score_xref.rb | 8 +- app/models/suggested_location.rb | 12 ++- app/models/user.rb | 2 +- app/views/locations/_form.html.haml | 2 +- app/views/locations/_locations.html.haml | 2 +- bin/bundle-audit | 27 ++++++ bin/bundler-audit | 27 ++++++ config/brakeman.ignore | 94 +++++++++++++++++++ config/initializers/cookies_serializer.rb | 2 +- 12 files changed, 168 insertions(+), 18 deletions(-) create mode 100755 bin/bundle-audit create mode 100755 bin/bundler-audit create mode 100644 config/brakeman.ignore diff --git a/app/controllers/api/v1/location_machine_xrefs_controller.rb b/app/controllers/api/v1/location_machine_xrefs_controller.rb index f55a90568..fa2724b3a 100644 --- a/app/controllers/api/v1/location_machine_xrefs_controller.rb +++ b/app/controllers/api/v1/location_machine_xrefs_controller.rb @@ -38,8 +38,8 @@ def create return return_response(AUTH_REQUIRED_MSG, 'errors') if user.nil? - location_id = params[:location_id] - machine_id = params[:machine_id] + location_id = params[:location_id].to_i + machine_id = params[:machine_id].to_i condition = params[:condition] status_code = 200 diff --git a/app/controllers/api/v1/location_picture_xrefs_controller.rb b/app/controllers/api/v1/location_picture_xrefs_controller.rb index 867a831f3..82ca86890 100644 --- a/app/controllers/api/v1/location_picture_xrefs_controller.rb +++ b/app/controllers/api/v1/location_picture_xrefs_controller.rb @@ -21,7 +21,7 @@ def show def create return return_response(AUTH_REQUIRED_MSG, 'errors') if current_user.nil? - location_id = params[:location_id] + location_id = params[:location_id].to_i return return_response('Failed to find location', 'errors') if location_id.nil? || !Location.exists?(location_id) photo = params[:photo] diff --git a/app/models/location.rb b/app/models/location.rb index e14302fd3..e3352c82d 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -3,8 +3,8 @@ class Location < ApplicationRecord validates_presence_of :name, :street, :city, :country validates :phone, phone: { possible: true, allow_blank: true, message: 'Phone format not valid.' } - validates :website, format: { with: %r{http(s?)://}, message: 'must begin with http:// or https://' }, if: :website? - validates :name, :street, :city, format: { with: /^\S.*/, message: "Can't start with a blank", multiline: true } + validates :website, format: { with: %r{\Ahttp(s?)://}, message: 'must begin with http:// or https://' }, if: :website? + validates :name, :street, :city, format: { with: /\A\S.*/, message: "Can't start with a blank", multiline: true } validates :lat, :lon, presence: { message: 'Latitude/Longitude failed to generate. Please double check address and try again, or manually enter the lat/lon' } belongs_to :location_type, optional: true diff --git a/app/models/machine_score_xref.rb b/app/models/machine_score_xref.rb index c55b44955..6f17986a0 100644 --- a/app/models/machine_score_xref.rb +++ b/app/models/machine_score_xref.rb @@ -8,8 +8,8 @@ class MachineScoreXref < ApplicationRecord scope :zone_id, lambda { |id| joins(:location_machine_xref).joins(:location).where(" - locations.zone_id = #{id} - ") + locations.zone_id = ? + ", id) } scope :region, lambda { |name| @@ -17,8 +17,8 @@ class MachineScoreXref < ApplicationRecord joins(:location_machine_xref).joins(:location).where(" location_machine_xrefs.id = machine_score_xrefs.location_machine_xref_id and locations.id = location_machine_xrefs.location_id - and locations.region_id = #{r.id} - ") + and locations.region_id = ? + ", r.id) } def username diff --git a/app/models/suggested_location.rb b/app/models/suggested_location.rb index 98e4fced1..d62fb5850 100644 --- a/app/models/suggested_location.rb +++ b/app/models/suggested_location.rb @@ -5,8 +5,8 @@ class SuggestedLocation < ApplicationRecord validates_presence_of :name, :machines, on: :create validates_presence_of :street, :city, :zip, on: :update - validates :website, format: { with: %r{http(s?)://}, message: 'must begin with http:// or https://' }, if: :website?, on: :update - validates :name, :street, :city, format: { with: /^\S.*/, message: "Can't start with a blank", multiline: true }, on: :update + validates :website, format: { with: %r{\Ahttp(s?)://}, message: 'must begin with http:// or https://' }, if: :website?, on: :update + validates :name, :street, :city, format: { with: /\A\S.*/, message: "Can't start with a blank", multiline: true }, on: :update validates :lat, :lon, presence: { message: 'Latitude/Longitude failed to generate. Please double check address and try again, or manually enter the lat/lon' }, on: :update belongs_to :region, optional: true @@ -97,19 +97,21 @@ def convert_to_location(user_email) delete - ActiveRecord::Base.connection.execute(<