File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
lib/action_controller/metal Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -106,13 +106,14 @@ def redirect_to(options = {}, response_options = {})
106
106
107
107
allow_other_host = response_options . delete ( :allow_other_host ) { _allow_other_host }
108
108
109
- self . status = _extract_redirect_to_status ( options , response_options )
109
+ proposed_status = _extract_redirect_to_status ( options , response_options )
110
110
111
111
redirect_to_location = _compute_redirect_to_location ( request , options )
112
112
_ensure_url_is_http_header_safe ( redirect_to_location )
113
113
114
114
self . location = _enforce_open_redirect_protection ( redirect_to_location , allow_other_host : allow_other_host )
115
115
self . response_body = ""
116
+ self . status = proposed_status
116
117
end
117
118
118
119
# Soft deprecated alias for #redirect_back_or_to where the `fallback_location`
Original file line number Diff line number Diff line change @@ -203,6 +203,14 @@ def redirect_with_null_bytes
203
203
redirect_to "\000 /lol\r \n wat"
204
204
end
205
205
206
+ def redirect_to_external_with_rescue
207
+ begin
208
+ redirect_to "http://www.rubyonrails.org/" , allow_other_host : false
209
+ rescue ActionController ::Redirecting ::UnsafeRedirectError
210
+ render plain : "caught error"
211
+ end
212
+ end
213
+
206
214
def rescue_errors ( e ) raise e end
207
215
208
216
private
@@ -617,6 +625,11 @@ def test_redirect_to_instrumentation
617
625
assert_equal "http://test.host/redirect/hello_world" , payload [ :location ]
618
626
end
619
627
628
+ def test_redirect_to_external_with_rescue
629
+ get :redirect_to_external_with_rescue
630
+ assert_response :ok
631
+ end
632
+
620
633
private
621
634
def with_raise_on_open_redirects
622
635
old_raise_on_open_redirects = ActionController ::Base . raise_on_open_redirects
You can’t perform that action at this time.
0 commit comments