<?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>Software and Opinions &#187; oauth</title>
	<atom:link href="http://ianloic.com/tag/oauth/feed/" rel="self" type="application/rss+xml" />
	<link>http://ianloic.com</link>
	<description>from Ian McKellar</description>
	<lastBuildDate>Thu, 19 Nov 2009 22:05:43 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Understanding the OAuth vulnerability</title>
		<link>http://ianloic.com/2009/04/23/understanding-the-oauth-vulnerability/</link>
		<comments>http://ianloic.com/2009/04/23/understanding-the-oauth-vulnerability/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 18:04:15 +0000</pubDate>
		<dc:creator>Ian McKellar</dc:creator>
				<category><![CDATA[Default]]></category>
		<category><![CDATA[oauth]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://ianloic.com/?p=115</guid>
		<description><![CDATA[Last night&#8217;s OAuth Security Advisory 2009.1 was a little light on the details. The blog post wasn&#8217;t much better. I was peripherally involved in the OAuth spec development and I couldn&#8217;t work out what the advisory meant without a bunch of thinking and spec reading so I thought I&#8217;d try to explain it in simpler [...]]]></description>
			<content:encoded><![CDATA[<p>Last night&#8217;s <a href="http://oauth.net/advisories/2009-1">OAuth Security Advisory 2009.1</a> was a little light on the details. The <a href="http://blog.oauth.net/2009/04/22/acknowledgement-of-the-oauth-security-issue/">blog post</a> wasn&#8217;t much better. I was peripherally involved in the OAuth spec development and I couldn&#8217;t work out what the advisory meant without a bunch of thinking and spec reading so I thought I&#8217;d try to explain it in simpler terms here.</p>
<p>For my example I&#8217;ll use the real service Twitter and a theoretical service Twitten that lets users post to to Twitter in LOL-speak and authenticates via OAuth. Alice and Bob will be my attacker and victim.</p>
<p>Alice&#8217;s normal authentication process goes like this:</p>
<ol>
<li>Alice loads twitten.com/login</li>
<li>Twitten creates a regular HTTP session for Alice</li>
<li>Twitten asks Twitter for an unauthorized token</li>
<li>Twitten redirects Alice to an URL on the Twitter servers that will allow her to authorize the token</li>
<li>Alice clicks OK to authorize the token</li>
<li>Twitter redirects Alice back to Twitten</li>
<li>Twitten exchanges its unauthorized token for an access token (associated with Alice&#8217;s account) with Twitter and stores it in Alice&#8217;s session</li>
<li>Alice makes inane posts on Twitter via Twitten</li>
</ol>
<p>The vulnerability here is in step 4. If instead of going to the authorization URL Alice convinces Bob to go there and authorize Twitten she can gain access to his account. Like this:</p>
<ol>
<li>Alice loads twitten.com/login</li>
<li>Twitten creates a regular HTTP session for Alice</li>
<li>Twitten asks Twitter for an unauthorized token</li>
<li>Twitten tells Alice what URL to go to to authorize the token, but she doesn&#8217;t go there</li>
<li>Alice tells Bob, &#8220;if you love Twitter and kittens try out Twitten &#8211; go to http://twitter.com/oauth/authorize/&#8230;.&#8221; (the authorization URL from Twitten)</li>
<li>Bob loads the authorization URL with his Twitter credentials and authorizes the token</li>
<li>Twitten requests Twitter to exchange the unauthorized token for an access token (associated with Bob’s Twitter account) and stores it in Alice’s session</li>
<li>Alice goes to twitten.com and posts &#8220;OMG PWNd&#8221; to Bob&#8217;s twitter account</li>
</ol>
<p>I&#8217;m not really sure how to address this issue. It&#8217;s fundamentally hard to establish trust between three parties over insecure communications. Hopefully more experienced people than me will come up with clever answers.</p>
<p><strong>Update:</strong> changed wording to match Eran&#8217;s suggestion, his <a href="http://www.hueniverse.com/hueniverse/2009/04/explaining-the-oauth-session-fixation-attack.html">blog post</a> on the subject is excellent reading.</p>
]]></content:encoded>
			<wfw:commentRss>http://ianloic.com/2009/04/23/understanding-the-oauth-vulnerability/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>A Different Model For Web Services Authorization</title>
		<link>http://ianloic.com/2009/01/05/a-different-model-for-web-services-authorization/</link>
		<comments>http://ianloic.com/2009/01/05/a-different-model-for-web-services-authorization/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 07:59:46 +0000</pubDate>
		<dc:creator>Ian McKellar</dc:creator>
				<category><![CDATA[Default]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[oauth]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://ianloic.com/?p=102</guid>
		<description><![CDATA[In my last post I set out to describe how easy it is to extract private keys from desktop software. As I was concluding I stumbled on an alternative approach that might be more secure in some circumstances. I didn&#8217;t really go into details, so here&#8217;s an expansion of the idea.
Current API authentication mechanisms including [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://ianloic.com/2009/01/05/no-more-secrets/">my last post</a> I set out to describe how easy it is to extract private keys from desktop software. As I was concluding I stumbled on an alternative approach that might be more secure in some circumstances. I didn&#8217;t really go into details, so here&#8217;s an expansion of the idea.</p>
<p>Current API authentication mechanisms including Flickr Auth, OAuth, Yahoo BBAuth and Google AuthSub work by allowing users to grant an application the right to act for the user on the site. Some implementations allow the user to grant access to only a subset of the functionality — Flickr lets users grant just read access, Google lets users grant access to just one class of data (for example Google Docs but not Google Calendar). But still, the user doesn&#8217;t know which specific operations they&#8217;re allowing to be carried out. This wouldn&#8217;t matter so much if the user can trust the application that they&#8217;re granting access to, but there&#8217;s no way to provide for that completely.</p>
<p>Another approach might be to give third-party applications the ability to submit sets of changes to be applied to a user&#8217;s account, but require the user to approve them through the service provider&#8217;s web site before they&#8217;re applied to the the user&#8217;s real data. For example, a Flickr upload might look like this:</p>
<ul>
<li>Client makes API request flickr.transaction.create(total_files=20, total_data=20M)</li>
<li>Flickr responds with transaction id X and a maximum lifetime for the transaction</li>
<li>Flickr responds with an URL to direct the user&#8217;s browser to to:
<ul>
<li>associate the transaction with an account, and</li>
<li>preview, permit and commit the changes</li>
</ul>
</li>
</ul>
<p>To a user this isn&#8217;t going to look or feel to different from the current Flickr upload scenario where on completion they&#8217;re presented with a set of uploaded photos and offered the opportunity to make metadata changes.</p>
<p>The key advantage here from a security standpoint is that users approve actions not applications. The challenge of expressing a set of changes to a user clearly is not small but unlike the challenge of identifying and trusting applications it&#8217;s solvable.</p>
<p>This model probably only makes sense for write-oriented sessions, and for infrequent, large write sessions (such as Flickr uploads) rather than frequent, small writes (like Twitter posting).</p>
<p>These ideas aren&#8217;t well thought out in my head, they&#8217;re fresh from me trying to come up with a workable model for API authentication and authorization that doesn&#8217;t depend on trusting the identity of clients. I&#8217;d really welcome feedback and ideas on how to take this forward and feedback implementers on the feasibility of adopting a model like this.</p>
]]></content:encoded>
			<wfw:commentRss>http://ianloic.com/2009/01/05/a-different-model-for-web-services-authorization/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>No More Secrets</title>
		<link>http://ianloic.com/2009/01/05/no-more-secrets/</link>
		<comments>http://ianloic.com/2009/01/05/no-more-secrets/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 23:40:31 +0000</pubDate>
		<dc:creator>Ian McKellar</dc:creator>
				<category><![CDATA[Default]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[oauth]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://ianloic.com/?p=93</guid>
		<description><![CDATA[Using secret keys to identify applications communicating across the internet has become popular as people have copied the very successful Flickr authentication API. Unfortunately people trust that they can keep these keys secret from attackers, even as they distribute applications that contain the secret keys to other people. I decided to see how hard it [...]]]></description>
			<content:encoded><![CDATA[<p>Using secret keys to identify applications communicating across the internet has become popular as people have copied the very successful <a href="http://www.flickr.com/services/api/auth.spec.html">Flickr authentication API</a>. Unfortunately people trust that they can keep these keys secret from attackers, even as they distribute applications that contain the secret keys to other people. I decided to see how hard it would be to extract the secret key and API key from Flickr&#8217;s new XULRunner based <a href="http://www.flickr.com/tools/uploadr/">Uploadr</a>.</p>
<p>While the Uploadr is nominally open source, they don&#8217;t include the key in the source code. In the README they instruct anyone building it to acquire their own key and modify the source code to include that key:</p>
<pre>You'll need your own API key and secret from Flickr to build Uploadr.
These can be obtained at http://flickr.com/services/api/.  The key
and secret must be placed in flKey.cpp as indicated.  This file is at:
  UPLOADR/MacUploadr.app/Contents/Resources/components/flKey.cpp

The API key is stored as a string.  The secret is stored as individual
characters so it is not easily readable from the binary.</pre>
<p>Such noble goals.</p>
<p>Getting the API key was as simple as running tcpdump:</p>
<pre>sudo tcpdump -i en1 -vvv -n -s 0 -w /tmp/DumpFile.dmp</pre>
<p>running the Uploadr, and then looking through the dump file to find where the API key is passed. Look:</p>
<pre>api_key=a5c4c07991a15c6b56b88005a76e7774</pre>
<p>In theory getting the secret key is harder, but it turned out to be even easier. It&#8217;s stored in the source code for the <code>flKey::Sign</code> method:</p>
<pre>	// The shared secret
#ifdef XP_MACOSX
	bytes[0] = '-';
	bytes[1] = '-';
	bytes[2] = '-';
	bytes[3] = '-';
	bytes[4] = '-';
	bytes[5] = '-';
	bytes[6] = '-';
	bytes[7] = '-';
	bytes[8] = '-';
	bytes[9] = '-';
	bytes[10] = '-';
	bytes[11] = '-';
	bytes[12] = '-';
	bytes[13] = '-';
	bytes[14] = '-';
	bytes[15] = '-';
#endif</pre>
<p>All I need to do is find that code, disassemble it and reassemble the string. I ran the Uploadr under gdb:</p>
<pre>gdb '/Applications/Flickr Uploadr.app/Contents/MacOS/xulrunner'</pre>
<p>and once it was up and running tried to find something to break on that would expose the secret key. There weren&#8217;t symbols for the <code>flKey::Sign</code> method that&#8217;s defined in the source file but I found I could break on <code>MD5Init</code> that&#8217;s called from that function. So:</p>
<pre>break MD5Init
kill
run</pre>
<p>And now I stop in the middle of the signature function &#8211; and from the stack trace I can see where flKey::Sign begins:</p>
<pre>Breakpoint 1, 0x149a086b in MD5Init ()
(gdb) where
#0  0x149a086b in MD5Init ()
#1  0x149a1588 in flKey::Sign ()
#2  0x017bb45d in NS_InvokeByIndex_P ()
...</pre>
<p>All I have to do is disassemble <code>flKey::Sign</code>:</p>
<pre>(gdb) disassemble 0x149a1588
Dump of assembler code for function _ZN5flKey4SignERK9nsAStringRS0_:
0x149a1498 &lt;_ZN5flKey4SignERK9nsAStringRS0_+0&gt;:	push   %ebp
0x149a1499 &lt;_ZN5flKey4SignERK9nsAStringRS0_+1&gt;:	mov    %esp,%ebp
0x149a149b &lt;_ZN5flKey4SignERK9nsAStringRS0_+3&gt;:	push   %edi
0x149a149c &lt;_ZN5flKey4SignERK9nsAStringRS0_+4&gt;:	push   %esi
...
0x149a153e &lt;_ZN5flKey4SignERK9nsAStringRS0_+166&gt;:	movb   <strong>$0xXX</strong>,(%eax)
0x149a1541 &lt;_ZN5flKey4SignERK9nsAStringRS0_+169&gt;:	movb   <strong>$0xXX</strong>,0x1(%eax)
0x149a1545 &lt;_ZN5flKey4SignERK9nsAStringRS0_+173&gt;:	movb   <strong>$0xXX</strong>,0x2(%eax)
0x149a1549 &lt;_ZN5flKey4SignERK9nsAStringRS0_+177&gt;:	movb   <strong>$0xXX</strong>,0x3(%eax)
0x149a154d &lt;_ZN5flKey4SignERK9nsAStringRS0_+181&gt;:	movb   <strong>$0xXX</strong>,0x4(%eax)
0x149a1551 &lt;_ZN5flKey4SignERK9nsAStringRS0_+185&gt;:	movb   <strong>$0xXX</strong>,0x5(%eax)
0x149a1555 &lt;_ZN5flKey4SignERK9nsAStringRS0_+189&gt;:	movb   <strong>$0xXX</strong>,0x6(%eax)
0x149a1559 &lt;_ZN5flKey4SignERK9nsAStringRS0_+193&gt;:	movb   <strong>$0xXX</strong>,0x7(%eax)
0x149a155d &lt;_ZN5flKey4SignERK9nsAStringRS0_+197&gt;:	movb   <strong>$0xXX</strong>,0x8(%eax)
0x149a1561 &lt;_ZN5flKey4SignERK9nsAStringRS0_+201&gt;:	movb   <strong>$0xXX</strong>,0x9(%eax)
0x149a1565 &lt;_ZN5flKey4SignERK9nsAStringRS0_+205&gt;:	movb   <strong>$0xXX</strong>,0xa(%eax)
0x149a1569 &lt;_ZN5flKey4SignERK9nsAStringRS0_+209&gt;:	movb   <strong>$0xXX</strong>,0xb(%eax)
0x149a156d &lt;_ZN5flKey4SignERK9nsAStringRS0_+213&gt;:	movb   <strong>$0xXX</strong>,0xc(%eax)
0x149a1571 &lt;_ZN5flKey4SignERK9nsAStringRS0_+217&gt;:	movb   <strong>$0xXX</strong>,0xd(%eax)
0x149a1575 &lt;_ZN5flKey4SignERK9nsAStringRS0_+221&gt;:	movb   <strong>$0xXX</strong>,0xe(%eax)
0x149a1579 &lt;_ZN5flKey4SignERK9nsAStringRS0_+225&gt;:	movb   <strong>$0xXX</strong>,0xf(%eax)
...
0x149a168e &lt;_ZN5flKey4SignERK9nsAStringRS0_+502&gt;:	pop    %esi
0x149a168f &lt;_ZN5flKey4SignERK9nsAStringRS0_+503&gt;:	pop    %edi
0x149a1690 &lt;_ZN5flKey4SignERK9nsAStringRS0_+504&gt;:	pop    %ebp
0x149a1691 &lt;_ZN5flKey4SignERK9nsAStringRS0_+505&gt;:	ret
End of assembler dump.</pre>
<p>And sure enough if I reconstruct those bytes, the secret key is: <strong style="color:white;background-color:black;"><code>REDACTED</code><code>REDACTED</code></strong></p>
<p>That wasn&#8217;t too hard was it? The fact that the code around the key was open source made it easier to find but even if it was closed source if I knew what kind of algorithm I was looking for it wouldn&#8217;t be hard to find and examine. It&#8217;s pretty easy to trace forward from user input or backward from network IO to find the signature algorithm, and the secret&#8217;s always the input to that.</p>
<p>Unfortunately <a href="http://oauth.net/">OAuth</a> follows the same model as Flickr, placing some value in a consumer&#8217;s &#8220;private&#8221; key. They do mention in <a href="http://oauth.net/core/1.0/#anchor40">Appendix B.7</a> that it&#8217;s often possible for attackers to access a secret it&#8217;s still a vital part of the protocol.</p>
<p>Since it&#8217;s not possible to securely identify clients we should move to a model where users approve actions against their accounts rather than granting carte-blanche actions to clients. For example Flickr could put photos that are uploaded into a staging area and require approval on the web site before including them in a user&#8217;s photo stream. This would allow users to make a informed decisions about third-party access to their accounts.</p>
<p><b>Updated:</b> at Flickr&#8217;s request I&#8217;ve removed the &#8220;secret&#8221; key.</p>
<p><b>Updated again:</b> I made <a href="http://ianloic.com/2009/01/05/a-different-model-for-web-services-authorization/">another post</a> about this topic, expanding on the final paragraph of this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://ianloic.com/2009/01/05/no-more-secrets/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
