This project is archived and is in readonly mode.
Mass Assignment Security Refactoring
-
Eric Chapweske
- Tag changed from patch to activerecord, patch
-
Michael Koziarski
- Milestone cleared.
- Assigned user set to Michael Koziarski
Hey Eric,
This looks like a really awesome refactoring.
I especially like the way they're tested independently of active record's own attributes= method. Could you also include an example in the documentation for the sanitizer how you'd suggest using it in a controller.
CCing jeremy pratik and josh as I think this is good to go but would like to get more eyes on it.
Great work
-
Eric Chapweske
Thanks for the feedback! I've added the example documentation and also updated the implementation so that it can be extended for context-sensitive sanitization, as shown in the example in mass_assignment_security.rb. I would like to find a cleaner solution for this, but I think this approach requires the fewest API changes.
-
Eric Chapweske
Round 3. Hmmm, refactored the refactoring and expanded the documentation a bit. This simplifies the implementation significantly. Don't plan to make any other changes unless requested.
Also added mass_assignment_security/context.rb. I'd be happy to move it to a plugin, although I think it's pretty useful, and it's optional to include it.
Also rewrote multi-parameter assignment, the ticket is at #3317 Multi-parameter assignment refactoring
-
Eric Chapweske
And the patch:
-
Eric Chapweske
Any chance of this making it in the next release? Hoping to utilize this in the near future.
Thanks!
-Eric -
Rizwan Reza
- Tag changed from activerecord, patch to activerecord, bugmash, patch
The patch doesn't apply cleanly anymore.
-
Eric Chapweske
New patch against master.
-
Eric Chapweske
Oh, this patch also modifies the documentation. Removed advise about using Hash.slice, and replaced it with this:
# Note that using <tt>Hash#except</tt> or <tt>Hash#slice</tt> in place of +attr_accessible+ # to sanitize attributes won't provide sufficient protection.Edited by Rohit Arondekar for formating.
-
Jeremy Kemper
- State changed from new to open
This is nice and it works for me. The code style is different from the rest of Rails though: extra spaces padding class declarations, no indentation after protected/private. It's nit-picking, I know, but let's keep it uniform.
-
Eric Chapweske
Woops. Adding indentation for private/protected and no spaces between modules and classes.
-
Eric Chapweske
Bleh, scratch that -- this patch has a bug in it -- but I expect the style is correct :)
-
joshsz
FWIW, this patch is no longer applying cleanly to master:
$ git apply /tmp/mass_assign_clean.diff -v (...) Checking patch activerecord/lib/active_record/base.rb... error: while searching for: extend ActiveModel::Naming extend QueryCache::ClassMethods extend ActiveSupport::Benchmarkable include Validations include Locking::Optimistic, Locking::Pessimistic error: patch failed: activerecord/lib/active_record/base.rb:2378 error: activerecord/lib/active_record/base.rb: patch does not apply (...) -
Rohit Arondekar
- Importance changed from to Medium
Any updates to this ticket? Eric did you manage to fix that bug?
-
José Valim
- Assigned user changed from Michael Koziarski to José Valim
- State changed from open to resolved
Hoooray, applied!
