Skip to main content

OAuth 2 attacks - Introducing 'The Devil Wears Prada' and 'Lassie Come Home'

As the OAuth 2 framework is becoming more and more used I thought it would be useful to share some of the most common attacks. It is important to highlight that the attacks I am going to introduce today are not issues in the specification per se but rather possible implementation issues. The first document to look at when you try to secure one OAuth 2 implementation is the OAuth 2.0 Threat Model but this is way not enough. In order to have a safe implementation it is important to understand what is OAuth about and to be involved in the "OAuthsphere" (OAuth mailing list, blogs, etc),

In this blog post I will try to show two of the most common attacks that I have renamed  'The Devil Wears Prada' and 'Lassie Come Home'.

Let's see. Firstly the actors:

The Actors


The Devil Wears Prada

The first time I read about this potential issue was in one of John Bradley's blog post . This issue is also known as "confused deputy problem". In a nutshell (once again) OAuth is NOT an authentication protocol. It is an access delegation protocol. It is/can-be-used as an authentication protocol but only and only if you know what you are doing! Let's see what it could happen if you are using the OAuth Implicit Grant flow (aka Client side) . Firstly here a quick reminder of the Client side flow:

  

In the above example, Alice (the resource owner, RO from now) allows Bob  from www.printondemand,biz (the client)  to access the profile pictures from her Facebook (the server) account in order to have a nice photo album. So far so good, right? (Yes :)) Now let see what could happen if www.printondemand,biz would use the profile information of Alice to authenticate her:



The are at least two things to be noticed from the flow above:
  • www.printondemand.biz uses the profile information from Facebook to log in
  • www.printondemand.biz does not have any security. Indeed they have not Authenticated the User! (at all...)
What does this tell us? That www.printondemand.biz authenticates, given an Access Token.

Now let's see how we can use this information to "our" (from the attacker point of view) advantage.
Let's assume there is yet another client (www.dosomething.biz). This client uses legitimately the profile information from Alice to do something that Alice authorized for (e.g. keeping historical profile information). Now when Alice gives the Access Token to www.dosomething.biz the latter does exactly what Alice expects it to do. The problem is that he does as well something more, behind the back of Alice. Here's the flow:


So, referring to the image above, after point 6, Alice got from www.dosomething.biz what he requested. At this point Alice is out of the game. www.dosomething.biz owns an Access Token from Alice though. What www.dosomething.biz can do is to give this Access Token to www.printondemand.biz. And which one is the outcome? You have guessed it, right? How nice :) www.printondemand.biz just authenticated www.dosomething.biz as Alice!!!!
To be noticed that this attack came from something that the RO kind of trusted, hence I named it  "The Devil Wears Prada".

At this point you might wonder which one is the mitigation for this attack. There are several but the best that comes in my mind is to use OpenId Connect for authentication.

 Lassie Come Home

Ready for another one?  This attack is a generalization of on attack done some time ago against Facebook. Now let see an example:




The famous www.thecloudcompany.biz offers the possibility to register your own client.
One of the client of www.thecloudcompany.biz (named example) is one departement of www.thecloudcompany.biz itself. This clients runs under the domain of www.example.thecloudcompany.biz. Above you can see a normal client side flow.
The problem that can happens in this case is a bit subtle but well known. It is really important that the redirect uri matches as much as possible the hostname of the client. Let's see what it could happen if, at client registration time, www.example.thecloudcompany.biz chooses a redirect uri of *.thecloudcompany.biz


Following the image above let's assume that I (www.bad.com) have registered yet another client at thecloudcompany.biz. My client id is 'Bad' and ther registered redirect uri is www.bad.com.
The next step to do is to create a link as per the image above and let the RO click on it.
Guess where the RO Access Token ends up? If you answered www.bad.com kudos to you.
The reasons why this happens are basically two:

1. the registered redirect uri from the client 'example' is too loose so https://www.thecloudcompany.biz%2Foauth%2Fauthorize%3Fclient_id=Bad%26response_type=token%26redirect_uri=http://www.bad.com is a perfectly valid redirect uri!!
2. URL Fragment is preserved for 302 redirects

At this stage you might also wonder why I named this attack 'Lassie come home' but I also hope you figured out the answer :).
That's all for now folks. Happy hacking....




Comments

This comment has been removed by a blog administrator.

Popular posts from this blog

OpenSSL Key Recovery Attack on DH small subgroups (CVE-2016-0701)

Usual Mandatory Disclaimer: IANAC (I am not a cryptographer) so I might likely end up writing a bunch of mistakes in this blog post...

tl;dr The OpenSSL 1.0.2 releases suffer from a Key Recovery Attack on DH small subgroups. This issue got assigned CVE-2016-0701 with a severity of High and OpenSSL 1.0.2 users should upgrade to 1.0.2f. If an application is using DH configured with parameters based on primes that are not "safe" or not Lim-Lee (as the one in RFC 5114) and either Static DH ciphersuites are used or DHE ciphersuites with the default OpenSSL configuration (in particular SSL_OP_SINGLE_DH_USE is not set) then is vulnerable to this attack.  It is believed that many popular applications (e.g. Apache mod_ssl) do set the  SSL_OP_SINGLE_DH_USE option and would therefore not be at risk (for DHE ciphersuites), they still might be for Static DH ciphersuites.
Introduction So if you are still here it means you wanna know more. And here is the thing. In my last blog post I was …

All your Paypal OAuth tokens belong to me - localhost for the win

tl;dr  I was able to hijack the OAuth tokens of EVERYPaypal OAuth application with a really simple trick.
Introduction If you have been following this blog you might have got tired of how many times  I have stressed out the importance of the redirect_uri parameter in the OAuth flow.
This simple parameter might be source of many headaches for any maintainer of OAuth installations being it a client or a server.
Accepting the risk of repeating myself here is two simple suggestions that may help you stay away from troubles (you can always skip this part and going directly to the Paypal Vulnerability section):
If you are building an OAuth client,   Thou shall register a redirect_uri as much as specific as you can
i.e. if your OAuth client callback is https://yourouauthclient.com/oauth/oauthprovider/callback then

DO register https://yourouauthclient.com/oauth/oauthprovider/callbackNOT JUST https://yourouauthclient.com/ or https://yourouauthclient.com/oauth If you are still not convinced here…

Critical vulnerability in JSON Web Encryption (JWE) - RFC 7516

tl;dr if you are using go-jose, node-jose, jose2go, Nimbus JOSE+JWT or jose4j with ECDH-ES please update to the latest version. RFC 7516 aka JSON Web Encryption (JWE) hence many software libraries implementing this specification used to suffer from a classic Invalid Curve Attack. This would allow an attacker to completely recover the secret key of a party using JWE with Key Agreement with Elliptic Curve Diffie-Hellman Ephemeral Static (ECDH-ES), where the sender could extract receiver’s private key.

Premise
In this blog post I assume you are already knowledgeable about elliptic curves and their use in cryptography. If not Nick Sullivan's A (Relatively Easy To Understand) Primer on Elliptic Curve Cryptography or Andrea Corbellini's series Elliptic Curve Cryptography: finite fields and discrete logarithms are great starting points. Then if you further want to climb the elliptic learning curve including the related attacks you might also want to visit https://safecurves.cr.yp.to…