<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Rails 2.3 Nested Object Forms: I&#8217;m not Crazy about Them</title>
	<atom:link href="http://blog.smartlogicsolutions.com/2009/02/24/rails-23-nested-object-forms-im-not-crazy-about-them/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smartlogicsolutions.com/2009/02/24/rails-23-nested-object-forms-im-not-crazy-about-them/</link>
	<description>News and updates from the people at SmartLogic Solutions</description>
	<lastBuildDate>Mon, 15 Mar 2010 20:35:39 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Gaspard Bucher</title>
		<link>http://blog.smartlogicsolutions.com/2009/02/24/rails-23-nested-object-forms-im-not-crazy-about-them/comment-page-1/#comment-846</link>
		<dc:creator>Gaspard Bucher</dc:creator>
		<pubDate>Wed, 04 Mar 2009 07:22:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=529#comment-846</guid>
		<description>I really like the idea to force the use of attr_accessible (maybe with something like routable_attributes http://tinyurl.com/b6t3zv in case you use dynamic attributes that you could not list).

In the case of nested_attributes, it&#039;s very good to explicitly allow them so that you can allow setting the preferences of a user through user but disallow the reverse.

class User
  attr_accessible  :preferences_attributes
end

class Preference
  # nested disallowed from here
end</description>
		<content:encoded><![CDATA[<p>I really like the idea to force the use of attr_accessible (maybe with something like routable_attributes <a href="http://tinyurl.com/b6t3zv" rel="nofollow">http://tinyurl.com/b6t3zv</a> in case you use dynamic attributes that you could not list).</p>
<p>In the case of nested_attributes, it&#8217;s very good to explicitly allow them so that you can allow setting the preferences of a user through user but disallow the reverse.</p>
<p>class User<br />
  attr_accessible  :preferences_attributes<br />
end</p>
<p>class Preference<br />
  # nested disallowed from here<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Trupiano</title>
		<link>http://blog.smartlogicsolutions.com/2009/02/24/rails-23-nested-object-forms-im-not-crazy-about-them/comment-page-1/#comment-845</link>
		<dc:creator>John Trupiano</dc:creator>
		<pubDate>Tue, 03 Mar 2009 12:59:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=529#comment-845</guid>
		<description>@Gaspard, I think you&#039;ve summed it up very nicely.  Because of the complexity of the domain of authorization, we don&#039;t have it built into rails (which is likely a good thing).  I&#039;d think we&#039;d have a tough time building a generic authorization layer that actually provided any utility.

That said, the question turns back to whether or not we think that this mass assignment vulnerability is worth addressing.  Out of curiosity, what did you think of my suggestion on the rails-core list?  Specifically turning off mass assignment by default, and requiring developers to open it up with attr_accessible declarations (I also suggested that the generators could be updated to include this attr_accessible declaration, bringing more visibility to the vulernability).  Do you think there&#039;s value in this, and if not, why?</description>
		<content:encoded><![CDATA[<p>@Gaspard, I think you&#8217;ve summed it up very nicely.  Because of the complexity of the domain of authorization, we don&#8217;t have it built into rails (which is likely a good thing).  I&#8217;d think we&#8217;d have a tough time building a generic authorization layer that actually provided any utility.</p>
<p>That said, the question turns back to whether or not we think that this mass assignment vulnerability is worth addressing.  Out of curiosity, what did you think of my suggestion on the rails-core list?  Specifically turning off mass assignment by default, and requiring developers to open it up with attr_accessible declarations (I also suggested that the generators could be updated to include this attr_accessible declaration, bringing more visibility to the vulernability).  Do you think there&#8217;s value in this, and if not, why?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gaspard Bucher</title>
		<link>http://blog.smartlogicsolutions.com/2009/02/24/rails-23-nested-object-forms-im-not-crazy-about-them/comment-page-1/#comment-843</link>
		<dc:creator>Gaspard Bucher</dc:creator>
		<pubDate>Tue, 03 Mar 2009 08:56:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=529#comment-843</guid>
		<description>It seems the url did not show correctly in the previous post: http://tinyurl.com/bfvpks</description>
		<content:encoded><![CDATA[<p>It seems the url did not show correctly in the previous post: <a href="http://tinyurl.com/bfvpks" rel="nofollow">http://tinyurl.com/bfvpks</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gaspard Bucher</title>
		<link>http://blog.smartlogicsolutions.com/2009/02/24/rails-23-nested-object-forms-im-not-crazy-about-them/comment-page-1/#comment-842</link>
		<dc:creator>Gaspard Bucher</dc:creator>
		<pubDate>Tue, 03 Mar 2009 08:54:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=529#comment-842</guid>
		<description>@John, you are right, there is no golden rule.

In zena, access to users is controlled with a before filter in the controller since it&#039;s a very simple grant/refuse authorization scheme.

On the contrary, Node access (pages,notes,contacts,etc) is done with groups (like in UNIX). This means that when we follow links between nodes (children, other relations), we need to move with the visitor along and the authorization is then moved into the model.

I did not decide to go off the tracks and have an explicit visitor available in models just for fun. It makes testing harder and everyone says it&#039;s wrong. Apart from all these negative aspects, it&#039;s a very elegant solution when you have complexe workflows (publication/proposition/redaction) in a multiversion, group based authorisation scheme.

Another advantage is that you can write very clean authorization rules (http://tinyurl.com/bfvpks) that produce nice error messages in the forms (ajax) where the user tries to post forbidden data.

You could move such rules in the controller, but then it would need to know so much of the node&#039;s internals that it makes things worse.

As a rule of thumb, I would say that we need to move authorization to the part that knows the most about the necessary context. Sometimes it might be the controller because the session is the important part. Sometimes it should be the model because that&#039;s where the complexity lies.</description>
		<content:encoded><![CDATA[<p>@John, you are right, there is no golden rule.</p>
<p>In zena, access to users is controlled with a before filter in the controller since it&#8217;s a very simple grant/refuse authorization scheme.</p>
<p>On the contrary, Node access (pages,notes,contacts,etc) is done with groups (like in UNIX). This means that when we follow links between nodes (children, other relations), we need to move with the visitor along and the authorization is then moved into the model.</p>
<p>I did not decide to go off the tracks and have an explicit visitor available in models just for fun. It makes testing harder and everyone says it&#8217;s wrong. Apart from all these negative aspects, it&#8217;s a very elegant solution when you have complexe workflows (publication/proposition/redaction) in a multiversion, group based authorisation scheme.</p>
<p>Another advantage is that you can write very clean authorization rules (<a href="http://tinyurl.com/bfvpks" rel="nofollow">http://tinyurl.com/bfvpks</a>) that produce nice error messages in the forms (ajax) where the user tries to post forbidden data.</p>
<p>You could move such rules in the controller, but then it would need to know so much of the node&#8217;s internals that it makes things worse.</p>
<p>As a rule of thumb, I would say that we need to move authorization to the part that knows the most about the necessary context. Sometimes it might be the controller because the session is the important part. Sometimes it should be the model because that&#8217;s where the complexity lies.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Trupiano</title>
		<link>http://blog.smartlogicsolutions.com/2009/02/24/rails-23-nested-object-forms-im-not-crazy-about-them/comment-page-1/#comment-841</link>
		<dc:creator>John Trupiano</dc:creator>
		<pubDate>Mon, 02 Mar 2009 19:49:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=529#comment-841</guid>
		<description>@Gaspard, @Mina,

I&#039;ve long held the belief that models should be entirely session-independent.  In other words, they should not know who is logged in, or really that they (the models) are being consumed by a rails application.  I wrote my code such that controllers would orchestrate the permissions/authorization, and that the models were malleable pieces, unaware of roles/permissions/etc.

That said, the more I think about this, the more I&#039;m convinced that there isn&#039;t a golden rule for all of these cases.  Still, in the majority of my apps, authorization is best (and more appropriately I&#039;d argue) handled at the controller level.  However, in extreme cases where ACL&#039;s and the likes need to be implemented, there&#039;s no way around pushing authorization down to the model level.

As I noted earlier, perhaps we can take a few ideas from how roles/authorization are handled in my Michael Berkowitz&#039;s fork of the AASM gem: http://github.com/mikowitz/aasm

Though his implementation only deals with state transitions, it&#039;s easy to consider this idea being applied to the concept of editing a single field.

@Gaspard, I&#039;m also curious as to your approach for passing the &quot;current logged in user or access level&quot; to the model....this always felt very dirty to me (hence why I always advocated applying authorization at the controller level).

Also @Mina, I started a discussion on the core group about perhaps tweaking rails to protect against mass assignment by default.  Feel free to chime in there as well: http://groups.google.com/group/rubyonrails-core/browse_thread/thread/4e312a3de4c3579f</description>
		<content:encoded><![CDATA[<p>@Gaspard, @Mina,</p>
<p>I&#8217;ve long held the belief that models should be entirely session-independent.  In other words, they should not know who is logged in, or really that they (the models) are being consumed by a rails application.  I wrote my code such that controllers would orchestrate the permissions/authorization, and that the models were malleable pieces, unaware of roles/permissions/etc.</p>
<p>That said, the more I think about this, the more I&#8217;m convinced that there isn&#8217;t a golden rule for all of these cases.  Still, in the majority of my apps, authorization is best (and more appropriately I&#8217;d argue) handled at the controller level.  However, in extreme cases where ACL&#8217;s and the likes need to be implemented, there&#8217;s no way around pushing authorization down to the model level.</p>
<p>As I noted earlier, perhaps we can take a few ideas from how roles/authorization are handled in my Michael Berkowitz&#8217;s fork of the AASM gem: <a href="http://github.com/mikowitz/aasm" rel="nofollow">http://github.com/mikowitz/aasm</a></p>
<p>Though his implementation only deals with state transitions, it&#8217;s easy to consider this idea being applied to the concept of editing a single field.</p>
<p>@Gaspard, I&#8217;m also curious as to your approach for passing the &#8220;current logged in user or access level&#8221; to the model&#8230;.this always felt very dirty to me (hence why I always advocated applying authorization at the controller level).</p>
<p>Also @Mina, I started a discussion on the core group about perhaps tweaking rails to protect against mass assignment by default.  Feel free to chime in there as well: <a href="http://groups.google.com/group/rubyonrails-core/browse_thread/thread/4e312a3de4c3579f" rel="nofollow">http://groups.google.com/group/rubyonrails-core/browse_thread/thread/4e312a3de4c3579f</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mina Naguib</title>
		<link>http://blog.smartlogicsolutions.com/2009/02/24/rails-23-nested-object-forms-im-not-crazy-about-them/comment-page-1/#comment-840</link>
		<dc:creator>Mina Naguib</dc:creator>
		<pubDate>Mon, 02 Mar 2009 15:10:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=529#comment-840</guid>
		<description>@John 
Will take a look

@Gaspard
I agree regarding doing the authorization in the model, though not entirely with the approach you suggest.

I&#039;d feel more comfortable if the setter method is never called in the first place, as opposed to having it called and then try to do authorization later when .valid? is invoked - this is in case the setter has any side effects (hand-rolled setters, or nested mass assignment helpers for instance).

If we agree on the above, and if my understanding is correct, all mass-assignment methods (new/update_attributes) end up delegating to #attributes= at one point. Therefore, this is the place to inject the authorization logic to not invoke setters the visitor doesn&#039;t have access to invoke.

Regarding your exact suggested approach though, which already does a decent job attacking the problem: do you hand-roll the notion of &quot;visitor&quot; in your example in every rails app ? or are you aware of plugins to do this ? Also, how do you communicate the visitor from the controller to the model ?</description>
		<content:encoded><![CDATA[<p>@John<br />
Will take a look</p>
<p>@Gaspard<br />
I agree regarding doing the authorization in the model, though not entirely with the approach you suggest.</p>
<p>I&#8217;d feel more comfortable if the setter method is never called in the first place, as opposed to having it called and then try to do authorization later when .valid? is invoked &#8211; this is in case the setter has any side effects (hand-rolled setters, or nested mass assignment helpers for instance).</p>
<p>If we agree on the above, and if my understanding is correct, all mass-assignment methods (new/update_attributes) end up delegating to #attributes= at one point. Therefore, this is the place to inject the authorization logic to not invoke setters the visitor doesn&#8217;t have access to invoke.</p>
<p>Regarding your exact suggested approach though, which already does a decent job attacking the problem: do you hand-roll the notion of &#8220;visitor&#8221; in your example in every rails app ? or are you aware of plugins to do this ? Also, how do you communicate the visitor from the controller to the model ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gaspard Bucher</title>
		<link>http://blog.smartlogicsolutions.com/2009/02/24/rails-23-nested-object-forms-im-not-crazy-about-them/comment-page-1/#comment-838</link>
		<dc:creator>Gaspard Bucher</dc:creator>
		<pubDate>Mon, 02 Mar 2009 08:08:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=529#comment-838</guid>
		<description>All these scenarios and awful risks can be easily avoided if we accept that the security level should live in the model, not in the controller.

This simple assertion means that models know who is doing what to them when they are saved.

For example, you would have a validation that verifies that only admins can change the &quot;credit&quot;:

validate :only_admins_can_change_credit

def only_admins_can_change_credit
  errors.add(&#039;credit&#039;, &#039;cannot be changed&#039;) if credit_changed? &amp;&amp; !visitor.is_admin?
end</description>
		<content:encoded><![CDATA[<p>All these scenarios and awful risks can be easily avoided if we accept that the security level should live in the model, not in the controller.</p>
<p>This simple assertion means that models know who is doing what to them when they are saved.</p>
<p>For example, you would have a validation that verifies that only admins can change the &#8220;credit&#8221;:</p>
<p>validate :only_admins_can_change_credit</p>
<p>def only_admins_can_change_credit<br />
  errors.add(&#8217;credit&#8217;, &#8216;cannot be changed&#8217;) if credit_changed? &amp;&amp; !visitor.is_admin?<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Trupiano</title>
		<link>http://blog.smartlogicsolutions.com/2009/02/24/rails-23-nested-object-forms-im-not-crazy-about-them/comment-page-1/#comment-837</link>
		<dc:creator>John Trupiano</dc:creator>
		<pubDate>Sun, 01 Mar 2009 19:53:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=529#comment-837</guid>
		<description>As a followup, I&#039;ve beefed up the mass assignment section of the Securing Rails Applications guide: http://guides.rubyonrails.org/security.html#_mass_assignment

Mina, it&#039;s possible you may have more to contribute, so check it out if you have an opportunity.</description>
		<content:encoded><![CDATA[<p>As a followup, I&#8217;ve beefed up the mass assignment section of the Securing Rails Applications guide: <a href="http://guides.rubyonrails.org/security.html#_mass_assignment" rel="nofollow">http://guides.rubyonrails.org/security.html#_mass_assignment</a></p>
<p>Mina, it&#8217;s possible you may have more to contribute, so check it out if you have an opportunity.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Trupiano</title>
		<link>http://blog.smartlogicsolutions.com/2009/02/24/rails-23-nested-object-forms-im-not-crazy-about-them/comment-page-1/#comment-836</link>
		<dc:creator>John Trupiano</dc:creator>
		<pubDate>Thu, 26 Feb 2009 18:28:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=529#comment-836</guid>
		<description>@Jose, that&#039;s an interesting take-- I suppose I&#039;m not a fan of it from a &quot;style&quot; point of view....writing special save() methods for each set of restricted permissions will get cumbersome....then again, any fine-grained access control is going to get nasty, so maybe mine is not really a valid point.  

It&#039;s clear at this point that we do have suitable workarounds.  My two primary concerns at this point are: (1) can we make this safer out of the box? (2) regardless of (1), let&#039;s make sure we&#039;re making this information available.

I think Mina captured the shortcomings very well in his responses farther up.  A/R&#039;s attr_accessible and attr_protected are fantastic for the simple cases, but don&#039;t scale very well when you want finer access control.

A colleague of mine has been working on an AASM fork (http://github.com/mikowitz/aasm) that includes (among other things) the ability to restrict a transition to a specific set of &quot;roles.&quot;  While still early in development, I wonder if some of the ideas from that project might apply here....seems to share several similarities to this discussion, particularly as it relates to fine-grained access control.

@Ryan I&#039;m hoping to submit a doc patch this weekend for that guide.</description>
		<content:encoded><![CDATA[<p>@Jose, that&#8217;s an interesting take&#8211; I suppose I&#8217;m not a fan of it from a &#8220;style&#8221; point of view&#8230;.writing special save() methods for each set of restricted permissions will get cumbersome&#8230;.then again, any fine-grained access control is going to get nasty, so maybe mine is not really a valid point.  </p>
<p>It&#8217;s clear at this point that we do have suitable workarounds.  My two primary concerns at this point are: (1) can we make this safer out of the box? (2) regardless of (1), let&#8217;s make sure we&#8217;re making this information available.</p>
<p>I think Mina captured the shortcomings very well in his responses farther up.  A/R&#8217;s attr_accessible and attr_protected are fantastic for the simple cases, but don&#8217;t scale very well when you want finer access control.</p>
<p>A colleague of mine has been working on an AASM fork (<a href="http://github.com/mikowitz/aasm" rel="nofollow">http://github.com/mikowitz/aasm</a>) that includes (among other things) the ability to restrict a transition to a specific set of &#8220;roles.&#8221;  While still early in development, I wonder if some of the ideas from that project might apply here&#8230;.seems to share several similarities to this discussion, particularly as it relates to fine-grained access control.</p>
<p>@Ryan I&#8217;m hoping to submit a doc patch this weekend for that guide.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Sobol</title>
		<link>http://blog.smartlogicsolutions.com/2009/02/24/rails-23-nested-object-forms-im-not-crazy-about-them/comment-page-1/#comment-835</link>
		<dc:creator>Ryan Sobol</dc:creator>
		<pubDate>Thu, 26 Feb 2009 17:43:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=529#comment-835</guid>
		<description>@John - Thanks for bringing this security concern to the forefront of the developer community.  

+1 for a good write-up in the rails guides</description>
		<content:encoded><![CDATA[<p>@John &#8211; Thanks for bringing this security concern to the forefront of the developer community.  </p>
<p>+1 for a good write-up in the rails guides</p>
]]></content:encoded>
	</item>
</channel>
</rss>
