Skip to content

Commit 4d68f67

Browse files
committed
Merge branch '5-2-sec' into 5-2-stable
* 5-2-sec: Preparing for 5.2.4.6 release Update changelog Prevent slow regex when parsing host authorization header Prevent string polymorphic route arguments
2 parents fea508c + 2612683 commit 4d68f67

File tree

17 files changed

+298
-199
lines changed

17 files changed

+298
-199
lines changed

Gemfile.lock

Lines changed: 153 additions & 188 deletions
Large diffs are not rendered by default.

actioncable/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
* No changes.
44

55

6+
## Rails 5.2.4.6 (May 05, 2021) ##
7+
8+
* No changes.
9+
10+
611
## Rails 5.2.4.5 (February 10, 2021) ##
712

813
* No changes.

actionmailer/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
* No changes.
44

55

6+
## Rails 5.2.4.6 (May 05, 2021) ##
7+
8+
* No changes.
9+
10+
611
## Rails 5.2.4.5 (February 10, 2021) ##
712

813
* No changes.

actionpack/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@
2424
* No changes.
2525

2626

27+
## Rails 5.2.4.6 (May 05, 2021) ##
28+
29+
* Prevent regex DoS in HTTP token authentication
30+
CVE-2021-22904
31+
32+
* Prevent string polymorphic route arguments.
33+
34+
`url_for` supports building polymorphic URLs via an array
35+
of arguments (usually symbols and records). If a developer passes a
36+
user input array, strings can result in unwanted route helper calls.
37+
38+
CVE-2021-22885
39+
40+
*Gannon McGibbon*
41+
2742
## Rails 5.2.4.5 (February 10, 2021) ##
2843

2944
* No changes.

actionpack/lib/action_controller/metal/http_authentication.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def opaque(secret_key)
406406
module Token
407407
TOKEN_KEY = "token="
408408
TOKEN_REGEX = /^(Token|Bearer)\s+/
409-
AUTHN_PAIR_DELIMITERS = /(?:,|;|\t+)/
409+
AUTHN_PAIR_DELIMITERS = /(?:,|;|\t)/
410410
extend self
411411

412412
module ControllerMethods

actionpack/lib/action_dispatch/routing/polymorphic_routes.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,23 +288,27 @@ def handle_list(list)
288288

289289
args = []
290290

291-
route = record_list.map { |parent|
291+
route = record_list.map do |parent|
292292
case parent
293-
when Symbol, String
293+
when Symbol
294294
parent.to_s
295+
when String
296+
raise(ArgumentError, "Please use symbols for polymorphic route arguments.")
295297
when Class
296298
args << parent
297299
parent.model_name.singular_route_key
298300
else
299301
args << parent.to_model
300302
parent.to_model.model_name.singular_route_key
301303
end
302-
}
304+
end
303305

304306
route <<
305307
case record
306-
when Symbol, String
308+
when Symbol
307309
record.to_s
310+
when String
311+
raise(ArgumentError, "Please use symbols for polymorphic route arguments.")
308312
when Class
309313
@key_strategy.call record.model_name
310314
else

actionpack/test/controller/http_token_authentication_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ def authenticate_long_credentials
8989
assert_equal "HTTP Token: Access denied.\n", @response.body, "Authentication header was not properly parsed"
9090
end
9191

92+
test "authentication request with evil header" do
93+
@request.env["HTTP_AUTHORIZATION"] = "Token ." + " " * (1024*80-8) + "."
94+
Timeout.timeout(1) do
95+
get :index
96+
end
97+
98+
assert_response :unauthorized
99+
assert_equal "HTTP Token: Access denied.\n", @response.body, "Authentication header was not properly parsed"
100+
end
101+
92102
test "successful authentication request with Bearer instead of Token" do
93103
@request.env["HTTP_AUTHORIZATION"] = "Bearer lifo"
94104
get :index

actionpack/test/controller/redirect_test.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ def redirect_to_nil
108108
redirect_to nil
109109
end
110110

111+
def redirect_to_polymorphic
112+
redirect_to [:internal, Workshop.new(5)]
113+
end
114+
115+
def redirect_to_polymorphic_string_args
116+
redirect_to ["internal", Workshop.new(5)]
117+
end
118+
111119
def redirect_to_params
112120
redirect_to ActionController::Parameters.new(status: 200, protocol: "javascript", f: "%0Aeval(name)")
113121
end
@@ -310,6 +318,43 @@ def test_redirect_to_record
310318
end
311319
end
312320

321+
def test_polymorphic_redirect
322+
with_routing do |set|
323+
set.draw do
324+
namespace :internal do
325+
resources :workshops
326+
end
327+
328+
ActiveSupport::Deprecation.silence do
329+
get ":controller/:action"
330+
end
331+
end
332+
333+
get :redirect_to_polymorphic
334+
assert_equal "http://test.host/internal/workshops/5", redirect_to_url
335+
assert_redirected_to [:internal, Workshop.new(5)]
336+
end
337+
end
338+
339+
def test_polymorphic_redirect_with_string_args
340+
with_routing do |set|
341+
set.draw do
342+
namespace :internal do
343+
resources :workshops
344+
end
345+
346+
ActiveSupport::Deprecation.silence do
347+
get ":controller/:action"
348+
end
349+
end
350+
351+
error = assert_raises(ArgumentError) do
352+
get :redirect_to_polymorphic_string_args
353+
end
354+
assert_equal("Please use symbols for polymorphic route arguments.", error.message)
355+
end
356+
end
357+
313358
def test_redirect_to_nil
314359
error = assert_raise(ActionController::ActionControllerError) do
315360
get :redirect_to_nil

actionview/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
* No changes.
44

55

6+
## Rails 5.2.4.6 (May 05, 2021) ##
7+
8+
* No changes.
9+
10+
611
## Rails 5.2.4.5 (February 10, 2021) ##
712

813
* No changes.

actionview/test/activerecord/polymorphic_routes_test.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,6 @@ def test_with_array_containing_single_name
460460
end
461461
end
462462

463-
def test_with_array_containing_single_string_name
464-
with_test_routes do
465-
assert_url "http://example.com/projects", ["projects"]
466-
end
467-
end
468-
469463
def test_with_array_containing_symbols
470464
with_test_routes do
471465
assert_url "http://example.com/series/new", [:new, :series]
@@ -620,6 +614,22 @@ def test_nested_routing_to_a_model_delegate
620614
end
621615
end
622616

617+
def test_string_route_arguments
618+
with_admin_test_routes do
619+
error = assert_raises(ArgumentError) do
620+
polymorphic_url(["admin", @project])
621+
end
622+
623+
assert_equal("Please use symbols for polymorphic route arguments.", error.message)
624+
625+
error = assert_raises(ArgumentError) do
626+
polymorphic_url([@project, "bid"])
627+
end
628+
629+
assert_equal("Please use symbols for polymorphic route arguments.", error.message)
630+
end
631+
end
632+
623633
def with_namespaced_routes(name)
624634
with_routing do |set|
625635
set.draw do

0 commit comments

Comments
 (0)