tl;dr Facebook Groups offers the option to upload files directly from the Dropbox account. This integration is done using the Facebook Groups offers the option to upload files directly from the Dropbox account. This integration is done using the OAuth 2.0 protocol and suffered from a variant of the classic OAuth CSRF (defined by Egor Homakov as the the Most Common OAuth2 Vulnerability ), see video below:





Introduction

Facebook Groups offers the option to upload files directly from the Dropbox account:













This will allow to surf via browser the Dropbox account













and post a specific file to the group.

From “OAuth 2 In Action” by Justin Richer and Antonio Sanso, Copyrights 2017



Usually the client initiates the OAuth flow in the following way:





From “OAuth 2 In Action” by Justin Richer and Antonio Sanso, Copyrights 2017



then after that the resource owner has authorized the client the authorization server redirects the resource owner back to the client with an authorization code:

From “OAuth 2 In Action” by Justin Richer and Antonio Sanso, Copyrights 2017



Then the OAuth dance continues....

Facebook/Dropbox integration

The flow is a pretty standard OAuth flow with an exception. Being Dropbox the client he would be in charge of initiate the dance, but the reality is:













Indeed is Facebook that initiates the flow doing:





https://www.facebook.com/dialog/oauth?display=popup&client_id=210019893730&redirect_uri=https%3A%2F%2Fwww.dropbox.com%2Ffb%2Ffilepicker%3Frestrict%3D100000740415566%26group_id%3D840143532794003&scope=publish_actions%2Cuser_groups%2Cemail&response_type=code





Everything else is as supposed to be:









CSRF in OAuth 2

The eagle-eye reader will sure notice that the initiation link, aka





https://www.facebook.com/dialog/oauth?display=popup&client_id=210019893730&redirect_uri=https%3A%2F%2Fwww.dropbox.com%2Ffb%2Ffilepicker%3Frestrict%3D100000740415566%26group_id%3D840143532794003&scope=publish_actions%2Cuser_groups%2Cemail&response_type=code





lacks one really important piece (in OAuthland) namely the state parameter. This parameter is, according to the OAuth core specification:



An opaque value used by the client to maintain state between the request and callback. The authorization server includes this value when redirecting the user-agent back to the client. The parameter SHOULD be used for preventing cross-site request forgery (CSRF).





The best way to see this CSRF account in action is through a picture:





From “OAuth 2 In Action” by Justin Richer and Antonio Sanso, Copyrights 2017

You can also find a great introduction to this attack in the the Most Common OAuth2 Vulnerability by Egor Homakov.





CSRF in Facebook/Dropbox integration

state parameter) would not work in this case. The reason is due the fact that, as we have seen already, the flow is initiated "weirdly" by Facebook and not Dropbox. So there is no way to have Dropbox checking that the right state parameter is bounced back. So wazzup? The attacker will forge a page with a malicious link (containing his own authorization code) in



<html>

<img src="https://www.dropbox.com/fb/filepicker?restrict=100000740415566

&group_id=236635446746130

&code=AQAJspmJvIyCiTicc4QNr7qVU4EF05AYqBE_K9pl-fbhSuKyxtjHS_UyYU8K0S

czXZCTa9WxtG7I8EoxAIcyqhyO0tagiVSa1m2H3Umg8uZR6gixrlmUXKuyoXmYsb14yxPbwonY

xvepwP2N93gWxhVwl1me-qeenZIX2oKgqBuFMRHAW5SCaYCvYSYtaMlrDyYGoftTCAYM0QfU_

bX94LfkHUl81O1tmrLU2NtnU5Eh_XKvxjiD5j2ftSWfpCoxeb7ccaz_9UPZjsFnKGCtTTPX_2dCqi99aT

7B3M4idq6hzY-wUuDmaOL143WolrCGkDUu-np8gyEFx4wfMMdX0a0g#_=_" />

</html>



and after the victim visits this address his Dropbox upload file post will be done with the name of the attacker!! See:



Before to describe the specific attack we need to highlight one really important thing. The classic protection against CSRF in OAuth (aka the use of theparameter) would not work in this case. The reason is due the fact that, as we have seen already, the flow is initiated "weirdly" by Facebook and not Dropbox. So there is no way to have Dropbox checking that the rightparameter is bounced back. So wazzup? The attacker will forge a page with a malicious link (containing his own authorization code) in https://asanso.github.io/facebook/fb.html and after the victim visits this addresshis Dropbox upload file post will be done with the name of the attacker!! See:









But wait a second, why this is actually the case? Well it turns out that it was a strange issue in Dropbox and the access token was cached indefinitely. So once the crafted authorization code was bound with the victim resource owner than no matter a legit authorization code was actually employed, Dropbox will not trade it and continue to use the old malicious access token to post the file to Facebook!!

Disclosure timeline



Little rant. Reporting integration issues is always a challenge. Is not always clear who the culprit is. In this case the culprit was clearly Dropbox while the victim was Facebook. The paradox was the being Dropbox not affected by the issue it was not extremely interested to hear about this issue. On the Facebook side even if they were clearly the target they could not do much without the help of Dropbox. And me ? Well I was right in the middle :)

13-01-2017 - Reported to Facebook security team.

14-01-2017 - Reported to Dropbox security team via Hackerone.



Dropbox part I

15-01-2017 - Dropbox replied: "This is a bug in Facebook's use of our API rather than the Dropbox API itself."

15-01-2017 - I replied to Dropbox saying: "Is not Facebook using Dropbox API but it is quite the opposite."

15-01-2017 - Dropbox replied: "I will take a look again and reopen if we decide its valid." and -5 points!!!!!!!!

Reported to Facebook security team.Reported to Dropbox security team via Hackerone.Dropbox replied: "This is a bug in Facebook's use of our API rather than the Dropbox API itself."I replied to Dropbox saying: "Is not Facebook using Dropbox API but it is quite the opposite."

15-01-2016 - While I do not care too much about those point I replied to Dropbox saying: having -5 points reputation for this is rather frustrating.....

15-01-2016 - Dropbox reopened the report and closed as Informative (so got +5 points back :))





Facebook



from 20-01-2017 to 25-02-2017 - Back an forth between me and Facebook in order to have them to reproduce the issue.

25-02-2017 - Facebook closed the issue saying: "We're able to reproduce the behavior you described, but this may be an issue on the Dropbox side (in particular the /fb/filepicker endpoint) which we do not control."

04-03-2017 - Asked Facebook if there is any chance they can contact Dropbox and explain the situation.



Dropbox part II

$1,331

Acknowledgement





That's all folks. For more OAuthy goodies, follow me on Twitter.



<snip>

//SHAMELESS SELF ADVERTISEMENT

like OAuth 2.0 and/or you want to know more about it If youOAuth 2.0 and/or you want to know more about it here you can find a book on OAuth that Justin Richer and myself have been writing on the subject.



</snip> This was quite a ride with an happy end eventually! I would like to thank the Facebook and Dropbox security teams and specially Neal Poole from Facebook Security.

In the Facebook/Dropbox integration Dropbox is the client while Facebook is Authorization/Resource server.Reported (once more) to Dropbox security team via Hackerone. Dropbox rewarded asanso with abounty.- Public disclosure.