Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
attr_accessible on some properties + attr_protected on others makes class 'open-by-default'
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Uberbrady  
View profile   Translate to Translated (View Original)
 More options Jul 9 2012, 6:19 pm
From: Uberbrady <uberbr...@gmail.com>
Date: Mon, 9 Jul 2012 15:19:12 -0700 (PDT)
Local: Mon, Jul 9 2012 6:19 pm
Subject: attr_accessible on some properties + attr_protected on others makes class 'open-by-default'

(I posted this as a bug in GitHub
(https://github.com/rails/rails/issues/7018), but then someone there told
me I should post it here, so here it is.)

If you set attr_accessible on some properties in an ActiveRecord-descended
class, and then attr_protected on others - the class becomes 'default-open'
- if any properties are missed or added later, they will be accessible by
default to MassAssignment.

This undoes the entire point of having put attr_accessible in one's class.

Two possible solutions -

#1) 'default-closed' - the attr_protected statements will either be
ignored, or just used to override attr_accessiblefor a particular property.
#2) 'explicit-only' - any attribute accessed in mass-assignment that is not
explicitly mentioned in eitherattr_accessible or attr_protected raises a
new error - something like
 MassAssignmentError:AttributeNotExplicitlyDeclared. Maybe even throw an
error if the attribute is accessed in*any* way (mything.whatever="boo"; #
kerplow! throws error?) though that might perform poorly.

Solution #1 is probably fine - accesses to not attr_accessible properties
will throw a MassAssignment error under these circumstances anyways.
Solution #2 just makes things really explicit, which some might want for
some kinds of high-security applications.

I found this bug in my own code during the development cycle; I liked
putting both attr_accessible andattr_protected in for symmetry and to
remind me of my DB schema at the top. Stupid reason, I know. I found that a
belongs_to relation was unprotected in that circumstance.

-B.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Prem Sichanugrist  
View profile   Translate to Translated (View Original)
 More options Jul 9 2012, 9:38 pm
From: Prem Sichanugrist <sikand...@gmail.com>
Date: Mon, 9 Jul 2012 21:38:12 -0400
Local: Mon, Jul 9 2012 9:38 pm
Subject: Re: [Rails-core] attr_accessible on some properties + attr_protected on others makes class 'open-by-default'
I personally think we should deprecate attr_protected, and go with
whitelisting only (attr_accessible + strong_parameters) route. I think
it make more sense from the security standpoint, and all the exploit
we have seen.

Core teams, wdyt?

- Prem


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Brown  
View profile  
 More options Jul 9 2012, 9:57 pm
From: Peter Brown <p...@lette.us>
Date: Mon, 9 Jul 2012 18:57:44 -0700 (PDT)
Local: Mon, Jul 9 2012 9:57 pm
Subject: Re: [Rails-core] attr_accessible on some properties + attr_protected on others makes class 'open-by-default'

Just a guy with an opinion weighing in... I would love to see
attr_protected removed. The official Rails Guide on security<http://guides.rubyonrails.org/security.html#countermeasures> calls
attr_accessible "A much better way", and I don't think Michael Hartl's
popular Ruby on Rails Tutorial <http://ruby.railstutorial.org/> even
mentions attr_protected. I think it gives people a false sense of security,
especially in a large application where it's easy to forget to update it
when new fields are added.

- Pete


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ryan Bigg  
View profile   Translate to Translated (View Original)
 More options Jul 10 2012, 1:45 am
From: Ryan Bigg <radarliste...@gmail.com>
Date: Tue, 10 Jul 2012 15:45:28 +1000
Local: Tues, Jul 10 2012 1:45 am
Subject: Re: [Rails-core] attr_accessible on some properties + attr_protected on others makes class 'open-by-default'

For the record: I don't mention attr_protected at all in Rails 3 in Action either.

+1 to removing attr_protected.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Xavier Noria  
View profile  
 More options Jul 10 2012, 3:39 am
From: Xavier Noria <f...@hashref.com>
Date: Tue, 10 Jul 2012 09:39:15 +0200
Local: Tues, Jul 10 2012 3:39 am
Subject: Re: [Rails-core] attr_accessible on some properties + attr_protected on others makes class 'open-by-default'

Sometimes you have a table with a bunch of regular data and one single FK
to protect. I don't think forcing users to whitelist that model is a good
idea.

I prefer Rails to provide both options (three if you count declaring
nothing) and leave the judgement of what's appropriate in every situation
to the user.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Breen  
View profile   Translate to Translated (View Original)
 More options Jul 10 2012, 7:11 am
From: Michael Breen <hard...@gmail.com>
Date: Tue, 10 Jul 2012 07:11:14 -0400
Local: Tues, Jul 10 2012 7:11 am
Subject: Re: [Rails-core] attr_accessible on some properties + attr_protected on others makes class 'open-by-default'

I'd like to see attr_protected stick around. There are times I'm working with models and I don't want to communicate the15 fields that can be written to but rather the two fields that can't.

Best.
Mike

On Jul 10, 2012, at 1:45 AM, Ryan Bigg <radarliste...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jay Feldblum  
View profile   Translate to Translated (View Original)
 More options Jul 10 2012, 9:59 am
From: Jay Feldblum <yfeldb...@gmail.com>
Date: Tue, 10 Jul 2012 06:59:01 -0700 (PDT)
Local: Tues, Jul 10 2012 9:59 am
Subject: Re: attr_accessible on some properties + attr_protected on others makes class 'open-by-default'

In this type of case, it makes sense either to declare a whitelist or to
declare a blacklist. But it doesn't make much sense to declare both of them.

Solution #3: ActiveRecord (or ActiveModel) should raise if a class declares
both a whitelist and a blacklist of mass-assignable attributes.

class Comment
    attr_accessible: title
    attr_protected: author_id # raises immediately
end

Cheers,
Jay


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rafael Mendonça França  
View profile  
 More options Jul 10 2012, 10:03 am
From: Rafael Mendonça França <rafaelmfra...@gmail.com>
Date: Tue, 10 Jul 2012 11:03:18 -0300
Local: Tues, Jul 10 2012 10:03 am
Subject: Re: [Rails-core] Re: attr_accessible on some properties + attr_protected on others makes class 'open-by-default'

Jay, this solution doesn't play nice with inheritance.

Rafael Mendonça França
http://twitter.com/rafaelfranca
https://github.com/rafaelfranca


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Prem Sichanugrist  
View profile   Translate to Translated (View Original)
 More options Jul 10 2012, 12:29 pm
From: Prem Sichanugrist <sikand...@gmail.com>
Date: Tue, 10 Jul 2012 12:29:59 -0400
Local: Tues, Jul 10 2012 12:29 pm
Subject: Re: [Rails-core] attr_accessible on some properties + attr_protected on others makes class 'open-by-default'

Yeah, Jay. Your solution won't work with inheritance.

By deprecating the attr_protected, you can allow most of the attributes anyway (but seriously seriously seriously discouraged) by do something like:

   attr_accessible columns - [:created_at, :updated_at]

Having attr_accessible and attr_protected together in the same model is just asking for the trouble. You tell the model to whitelist, then you tell it again to blacklist.

- Prem

On Jul 10, 2012, at 10:03 AM, Rafael Mendonça França <rafaelmfra...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jay Feldblum  
View profile  
 More options Jul 10 2012, 12:35 pm
From: Jay Feldblum <y_feldb...@yahoo.com>
Date: Tue, 10 Jul 2012 12:35:40 -0400
Local: Tues, Jul 10 2012 12:35 pm
Subject: Re: [Rails-core] attr_accessible on some properties + attr_protected on others makes class 'open-by-default'

Prem,

What's the conflict with inheritance?

Cheers,
Jay

On Tue, Jul 10, 2012 at 12:29 PM, Prem Sichanugrist <sikand...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Jones  
View profile   Translate to Translated (View Original)
 More options Jul 10 2012, 1:17 pm
From: Matt Jones <al2o...@gmail.com>
Date: Tue, 10 Jul 2012 13:17:50 -0400
Local: Tues, Jul 10 2012 1:17 pm
Subject: Re: [Rails-core] attr_accessible on some properties + attr_protected on others makes class 'open-by-default'

On Jul 10, 2012, at 12:29 PM, Prem Sichanugrist wrote:

> Yeah, Jay. Your solution won't work with inheritance.

> By deprecating the attr_protected, you can allow most of the attributes anyway (but seriously seriously seriously discouraged) by do something like:

>    attr_accessible columns - [:created_at, :updated_at]

Note that this may die in exciting ways if you put it in a model that hasn't been created in the DB yet. (since columns looks at the table metadata)

--Matt Jones


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions Older topic »