Skip to content

Commit

Permalink
Strip [nil] from parameters hash.
Browse files Browse the repository at this point in the history
Thanks to Ben Murphy for reporting this!

CVE-2012-2660
  • Loading branch information
tenderlove committed May 30, 2012
1 parent 71f7917 commit dff6db1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
22 changes: 22 additions & 0 deletions actionpack/lib/action_dispatch/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,28 @@ def local?
LOCALHOST.any? { |local_ip| local_ip === remote_addr && local_ip === remote_ip }
end

protected

# Remove nils from the params hash
def deep_munge(hash)
hash.each_value do |v|
case v
when Array
v.grep(Hash) { |x| deep_munge(x) }
when Hash
deep_munge(v)
end
end

keys = hash.keys.find_all { |k| hash[k] == [nil] }
keys.each { |k| hash[k] = nil }
hash
end

def parse_query(qs)
deep_munge(super)
end

private

def check_method(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ def teardown
end

test "query string without equal" do
assert_parses({ "action" => nil }, "action")
assert_parses({"action" => nil}, "action")
assert_parses({"action" => {"foo" => nil}}, "action[foo]")
assert_parses({"action" => {"foo" => { "bar" => nil }}}, "action[foo][bar]")
assert_parses({"action" => {"foo" => { "bar" => nil }}}, "action[foo][bar][]")
assert_parses({"action" => {"foo" => nil}}, "action[foo][]")
assert_parses({"action"=>{"foo"=>[{"bar"=>nil}]}}, "action[foo][][bar]")
end

test "query string with empty key" do
Expand Down

0 comments on commit dff6db1

Please sign in to comment.