diff --git a/Gemfile b/Gemfile index e91c3ae..489202f 100644 --- a/Gemfile +++ b/Gemfile @@ -40,6 +40,8 @@ gem 'jbuilder', '~> 2.5' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +gem 'rack-attack' + group :development, :test do gem 'rspec-rails' # Call 'byebug' anywhere in the code to stop execution and get a debugger console @@ -48,7 +50,8 @@ end group :development do gem 'faker' - + gem 'brakeman' + gem 'bundler-audit' # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. gem 'web-console', '>= 3.3.0' gem 'listen', '~> 3.0.5' diff --git a/Gemfile.lock b/Gemfile.lock index 30c443b..5e6563f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,7 +46,11 @@ GEM bootstrap-sass (3.3.7) autoprefixer-rails (>= 5.2.1) sass (>= 3.3.4) + brakeman (3.5.0) builder (3.2.3) + bundler-audit (0.5.0) + bundler (~> 1.2) + thor (~> 0.18) byebug (9.0.6) coffee-rails (4.2.1) coffee-script (>= 2.2.0) @@ -98,6 +102,8 @@ GEM orm_adapter (0.5.0) puma (3.8.2) rack (2.0.1) + rack-attack (5.0.1) + rack rack-test (0.6.3) rack (>= 1.0) rails (5.0.2) @@ -192,6 +198,8 @@ PLATFORMS DEPENDENCIES bootstrap-sass + brakeman + bundler-audit byebug coffee-rails (~> 4.2) devise @@ -200,6 +208,7 @@ DEPENDENCIES jquery-rails listen (~> 3.0.5) puma (~> 3.0) + rack-attack rails (~> 5.0.2) rspec-rails sass-rails (~> 5.0) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 682a07d..cd6ea53 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,6 @@ class ApplicationController < ActionController::Base - # protect_from_forgery with: :exception + protect_from_forgery with: :exception helper_method :current_cart diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 245dece..4ab4b15 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -9,10 +9,12 @@ def show @comments = @event.comments if params[:keyword] - @comments = @comments.where( "comments.content LIKE '%#{params[:keyword]}%'") + # @comments = @comments.where( "comments.content LIKE '%#{params[:keyword]}%'") + keyword = ActiveRecord::Base::connection.quote_string( params[:keyword] ) + @comments = @comments.where( "comments.content LIKE ?", "%#{params[:keyword]}%") end - if params[:sort] + if params[:sort] && ["id DESC", "id ASC"].include?(params[:sort]) @comments = @comments.order(params[:sort]) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f4b4e65..1a5e5d5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -10,13 +10,20 @@ def edit def update @user = current_user - params[:user].permit! + # params[:user].permit! - if @user.update(params[:user]) + # if @user.update(params[:user]) + if @user.update(user_params) redirect_to user_path(@user) else render "edit" end end + protected + + def user_params + params.require(:user).permit(:nickname) + end + end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index ed49051..7c220a0 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -7,9 +7,13 @@ def user_avatar_link(user) email_md5 = Digest::MD5.hexdigest(user.email) gravatar_url = "https://www.gravatar.com/avatar/#{email_md5}" - str = "