From d5cd97baa44fa66dc681041a213092b45c57c32f Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 4 Jan 2013 12:02:22 -0800 Subject: * Strip nils from collections on JSON and XML posts. [CVE-2013-0155] * dealing with empty hashes. Thanks Damien Mathieu --- actionpack/lib/action_dispatch/http/request.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'actionpack/lib/action_dispatch/http/request.rb') diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index afc0496ef9..dea8e86808 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -247,18 +247,14 @@ 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) - keys = hash.keys.find_all { |k| hash[k] == [nil] } - keys.each { |k| hash[k] = nil } - - hash.each_value do |v| + hash.each do |k, v| case v when Array v.grep(Hash) { |x| deep_munge(x) } v.compact! + hash[k] = nil if v.empty? when Hash deep_munge(v) end @@ -267,6 +263,8 @@ module ActionDispatch hash end + protected + def parse_query(qs) deep_munge(super) end -- cgit v1.2.3