File tree Expand file tree Collapse file tree 5 files changed +39
-2
lines changed
actionmailbox/app/controllers/action_mailbox
lib/action_controller/metal
railties/test/application Expand file tree Collapse file tree 5 files changed +39
-2
lines changed Original file line number Diff line number Diff line change 3
3
module ActionMailbox
4
4
# The base class for all Action Mailbox ingress controllers.
5
5
class BaseController < ActionController ::Base
6
- skip_forgery_protection if default_protect_from_forgery
6
+ skip_forgery_protection
7
7
8
8
before_action :ensure_configured
9
9
Original file line number Diff line number Diff line change
1
+ * Fix ` skip_forgery_protection ` to run without raising an error if forgery
2
+ protection has not been enabled / ` verify_authenticity_token ` is not a
3
+ defined callback.
4
+
5
+ This fix prevents the Rails 7.0 Welcome Page (` / ` ) from raising an
6
+ ` ArgumentError ` if ` default_protect_from_forgery ` is false.
7
+
8
+ * Brad Trick*
9
+
1
10
* Make ` redirect_to ` return an empty response body.
2
11
3
12
Application controllers that wish to add a response body after calling
Original file line number Diff line number Diff line change @@ -155,7 +155,7 @@ def protect_from_forgery(options = {})
155
155
#
156
156
# See +skip_before_action+ for allowed options.
157
157
def skip_forgery_protection ( options = { } )
158
- skip_before_action :verify_authenticity_token , options
158
+ skip_before_action :verify_authenticity_token , options . reverse_merge ( raise : false )
159
159
end
160
160
161
161
private
Original file line number Diff line number Diff line change @@ -190,6 +190,11 @@ class SkipProtectionController < ActionController::Base
190
190
attr_accessor :skip_requested
191
191
end
192
192
193
+ class SkipProtectionWhenUnprotectedController < ActionController ::Base
194
+ include RequestForgeryProtectionActions
195
+ skip_forgery_protection
196
+ end
197
+
193
198
# common test methods
194
199
module RequestForgeryProtectionTests
195
200
def setup
@@ -1121,3 +1126,14 @@ def assert_not_blocked(&block)
1121
1126
assert_response :success
1122
1127
end
1123
1128
end
1129
+
1130
+ class SkipProtectionWhenUnprotectedControllerTest < ActionController ::TestCase
1131
+ def test_should_allow_skip_request_when_protection_is_not_set
1132
+ assert_not_blocked { post :index }
1133
+ end
1134
+
1135
+ def assert_not_blocked ( &block )
1136
+ assert_nothing_raised ( &block )
1137
+ assert_response :success
1138
+ end
1139
+ end
Original file line number Diff line number Diff line change @@ -747,5 +747,17 @@ def index
747
747
get "/"
748
748
assert_equal 200 , last_response . status
749
749
end
750
+
751
+ test "request to rails/welcome is successful when default_protect_from_forgery is false" do
752
+ add_to_config <<-RUBY
753
+ config.action_dispatch.show_exceptions = false
754
+ config.action_controller.default_protect_from_forgery = false
755
+ RUBY
756
+
757
+ app "development"
758
+
759
+ get "/"
760
+ assert_equal 200 , last_response . status
761
+ end
750
762
end
751
763
end
You can’t perform that action at this time.
0 commit comments