https://github.com/jamis/safe_mass_assignment
ActiveRecord plugin for allowing (careful) mass assignment of protected attributes, separate from values provided via users of your application.
https://github.com/jamis/safe_mass_assignment
Last synced: 7 months ago
JSON representation
ActiveRecord plugin for allowing (careful) mass assignment of protected attributes, separate from values provided via users of your application.
- Host: GitHub
- URL: https://github.com/jamis/safe_mass_assignment
- Owner: jamis
- Created: 2009-04-12T22:29:42.000Z (about 17 years ago)
- Default Branch: master
- Last Pushed: 2011-05-11T13:52:06.000Z (about 15 years ago)
- Last Synced: 2025-04-23T20:19:24.176Z (about 1 year ago)
- Language: Ruby
- Homepage:
- Size: 108 KB
- Stars: 55
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
Awesome Lists containing this project
README
= Safe Mass Assignment
== SUMMARY:
Allows (careful) mass assignment of protected attributes, separate from values provided via users of your application.
== DESCRIPTION:
When creating models via ActiveRecord, it is good practice to use attr_protected or (even better) attr_accessible to prevent malicious (or clueless) users from assigning values to attributes that you did not intend to be assignable via the web interface. Unfortunately, this results in clumsy situations where you need your program to be able to assign to those attributes:
user.attributes = params[:user]
user.admin = true
user.save
This plugin adds a second parameter to create, update_attributes, and related, which will always mass-assign, regardless of attr_protected or attr_accessible:
user.update_attributes(params[:user], :admin => true)
Naturally, clueless programmers will still be able to make a muck of this, but as long as you ensure that the second parameter is never using values provided by the user, you'll be just as secure as if you were using the first (more verbose) version.
== SYNOPSIS:
Account.create(params[:account], :comped => true)
Account.create!(params[:account], :comped => true)
account.update_attributes(params[:account], :comped => true)
account.update_attributes!(params[:account], :comped => true)
account.users.create(params[:user], :admin => true)
account.users.create!(params[:user], :admin => true)
== LICENSE:
(The MIT License)
Copyright (c) 2009 Jamis Buck
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.