1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

28 commits

Author SHA1 Message Date
Prem Sichanugrist
61fff0e23b Add AC::Parameters#to_unsafe_h
As suggested in #16299([1]), this method should be a new public API for
retrieving unfiltered parameters from `ActionController::Parameters`
object, given that `Parameters#to_hash` will no longer work in Rails
5.0+ as we stop inheriting `Parameters` from `Hash`.

[1]: https://github.com/rails/rails/pull/16299#issuecomment-50220919
2014-12-12 18:52:10 +07:00
Prem Sichanugrist
0663e8f179 Seperate Parameters accessors and mutators tests 2014-08-18 20:42:46 -04:00
Prem Sichanugrist
bd7f47190e Add missing Hash methods to AC::Parameters
This is to make sure that `permitted` status is maintained on the
resulting object.

I found these methods that needs to be redefined by looking for
`self.class.new` in the code.

* extract!
* transform_keys
* transform_values
2014-08-18 20:42:45 -04:00
Prem Sichanugrist
5109740c6b Make AC::Params#to_h return Hash with safe keys
`ActionController::Parameters#to_h` now returns a `Hash` with
unpermitted keys removed. This change is to reflect on a security
concern where some method performed on an `ActionController::Parameters`
may yield a `Hash` object which does not maintain `permitted?` status.
If you would like to get a `Hash` with all the keys intact, duplicate
and mark it as permitted before calling `#to_h`.

    params = ActionController::Parameters.new(name: 'Senjougahara Hitagi')
    params.to_h # => {}

    unsafe_params = params.dup.permit!
    unsafe_params.to_h # => {"name"=>"Senjougahara Hitagi"}

    safe_params = params.permit(:name)
    safe_params.to_h # => {"name"=>"Senjougahara Hitagi"}

This change is consider a stopgap as we cannot chage the code to stop
`ActionController::Parameters` to inherit from
`HashWithIndifferentAccess` in the next minor release.

Also, adding a CHANGELOG entry to mention that
`ActionController::Parameters` will not inheriting from
`HashWithIndifferentAccess` in the next major version.
2014-08-18 20:42:45 -04:00
Xavier Noria
f84d081faf adds some details to the rationale of converted_arrays [ci skip] 2014-06-07 13:30:03 +02:00
Xavier Noria
f712f89961 adds a regression test for the strong params converted arrays cache
This is a regression test for 29844dd.
2014-06-07 13:19:16 +02:00
Xavier Noria
1ecada20d1 Revert "Convert StrongParameters cache to a hash. This fixes an unbounded"
We cannot cache keys because arrays are mutable. We rather want to cache
the arrays. This behaviour is tailor-made for the usage pattern strongs
params is designed for.

In a forthcoming commit I am going to add a test that covers why we need
to cache by value.

Every strong params instance has a live span of a request, the cache goes
away with the object. Since strong params have such a concrete intention,
it would be interesting to see if there are actually any real-world use
cases that are an actual leak, one that practically may matter.

I am not convinced that the theoretical leak has any practical consequences,
but if it can be shown there are, then I believe we should either get rid of
the cache (which is an optimization), or else wipe it in the mutating API.

This reverts commit e63be2769c.
2014-06-07 13:19:16 +02:00
Ryan Davis
e63be2769c Convert StrongParameters cache to a hash. This fixes an unbounded
memory leak demonstrated on @tenderlove's latest blog post:

http://tenderlovemaking.com/2014/06/02/yagni-methods-are-killing-me.html
2014-06-03 16:57:22 -07:00
Xavier Noria
fa0380cb4a AC::Parameters#permit! permits hashes in array values 2013-12-23 22:55:03 +01:00
Xavier Noria
273045d6d5 optimizes array conversion in AC::Parameters 2013-12-21 14:22:08 +01:00
Xavier Noria
92f9ff8cc3 converts hashes in arrays of unfiltered params to unpermitted params [fixes #13382] 2013-12-21 01:16:38 +01:00
Doug Cole
7171111d3a don't mutate hash with fetch 2013-10-26 19:22:31 -07:00
Vasiliy Ermolovich
1d375e59f1 do not break params filtering on nil values
closes #12149
2013-09-07 15:16:45 +03:00
Fabio Kreusch
fa9ec0a678 Rack::Test::UploadedFile is a permitted scalar 2013-02-21 11:00:26 -03:00
Xavier Noria
8ac94d7c89 ActionDispatch::Http::UploadedFile is a permitted scalar [Closes #9051] 2013-01-23 23:15:26 +01:00
Rafael Mendonça França
cb56c39b51 Lets kepp using Ruby 1.9 syntax 2013-01-22 10:40:33 -02:00
Carlos Antonio da Silva
e0cc7ab3ff Add missing assert calls 2013-01-20 22:03:31 -02:00
Xavier Noria
cbec22ce57 strong parameters filters permitted scalars 2013-01-20 17:59:53 +01:00
Benjamin Quorning
478d80fd57 Test that permitted? is sticky on accessors, mutators, and merges 2012-11-06 21:30:12 +01:00
Benjamin Quorning
1a0f14e045 Test that not permitted is sticky on #except 2012-11-06 21:24:14 +01:00
Benjamin Quorning
93eaffe59b Current tests are testing stickiness of non-permitted parameters 2012-11-06 21:23:24 +01:00
Benjamin Quorning
5b3b9b0ebc Fix buggy tests 2012-11-06 21:22:57 +01:00
David Heinemeier Hansson
750a30b19f No need for the debugger 2012-10-31 16:35:20 +01:00
David Heinemeier Hansson
954c350daf Allow #permit to take its list of permitted parameters as an array 2012-10-31 16:33:54 +01:00
dfens
ab9140ff02 Cleanup trailing whitespaces 2012-10-12 09:56:39 +02:00
Brendan Loudermilk
1aa522dc4e ActionController::Parameters#permit! is recursive 2012-10-04 11:51:08 -07:00
Guillermo Iguaran
1aaf4490b2 Add config.action_controller.permit_all_attributes to bypass StrongParameters protection 2012-09-16 23:58:21 -05:00
Guillermo Iguaran
1e1bee3ab9 Change tainted/untainted wording to permitted/forbidden 2012-09-16 23:58:21 -05:00
Renamed from actionpack/test/controller/parameters/parameters_taint_test.rb (Browse further)