### Open redirect in rfc6749 aka 'The OAuth 2.0 Authorization Framework'

tl;dr The Internet Bug Bounty rewarded me with a bounty for an Open Redirect in  rfc6749 aka 'The OAuth 2.0 Authorization Framework' .

Here the long version.

# The Introduction

Several months ago I did realize that if you want to implement an OAuth Authorization Server and  follow verbatim the OAuth core spec you might end up having an Open Redirect.
Now there is still some debate about this class of vulnerability since often they are relatively benign but not always (as we can see later).
Despite all at that point I notified the OAuth working group. There was some longish discussion but eventually (almost) all in the list agreed that this was somehow an issue (no where near the end of the world :)).

# The Issue

Section 4.1.2.1 of the OAuth specification says:

   If the request fails due to a missing, invalid, or mismatching
redirection URI, or if the client identifier is missing or invalid,
the authorization server SHOULD inform the resource owner of the
error and MUST NOT automatically redirect the user-agent to the
invalid redirection URI. 
   If the resource owner denies the access request or if the request
fails for reasons other than a missing or invalid redirection URI,
the authorization server informs the client by adding the following
parameters to the query component of the redirection URI using the...

Now let's assume an attacker:
• Registers a new client to the victim.com provider.
• Registers a redirect uri like attacker.com.
Then the attacker can craft a special URI of the form

http://victim.com/authorize?response_type=code&client_id=bc88FitX1298KPj2WS259BBMa9_KCfL3&scope=WRONG_SCOPE&redirect_uri=http://attacker.com

according to Section 4.1.2.1 this should redirect back to attacker.com (without any user interaction, ever...)!!! Here we use the a wrong scope parameter but any reasons other than a missing or invalid redirection URI would had make the trick....
Now according to my dictionary this is an open redirect :p

Some live example of real providers that exhibit this behavior:

A real cool special case is Moves (just click and enjoy :p)

Update: it seems that Facebook doesn't allow anymore redirect to data:text/html (hence the link below is broken now), more to come on this topic... ;)

As  (almost) usual Google did it right. Namely Google return 400 with the cause of the error..

400. That’s an error.

Error: invalid_scope

Some requested scopes were invalid. {invalid=[l]}

As we will see this is only one of the possible mitigation.

# The Vulnerability

Now you might argue that this is ONLY an open redirect and there is not much you can do with it right? :)
Well well well ...

## All I need is....an open redirect

Sometimes in order to accomplish some sort of attack you need to have an open redirect. This is only one small part of the chain but an essential one. And what can it be better (from the attacker perspective) if an OAuth provider gives you one :D ? If you do not believe me look like Andris Atteka used this very own issue as part of his attack to steal an access token.

## Lassie come home (again)

In some of my previous post I have highlighted the importance for an Authorization Server to
use exact matching against registered redirect uri to validate the redirect_uri parameter.
Indeed John Bradley realized how some attacker can chain the relaxed redirect uri validation with the open redirect described here to steal an access token.
He pointed out a possible attack scenario in the OAuth mailing list thread

# The Mitigation

John BradleyHannes Tschofenig and me came up with a draft for an OAuth security addendum that should provide better advice to implementers.
The mitigations are described in section 2.3 and they are rather simple, either :

• Respond with an HTTP 400 (Bad Request) status code.
• Perform a redirect to an intermediate URI under the control of the Authorization Server to clear referer information

Unknown said…
This comment has been removed by a blog administrator.

### 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 bl

### The Curious Case of WebCrypto Diffie-Hellman on Firefox - Small Subgroups Key Recovery Attack on DH

tl;dr Mozilla Firefox prior to version 72 suffers from Small Subgroups Key Recovery Attack on DH in the WebCrypto 's API. The Firefox's team fixed the issue r emoving completely support for DH over finite fields (that is not in the WebCrypto standard). If you find this interesting read further below. Premise In this blog post I assume you are already knowledgeable about Diffie-Hellman over finite fields and related attacks. If not I recommend to read any cryptography book that covers public key cryptography. Here is a really cool simple explanation by David Wong : I found a cooler way to explain Diffie-Hellman :D pic.twitter.com/DlPvGwZbto — David Wong (@cryptodavidw) January 4, 2020 If you want more details about Small Subgroups Key Recovery Attack on DH I covered some background in one of my previous post ( OpenSSL Key Recovery Attack on DH small subgroups (CVE-2016-0701) ). There is also an academic pape r where we examine the issue with some more rigors.

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

tl;dr   I was able to hijack the OAuth tokens of EVERY Paypal 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/callback   NOT JUST h ttps://yourouauthclient.com/ or https://yourouauthclient.com/oauth If