Backport Rails 3.2.16 Security Fixes to Rails 3.1.x

This fixes the following CVEs based off of @NZKoz's work for [Rails 3.2.16](https://github.com/rails/rails/commit/64226302d82493d9bf67aa9e4fa52b4e0269ee3d)

* [CVE-2013-6417](https://groups.google.com/forum/#!topic/ruby-security-ann/niK4drpSHT4)
* [CVE-2013-4491](https://groups.google.com/forum/#!topic/ruby-security-ann/pLrh6DUw998)
* [CVE-2013-6415](https://groups.google.com/forum/#!topic/ruby-security-ann/9WiRn2nhfq0)
* [CVE-2013-6414](https://groups.google.com/forum/#!topic/ruby-security-ann/A-ebV4WxzKg)