<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Nick Sieger: Security Threat Last Week</title>
    <link>http://blog.nicksieger.com/articles/2006/08/15/security-threat-last-week</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Security Threat Last Week</title>
      <description>&lt;p&gt;What was the biggest security threat story for me last week?  No, it
was not the &lt;a href="http://www.nytimes.com/2006/08/12/opinion/12sat1.html"&gt;disrupted liquid bomb plot&lt;/a&gt;, it was the &lt;a href="http://weblog.rubyonrails.com/2006/8/10/rails-1-1-6-backports-and-full-disclosure"&gt;Rails
security hole&lt;/a&gt; that caused quite a brouhaha among the Ruby
community.  (Guess that shows my increasing tendency to lose touch
with reality.  Maybe a sign of the miserable state of unrest in the
world and how living in the land of the world&amp;#8217;s only super-power makes
it easy to turn the other cheek?  Or&amp;#8230;ok, ok&amp;#8230;it&amp;#8217;s just me.)&lt;/p&gt;

&lt;p&gt;From my view of the Rails security issue, there are actually quite a
few interesting angles that came out of this story.&lt;/p&gt;

&lt;h2&gt;Rails is Growing Up&lt;/h2&gt;

&lt;p&gt;This is the obvious one.  The first major fault to be discovered in
Rails shows that Rails the codebase, Rails the core team, Rails the
technology stack, and Rails the community is going through growing
pains.  David was both praised and criticized widely for his handling
of the disclosure.  Many rightly complained that the initial
announcement didn&amp;#8217;t give system maintainers enough information to
decide whether the risk warranted disrupting normal operations to
spend time to test and roll out the patch.  This was compounded by the
fact that the initial announcement did not identify versions affected
and instead assumed all past versions, which turned out not to be the
case.&lt;/p&gt;

&lt;p&gt;Others thanked the Rails team for their discretion and trusted the
recommendation despite the fuzziness and lack of details.  These folks
either were able to perform the upgrade much more easily or had some
inkling of just how serious the issue was.&lt;/p&gt;

&lt;p&gt;The aftermath showed that the Rails core quickly learned from the
experience.  A &lt;a href="http://lists.rubyonrails.org/mailman/listinfo/rails-security"&gt;security mailing list&lt;/a&gt; and &lt;a href="http://groups.google.com/group/rails-security"&gt;google group&lt;/a&gt; were
set up for future incidents and David promised to apply more &lt;a href="http://weblog.rubyonrails.com/2006/8/10/rails-1-1-6-backports-and-full-disclosure"&gt;rigor
and policy&lt;/a&gt; to future announcements.&lt;/p&gt;

&lt;p&gt;It seems pretty obvious that the size of the gaffe was such that to
expose the details immediately would have had way too much potential
to cause widespread data loss and denial of service.  In fact, the
nature of the bug strikes me as one of those embarrassing bugs that
every software developer commits at one point in their coding life
where you amaze yourself at the short-sightedness of your
implementation.  I think the initial message could have been
dispatched with information on the severity of the threat without
necessarily disclosing the exact exploit.  So, essentially I agree
with the approach that was taken, but the message left out details
required to evaluate the threat.&lt;/p&gt;

&lt;h2&gt;Threat Analysis&lt;/h2&gt;

&lt;p&gt;Two early &lt;a href="http://blog.koehntopp.de/archives/1367-Ruby-On-Rails-Mandatory-Mystery-Patch.html"&gt;blog&lt;/a&gt; &lt;a href="http://blog.evanweaver.com/articles/2006/08/10/explanation-of-the-rails-security-vulnerability-in-1-1-4-others"&gt;posts&lt;/a&gt; came out the day after
claiming to know the details of the exploit.  It turned out that they
didn&amp;#8217;t quite understand what was afoot.  (Although Evan Weaver has
since updated &lt;a href="http://blog.evanweaver.com/articles/2006/08/10/explanation-of-the-rails-security-vulnerability-in-1-1-4-others"&gt;his post&lt;/a&gt; to clarify his original analysis.)&lt;/p&gt;

&lt;p&gt;The threat turned out to be a simple remote code execution issue.  The
&lt;code&gt;:controller&lt;/code&gt; dynamic expansion aspect of routing contained a bug that
allowed arbitrary .rb files in a Rails application to be executed
undesirably.  By far the most dramatic consequence would be
experienced if one&amp;#8217;s &lt;code&gt;db/schema.rb&lt;/code&gt; file were to be executed with a
request for &lt;code&gt;/db/schema&lt;/code&gt;, causing your entire database contents to be
dropped and reloaded.&lt;/p&gt;

&lt;p&gt;By examining the &lt;a href="http://dev.rubyonrails.org/svn/rails/tags/rel_1-1-4/actionpack/lib/action_controller/routing.rb"&gt;&lt;code&gt;safe_load_paths&lt;/code&gt;&lt;/a&gt; method defined in affected
versions, it appears that the implementation tried to limit elements
of the load path that matched the expanded &lt;code&gt;RAILS_ROOT&lt;/code&gt; of the
application.  Combine this with the fact that other elements of the
routing system eagerly &lt;code&gt;require&lt;/code&gt;&amp;#8216;d files with inadequate
bounds-checking spells your recipe for disaster.&lt;/p&gt;

&lt;p&gt;Many posters and commenters quipped that a simple &lt;code&gt;svn diff&lt;/code&gt; was
enough to give script kiddies or other black hats the information
needed to exploit the issue.  Or was it?  Given that the two early
analyses turned out to be off the mark, were people in the know
exercising more discretion by not disclosing more details? &lt;/p&gt;

&lt;p&gt;Personally, I spent more than an hour staring at the affected routing
code trying to untangle the various metaprogramming tricks and regular
expressions that make up the Rails routing system.  And I consider
myself fairly adept at reading and understanding code!  &lt;/p&gt;

&lt;p&gt;The truth of the matter is that, unless you&amp;#8217;re a member of core or
have a high level of familiarity and involvement with the Rails
codebase, the svn diffs provide far too little context to decode the
actual problem.&lt;/p&gt;

&lt;p&gt;Does this speak to the obfuscated nature of the Rails codebase or to
the relatively advanced nature of web programming in Ruby?  If I had
to pick one, it would be the latter, but I&amp;#8217;m leaning towards neither.
The Rails codebase is not the most readable, comprehensible piece of
code I&amp;#8217;ve ever seen, but it does its job remarkably well.  Perhaps if
the routing code in question was a bit more understandable by the
masses, this rather obvious security issue wouldn&amp;#8217;t have gone
undetected for so long.&lt;/p&gt;

&lt;h2&gt;Post-1.1.6 Release Triage&lt;/h2&gt;

&lt;p&gt;A group of enthusiastic Railsers jumped onto #rails-security on
freenode shortly after the 1.1.6 release, where an effort had been
organized to verify all the patches across various &lt;a href="http://wiki.caboo.se/caboose/pages/1.1.6+Matrix"&gt;combinations of
web servers and Rails versions&lt;/a&gt;.  An IRC channel, a &lt;a href="http://wiki.caboo.se/caboose/pages/1.1.6+Matrix"&gt;wiki&lt;/a&gt;,
Ruby, Zed&amp;#8217;s &lt;a href="http://rfuzz.rubyforge.org/design.html"&gt;RFuzz&lt;/a&gt;, and a &lt;a href="http://pastie.caboo.se/7993"&gt;piece of code&lt;/a&gt; were all the
tools required to get a distributed test verification process up and
running.  This sort of thing happens all the time in the open source
world, with programmers around the globe pitching in to raise the
triage tent of the MASH unit.  Still, it was exciting to see and be a
part of the action and to be reminded of the power of the collective
whole working for a common cause.&lt;/p&gt;

&lt;h2&gt;Dynamic Routing Harmful?&lt;/h2&gt;

&lt;p&gt;Rails&amp;#8217;s dynamic routing code came under fire too, understandably so.
Maybe this is one case where the developer-friendly approach of
magically recognizing URLs goes a little too far?  Production-only
routes that do away with the expandable path elements could easily be
generated by visiting all the controllers in the codebase and
generating a more static route for each &amp;#8211; sounds like a good idea for
a plugin.  Perhaps the controller is the better place to store routing
metadata anyway?&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;UsersController&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;ActionController&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Base&lt;/span&gt;
  &lt;span class="ident"&gt;map_default_route&lt;/span&gt;  &lt;span class="comment"&gt;# could be optional&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;

&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;PostsController&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;ActionController&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Base&lt;/span&gt;
  &lt;span class="ident"&gt;map_route_as_resource&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Sounds like good fodder for future investigation!&lt;/p&gt;</description>
      <pubDate>Tue, 15 Aug 2006 04:12:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:1e075610-8ab5-47a3-acae-7def4e3ab32a</guid>
      <author>Nick Sieger</author>
      <link>http://blog.nicksieger.com/articles/2006/08/15/security-threat-last-week</link>
      <category>ruby</category>
      <category>rails</category>
      <category>rails</category>
      <category>security</category>
      <trackback:ping>http://blog.nicksieger.com/articles/trackback/48</trackback:ping>
    </item>
  </channel>
</rss>
