Skip to content

Commit

Permalink
Return self when calling #each, #each_pair, and #each_value instead o…
Browse files Browse the repository at this point in the history
…f the raw @parameters hash

[CVE-2020-8164]
  • Loading branch information
JackMc authored and tenderlove committed May 15, 2020
1 parent 17507e8 commit b3230c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions actionpack/lib/action_controller/metal/strong_parameters.rb
Expand Up @@ -344,6 +344,8 @@ def each_pair(&block)
@parameters.each_pair do |key, value|
yield [key, convert_hashes_to_parameters(key, value)]
end

self
end
alias_method :each, :each_pair

Expand All @@ -353,6 +355,8 @@ def each_value(&block)
@parameters.each_pair do |key, value|
yield convert_hashes_to_parameters(key, value)
end

self
end

# Attribute that keeps track of converted arrays, if any, to avoid double
Expand Down
12 changes: 12 additions & 0 deletions actionpack/test/controller/parameters/accessors_test.rb
Expand Up @@ -19,6 +19,18 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
)
end

test "each returns self" do
assert_same @params, @params.each { |_| _ }
end

test "each_pair returns self" do
assert_same @params, @params.each_pair { |_| _ }
end

test "each_value returns self" do
assert_same @params, @params.each_value { |_| _ }
end

test "[] retains permitted status" do
@params.permit!
assert_predicate @params[:person], :permitted?
Expand Down

0 comments on commit b3230c5

Please sign in to comment.