<?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>All Night Diner &#187; security</title>
	<atom:link href="http://micropipes.com/blog/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://micropipes.com/blog</link>
	<description>because at 3am anything sounds good</description>
	<lastBuildDate>Mon, 03 May 2010 17:34:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How addons.mozilla.org defends against XSS attacks</title>
		<link>http://micropipes.com/blog/2009/02/23/how-addonsmozillaorg-defends-against-xss-attacks/</link>
		<comments>http://micropipes.com/blog/2009/02/23/how-addonsmozillaorg-defends-against-xss-attacks/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 16:16:56 +0000</pubDate>
		<dc:creator>Wil Clouser</dc:creator>
				<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[AMO]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://micropipes.com/blog/?p=70</guid>
		<description><![CDATA[One of the things that gets a lot of news time these days is XSS.  There are a lot of places that explain what it is and how to prevent it but most are oversimplified or don&#8217;t provide real world examples.  I thought I&#8217;d explain a couple of the ways AMO attempts to [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things that gets a lot of news time these days is <abbr title="Cross Site Scripting">XSS</abbr>.  There are a lot of places that explain what it is and how to prevent it but most are oversimplified or don&#8217;t provide real world examples.  I thought I&#8217;d explain a couple of the ways <a href="https://addons.mozilla.org/"><abbr title="addons.mozilla.org">AMO</abbr></a> attempts to prevent it.</p>
<p>I&#8217;m not trying to invite attackers by posting this.  My goal is to provide a (hopefully) working example from a real world, high-traffic site.  I think the people exploiting XSS have a fairly good idea what they are doing and, too often, the people attempting to secure their sites don&#8217;t.  Since AMO is open source I&#8217;m not sharing anything that isn&#8217;t available already anyway (side note: please don&#8217;t depend on security by obscurity).  </p>
<p>Firstly, this chunk of code sits in CakePHP&#8217;s <a href="http://svn.mozilla.org/addons/trunk/site/app/config/bootstrap.php">bootstrap.php</a> and runs very close to the start of every request:</p>
<pre><code>
if (array_key_exists('url',$_GET) &#038;&#038;
    !preg_match('/\/api\//', $_GET['url']) &#038;&#038;
    preg_match('/[^\w\d\/\.\-_!: ]/u',$_GET['url'])) {
    header("HTTP/1.1 400 Bad Request");
    exit;
}</code></pre>
<p>Since a lot of XSS attacks are launched from the URL we implemented this simple white list of characters we&#8217;ll allow.  If anything outside of that white-list is in the URL we return an invalid request header and die.  This isn&#8217;t a lot of protection but it does narrow the field of what our application expects and has to deal with (particularly with control characters, high level ASCII, etc.).</p>
<p>The second, and more important section of code is in our <a href="http://svn.mozilla.org/addons/trunk/site/app/app_controller.php">app_controller class</a>.  We wrote a custom sanitize() function that any string going into one of our views gets run through:</p>
<pre class="php"><code>
$sanitize_patterns = array(
    'patterns'      => array("/%/u", "/\(/u", "/\)/u", "/\+/u", "/-/u"),
    'replacements'  => array("&amp;#37;", "&amp;#40;", "&amp;#41;", "&amp;#43;", "&amp;#45;")
    );

........

$data = iconv('UTF-8', 'UTF-8//IGNORE', $data);
$data = htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
$data = preg_replace($sanitize_patterns['patterns'], $sanitize_patterns['replacements'], $data);
</code></pre>
<p>This code has several important parts and I&#8217;ll start with the functions.  The first function that modifies the actual data is <a href="http://php.oregonstate.edu/manual/en/function.iconv.php">iconv()</a>.  We ask it to convert our data from UTF-8 to UTF-8 which seems unnecessary but the &#8220;//IGNORE&#8221; part is important &#8211; that means it will throw out any characters it can&#8217;t represent appropriately.  This was added to prevent a proof of concept attack that exploited a <a href="http://en.wikipedia.org/wiki/C0_and_C1_control_codes">C0 ASCII control code</a> character to break the output (discovered on the <a href="http://sla.ckers.org/forum/">sla.ckers.org forums</a>).</p>
<p>The next function, <a href="http://php.oregonstate.edu/htmlspecialchars">htmlspecialchars()</a>, is a pretty well known function and converts special characters to their ASCII equivalents.  The second parameter specifically asks it to encode single quotes.</p>
<p>Lastly we use the array of patterns and replacements declared at the beginning to encode a few final symbols, like parenthesis and the percentage sign, into HTML entities.</p>
<p>This system has worked fairly well for a few years now and as issues are discovered we make changes to it.  If you&#8217;re looking for the latest code please be sure to check <a href="http://svn.mozilla.org/addons/trunk/">our repository</a>.  And, as always, if you find any kind of exploit on AMO please let me know! <img src='http://micropipes.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://micropipes.com/blog/2009/02/23/how-addonsmozillaorg-defends-against-xss-attacks/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Your signature matters (sometimes)</title>
		<link>http://micropipes.com/blog/2008/11/18/your-signature-matters-sometimes/</link>
		<comments>http://micropipes.com/blog/2008/11/18/your-signature-matters-sometimes/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 08:13:58 +0000</pubDate>
		<dc:creator>Wil Clouser</dc:creator>
				<category><![CDATA[personal]]></category>
		<category><![CDATA[pdx]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://micropipes.com/blog/?p=62</guid>
		<description><![CDATA[Some quick background for those who don&#8217;t live in Oregon:  In Oregon we do our governmental voting by mail and we&#8217;re given the option of sticking a stamp on it and mailing it or dropping it off at any of the ballot drop boxes scattered around the counties.
What we mail back consists of the [...]]]></description>
			<content:encoded><![CDATA[<p>Some quick background for those who don&#8217;t live in Oregon:  In Oregon we do our governmental voting by mail and we&#8217;re given the option of sticking a stamp on it and mailing it or dropping it off at any of the ballot drop boxes scattered around the counties.</p>
<p>What we mail back consists of the anonymous ballot, a secrecy envelope, and an outer envelope.  The outer envelope has a bar code which identifies who is voting and it also requires a signature on the outside of the envelope.  Once the fact the person has voted is counted (note: not <em>what</em> they voted) the outer envelope is discarded and anonymity takes over.</p>
<p>I&#8217;ve never liked having to sign the outside of the envelope.  It&#8217;s always seemed like one more way someone could rip off a signature relatively easily. </p>
<p>Is it that big of a deal though?  We sign all kinds of stuff and my general attitude has been that no one really looks at signatures these days anyway.  Mix that idea with <a href="http://www.zug.com/pranks/credit_card/">other people coming to the same conclusion</a>, add my general laziness and I guess I let my signature slop around on my ballot envelope.  Also, apparently they actually look at those.  I got a letter in the mail today that said:</p>
<blockquote><p>We were able to match your signature and your ballot was counted from this election, however it appears that your signature has changed since you last registered to vote.</p></blockquote>
<p>They include another registration card for me to update my signature.  I&#8217;m curious how they matched my signature despite it changing and, since they <em>could</em> match my signature, why am I being asked to sign another card?  My guess is it failed a computerized test and had to be reviewed in person.  That just raises the question, why can&#8217;t they scan the new signature and add it to the list of matches in the computer?</p>
<p>Anyway, it&#8217;s the first time my signature has mattered in a long time and seems to bring relevance to my original concern &#8211; putting it on the outside of an envelope makes it that much easier to copy.</p>
]]></content:encoded>
			<wfw:commentRss>http://micropipes.com/blog/2008/11/18/your-signature-matters-sometimes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Committing to SVN securely from a web application</title>
		<link>http://micropipes.com/blog/2008/09/19/committing-to-svn-securely-from-a-web-application/</link>
		<comments>http://micropipes.com/blog/2008/09/19/committing-to-svn-securely-from-a-web-application/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 22:29:58 +0000</pubDate>
		<dc:creator>Wil Clouser</dc:creator>
				<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SVN]]></category>
		<category><![CDATA[Verbatim]]></category>

		<guid isPermaLink="false">http://micropipes.com/blog/?p=56</guid>
		<description><![CDATA[Verbatim is the second project I&#8217;ve been the lead on recently where the requirements included people committing to SVN as themselves via the application.  At first glance this means storing the authentication tokens of the user in plain text since we&#8217;ll need to pass them along to SVN whenever they commit.  I wasn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://wiki.mozilla.org/Verbatim">Verbatim</a> is the second project I&#8217;ve been the lead on recently where the requirements included people committing to <abbr title="Subversion">SVN</abbr> as themselves via the application.  At first glance this means storing the authentication tokens of the user in plain text since we&#8217;ll need to pass them along to SVN whenever they commit.  I wasn&#8217;t happy with that solution so after a bit of thinking we came up with an idea that leaves everything encrypted and doesn&#8217;t cache any credentials.  It involved minimal code in Verbatim and minor work on the SVN server.</p>
<p>On the SVN server the first thing we did was to create a special Verbatim user that can commit to SVN via SSH using a generated key.  We copied this key to the Verbatim host which allowed us to commit as the verbatim user without typing a username or password.</p>
<p>The only thing that was added to the Verbatim code was <a href="http://sourceforge.net/mailarchive/forum.php?thread_name=ADA2D058-904B-44F0-8301-21334A7B6E02%40mozilla.com&#038;forum_name=translate-pootle">a patch that Dan Schafer cooked up</a> that sets an SVN revision property, <em>translate:author</em>, to the name of the current user.  When the user clicks &#8220;commit&#8221; this property is set and sent along with the commit.</p>
<p>At this point we could commit from the application but it still goes to the application as the Verbatim user.  We used <a href="http://svnbook.red-bean.com/en/1.4/svn-book.html#svn.ref.reposhooks">SVN&#8217;s hooks</a> to take the next step.</p>
<p>The first script we changed was the pre-revprop-change hook.  This controls what special revision properties a user can modify when they commit.  <a href="https://bugzilla.mozilla.org/attachment.cgi?id=337775">Our script</a> adds the ability to modify svn:author and translate:author.  Before allowing the modifications the script checks if the user committing is the special verbatim user to prevent anyone from committing as someone else.</p>
<p>Next we added a <a href="https://bugzilla.mozilla.org/attachment.cgi?id=339184">post-commit script</a> that looks for the translate:author property.  If it&#8217;s found it will take that value, replace svn:author, and remove translate:author; effectively making whatever was in translate:author the real author.  This is a non-versioned change which means there is no commit that needs to happen &#8211; the new author is set immediately.</p>
<p>With these scripts in place we can commit as anyone from the application and everyone&#8217;s credentials stay encrypted and secure.</p>
]]></content:encoded>
			<wfw:commentRss>http://micropipes.com/blog/2008/09/19/committing-to-svn-securely-from-a-web-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Another warning option for submitting forms?</title>
		<link>http://micropipes.com/blog/2008/04/04/another-warning-option-for-submitting-forms/</link>
		<comments>http://micropipes.com/blog/2008/04/04/another-warning-option-for-submitting-forms/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 04:44:10 +0000</pubDate>
		<dc:creator>Wil Clouser</dc:creator>
				<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://micropipes.com/blog/2008/04/04/another-warning-option-for-submitting-forms/</guid>
		<description><![CDATA[These are our current options for submitting forms in Firefox 3:

I don&#8217;t know anyone that has the &#8220;I submit information that&#8217;s not encrypted&#8221; option checked.  We used to prompt for submitting information that was unencrypted, next we added an option on the dialog that disabled the warning (and was checked by default), and finally [...]]]></description>
			<content:encoded><![CDATA[<p>These are our current options for submitting forms in Firefox 3:<br />
<img src="/blog/wp-content/img/firefox_security_options.png" alt="Firefox security options dialog" /></p>
<p>I don&#8217;t know anyone that has the &#8220;I submit information that&#8217;s not encrypted&#8221; option checked.  We used to prompt for submitting information that was unencrypted, next we added an option on the dialog that disabled the warning (and was checked by default), and finally we removed the warning by default all together.  People submit so much information via searches, surveys, voting, sending quick messages, etc. that it would just get in the way and be ignored.</p>
<p>I&#8217;ve noticed lately that <a href="http://www.wachovia.com/">a</a> <a href="http://www.scottrade.com/">lot</a> <a href="http://geico.com">of</a> <a href="http://www.tdameritrade.com">sites</a> are showing login forms on unencrypted pages but submitting them via <abbr title="Secure Socket Layer">SSL</abbr> to their target pages.  This is a secure method of logging in but it&#8217;s started to train me to not look for a secure connection before I log in and that&#8217;s not a good idea in the long run.</p>
<p>I think our current option is too broad, so I&#8217;m proposing that we add an option that says &#8220;I submit credentials that aren&#8217;t encrypted&#8221; or a sub-option for the current text that says something about &#8220;unless I&#8217;m sending a password.&#8221;</p>
<p>In more technical language:  If a user POSTs a form containing an input of type=&#8221;password&#8221; to a non-encrypted page we should show a warning.</p>
<p>This would mean regular searches, filling in surveys, anonymous voting and polls would all pass transparently if unencrypted, but when you got to a form with a password you would be warned.</p>
<p>I bounced this idea off a channel in <abbr title="Internet Relay Chat">IRC</abbr> and no one said I was nuts so I figured I&#8217;d take it here.  It seems like too small of a feature to make an add-on out of but I might if I get some free time.  What do you think?</p>
]]></content:encoded>
			<wfw:commentRss>http://micropipes.com/blog/2008/04/04/another-warning-option-for-submitting-forms/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>
