aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-01-08 12:11:18 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2013-01-08 12:11:18 -0800
commit88cc1688d0cb828c17706b41a8bd27870f2a2beb (patch)
tree1001415a74aa4ba81cc8fc305f4cb7a0bc145afc /actionpack/lib/action_dispatch
parentf049016cd348627bf8db0d72382d7580bf802a79 (diff)
parent2ced6f2f8a85957b160710ae5d9fb245a6106550 (diff)
downloadrails-88cc1688d0cb828c17706b41a8bd27870f2a2beb.tar.gz
rails-88cc1688d0cb828c17706b41a8bd27870f2a2beb.tar.bz2
rails-88cc1688d0cb828c17706b41a8bd27870f2a2beb.zip
Merge branch 'master-sec'
* master-sec: CVE-2013-0156: Safe XML params parsing. Doesn't allow symbols or yaml. * Strip nils from collections on JSON and XML posts. [CVE-2013-0155] * dealing with empty hashes. Thanks Damien Mathieu
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/http/request.rb7
-rw-r--r--actionpack/lib/action_dispatch/middleware/params_parser.rb4
2 files changed, 6 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index 452809a689..31b36eedb0 100644
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -276,15 +276,14 @@ module ActionDispatch
LOCALHOST =~ remote_addr && LOCALHOST =~ remote_ip
end
- protected
-
# Remove nils from the params hash
def deep_munge(hash)
- 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
@@ -293,6 +292,8 @@ module ActionDispatch
hash
end
+ protected
+
def parse_query(qs)
deep_munge(super)
end
diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb
index 2c98ca03a8..951f28f535 100644
--- a/actionpack/lib/action_dispatch/middleware/params_parser.rb
+++ b/actionpack/lib/action_dispatch/middleware/params_parser.rb
@@ -47,12 +47,12 @@ module ActionDispatch
when Proc
strategy.call(request.raw_post)
when :xml_simple, :xml_node
- data = Hash.from_xml(request.raw_post) || {}
+ data = request.deep_munge(Hash.from_xml(request.body.read) || {})
data.with_indifferent_access
when :yaml
YAML.load(request.raw_post)
when :json
- data = ActiveSupport::JSON.decode(request.raw_post)
+ data = request.deep_munge ActiveSupport::JSON.decode(request.body)
data = {:_json => data} unless data.is_a?(Hash)
data.with_indifferent_access
else