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

Commit 2560126

Browse files
Redirect unauthorised attempts to submit forms to 422
1 parent ddbd6cc commit 2560126

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

app/controllers/application_controller.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
class ApplicationController < ActionController::Base
22
protect_from_forgery with: :exception
33

4+
rescue_from ActionController::InvalidAuthenticityToken, with: :render_422
5+
46
# API access
57
before_action :authenticate_with_token!, if: :api_request
68

@@ -51,6 +53,15 @@ def pagination_content(name, current_page, total_pages)
5153
return pagination
5254
end
5355

56+
# Handle errors
57+
def handle_unverified_request
58+
raise(ActionController::InvalidAuthenticityToken)
59+
end
60+
61+
def render_422
62+
redirect_to '/422'
63+
end
64+
5465
def not_found
5566
raise ActionController::RoutingError.new('Not Found')
5667
rescue

0 commit comments

Comments
 (0)