Search code examples
facebookoauth-2.0google-pluslinkedin-api

OAuth2 : redirect_uri post LinkedIn & Facebook


I'm performing the server side oAuth2 flow.

I noticed that google has added a cool feature for their oAuth2 signin API which is redirect_uri=postmessage so we don't show the real redirect_uri on the browser url bar and the authorization code won't be included in the redirect url.

For linkedin, when the users accepts to share his personal data with the app, the response url looks like :

http://dev.localhost.com:8080/auth/linkedin?code=xxxxxxxxxxx&state=yyyyyyyyyyyyy

it's the same for Google unless we replace the real redirect_uri by postmessage.

If the redirect_uri + the response code is set in the url Every malicious script could be able to retrieve the returned code from the url and perform its own authentications.

So, is there any way to hide the return parameters and the redirect_uri for LinkedIn and Facebook ?


Solution

  • LinkedIn and Facebook are not vulnerable to malicious scripts accessing the redirect_uri.

    Assuming you use the recommended response_type=code both APIs require you make a request from your server that includes your API secret and the code value in order to get the users token. LinkedIn describes this in Exchange Authorization Code for a Request Token and Facebook describes this in Exchanging code for an access token.

    Additional security with Facebook can enabled with requiring that every request be signed with your API secret. Additional protection in general can be had by using a strong Content Security Policy to help prevent malicious scripts from running in the first place. And be sure to host your site exclusively over TLS to prevent your own JavaScript from being modified.