Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Redirect unauthorised attempts to submit forms to 422
Browse files Browse the repository at this point in the history
  • Loading branch information
constantine-nikolaou committed Nov 1, 2020
1 parent ddbd6cc commit 2560126
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception

rescue_from ActionController::InvalidAuthenticityToken, with: :render_422

# API access
before_action :authenticate_with_token!, if: :api_request

Expand Down Expand Up @@ -51,6 +53,15 @@ def pagination_content(name, current_page, total_pages)
return pagination
end

# Handle errors
def handle_unverified_request
raise(ActionController::InvalidAuthenticityToken)
end

def render_422
redirect_to '/422'
end

def not_found
raise ActionController::RoutingError.new('Not Found')
rescue
Expand Down

0 comments on commit 2560126

Please sign in to comment.