diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2016-08-04 11:15:03 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2016-08-11 13:29:47 -0700 |
commit | 1663bab3a9a1d898386a5f401a56ef8191cec3be (patch) | |
tree | 3fa7525b4eda1d3f7aa485bcf1fff66c258f7aa6 | |
parent | be68f180917808597f2cc9bfa8f58a45b955504a (diff) | |
download | rails-1663bab3a9a1d898386a5f401a56ef8191cec3be.tar.gz rails-1663bab3a9a1d898386a5f401a56ef8191cec3be.tar.bz2 rails-1663bab3a9a1d898386a5f401a56ef8191cec3be.zip |
Integration test to prevent regression for the 5th time
Fix unsafe query generation risk.
Redo of CVE-2012-2660, CVE-2012-2694 and CVE-2013-0155
CVE-2016-6317
-rw-r--r-- | railties/test/json_params_parsing_test.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/railties/test/json_params_parsing_test.rb b/railties/test/json_params_parsing_test.rb new file mode 100644 index 0000000000..eac731a942 --- /dev/null +++ b/railties/test/json_params_parsing_test.rb @@ -0,0 +1,47 @@ +require "abstract_unit" +require "action_dispatch" +require "active_record" + +class JsonParamsParsingTest < ActionDispatch::IntegrationTest + test "prevent null query" do + # Make sure we have data to find + klass = Class.new(ActiveRecord::Base) do + def self.name; 'Foo'; end + establish_connection adapter: "sqlite3", database: ":memory:" + connection.create_table "foos" do |t| + t.string :title + t.timestamps null: false + end + end + klass.create + assert klass.first + + app = ->(env) { + request = ActionDispatch::Request.new env + params = ActionController::Parameters.new request.parameters + if params[:t] + klass.find_by_title(params[:t]) + else + nil + end + } + + assert_nil app.call(make_env({ 't' => nil })) + assert_nil app.call(make_env({ 't' => [nil] })) + + [[[nil]], [[[nil]]]].each do |data| + assert_nil app.call(make_env({ 't' => data })) + end + end + + private + def make_env json + data = JSON.dump json + content_length = data.length + { + 'CONTENT_LENGTH' => content_length, + 'CONTENT_TYPE' => 'application/json', + 'rack.input' => StringIO.new(data) + } + end +end |