Strip [nil] from parameters hash.

Thanks to Ben Murphy for reporting this!

CVE-2012-2660
This commit is contained in:
Aaron Patterson
2012-05-30 15:13:03 -07:00
parent 71f7917c55
commit dff6db1884
2 changed files with 28 additions and 1 deletions

View File

@@ -247,6 +247,28 @@ module ActionDispatch
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)

View File

@@ -81,7 +81,12 @@ class QueryStringParsingTest < ActionDispatch::IntegrationTest
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