Ruby on Rails: Secure Mass Assignment
stephensclafani.com
stephensclafani.com
# config/initializers/disable_mass_assignment.rb
ActiveRecord::Base.send(:attr_accessible, nil)
# app/models/some_model.rb
class SomeModel < ActiveRecord::Base
attr_accessible :whitelisted, :attributes
endBy default, all attributes should have been inaccessible to ActiveRecord::Base#new and ActiveRecord::Base#update. That was a design-level mistake.
The particular solution outlined in the OP is quite incomplete. We need a check not see just which attributes can be edited by a user, but which rows can be edited by a user. attr_accessible offers no protection there.
And Rails is highlighting the fact that "allowed by default" is convenient, while the post highlights the fact that "allowed by default" is insecure :-)
Uhh...if it is in most other frameworks, as I claim, and you don't deny, then it is not Rails-specific.
http://blog.mhartl.com/2008/09/21/mass-assignment-in-rails-a...
and
http://blog.mhartl.com/2008/09/21/finding-and-fixing-mass-as...
for a much more detailed discussion of this issue.
Would this be a valid change to Rails. All belongs_to attributes are by default not accessible to mass assignment?
http://railscasts.com/episodes/26-hackers-love-mass-assignme...
Better idea: just set the attributes you want explicitly in the controller. Then your forms will never set data that you don't want it to.
http://github.com/ryanb/trusted-params
That should fix this problem for apps that use the plugin.