<?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>Darth Sid &#187; SSL</title>
	<atom:link href="http://darthsid.com/blog/tag/ssl/feed/" rel="self" type="application/rss+xml" />
	<link>http://darthsid.com/blog</link>
	<description>&#34;Powered by The Dark Side&#34;</description>
	<lastBuildDate>Tue, 06 Apr 2010 08:48:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>SSL checklist for Rails Applications</title>
		<link>http://darthsid.com/blog/2010/03/29/ssl-checklist-for-rails-applications/</link>
		<comments>http://darthsid.com/blog/2010/03/29/ssl-checklist-for-rails-applications/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 13:34:39 +0000</pubDate>
		<dc:creator>Sid</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[SSL]]></category>

		<guid isPermaLink="false">http://darthsid.com/blog/?p=126</guid>
		<description><![CDATA[The purpose of SSL is to provide a reasonable level of protection against eavesdropping and man-in-the-middle attacks. Although SSL provides a greater level of security, it introduces a lot of overheads and hence should be used sparingly. Two of the most common places to use SSL is for payment transactions and user registration/login. This post [...]]]></description>
			<content:encoded><![CDATA[<p>The purpose of SSL is to provide a reasonable level of protection against eavesdropping and man-in-the-middle attacks. Although SSL provides a greater level of security, it introduces a lot of overheads and hence should be used sparingly.  Two of the most common places to use SSL is for payment transactions and user registration/login.<br />
This post intentionally focuses only on the Rails application as there are numerous post on the net for SSL setup on the server. Enabling SSL in a Rails application is really trivial and there are just a few points that need your attention..<br />
<span id="more-126"></span><br />
<big><big><strong>1. Enabling SSL</strong></big></big><br />
<big>a. Install the <i>ssl_requirment</i> plugin:</big></p>
<pre class="brush: bash;">
./script/plugin install git://github.com/rails/ssl_requirement.git
</pre>
<p><big>b. Include it in your <i>application_controller.rb</i>:</big></p>
<pre class="brush: ruby;">
include SslRequirement
</pre>
<p><big>c. Specify actions that require SSL in their respective controllers. For eg. my session controller has the following line:</big></p>
<pre class="brush: ruby;">
ssl_required  :new, :create
</pre>
<p><big>d. Add the following line in <i>development.rb</i> to bypass SSL in development mode:</big></p>
<pre class="brush: ruby;">
SslRequirement.disable_ssl_check = true
</pre>
<p><big><big><strong>2. Gotcha&#8217;s</strong></big></big><br />
<big>a. Include all submit actions in requirement</big><br />
Any action that processes form data from a SSL page should also be added to the requirement. In the above example, the form on the login page(<i>new</i> action) is processed by the <i>create</i> action and hence it is also included in the requirement.<br />
<big>b. Ajax actions</big><br />
Ajax actions on a SSL page should also use SSL and must be included in the requirement. At times you do not have a body for the Ajax action and it is rendered using it&#8217;s respective RJS template. In such cases create an empty action and include it in the <i>ssl_requirement</i>.<br />
<big>c. Mixed content</big><br />
A lot of browsers show you a &#8220;Mixed Content Warning&#8221; if your SSL page references non-SSL assets. IE displays a scary looking confirmation dialog while Firefox and Chrome show a exclamation in the url bar. Any relative paths(eg. using _path helpers) on the page will automatically use the https protocol but any absolute paths(eg. using _url helper or by manually specifying as a string in link_to) will need to be changed to use https.<br />
<big>d. Asset host issue</big><br />
If you are using Rails asset hosts and do not have a SSL certificate that supports wildcard(for subdomains), then you need to disable them for the SSL pages. Just add the following code to your <i>production.rb</i>:</p>
<pre class="brush: ruby;">
ActionController::Base.asset_host = Proc.new { |source, request|
  if request.ssl?
    "#{request.protocol}#{request.host_with_port}"
  else
    "#{request.protocol}assets%d.yourdomain.com" % (source.hash % 4)
  end
}
</pre>
<p>Replace <i>&#8220;yourdomain&#8221;</i> with your apps domain and <i>&#8220;4&#8243;</i> with the number of asset hosts required.</p>
<p>The above should ensure that you have a proper SSL setup without displaying warnings to the user.</p>
]]></content:encoded>
			<wfw:commentRss>http://darthsid.com/blog/2010/03/29/ssl-checklist-for-rails-applications/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

