Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Javascript SDK security issue?

I am trying to embed facebook auth into my application. My initial effort was to login in browser and obtain code. I pass this code back to my api and obtain access token (that stays with the server) and route all my requests to FB Api through my server. Seemed totally secure to me as my client has no information to be able to make authorized calls to FB as my app.

I however have been looking at FB Javascript SDK to avoid writing code for dialog opening and closing and noticed that it allows me to getLoginStatus and returns me the access token. Also, I went over FB auth flows in their documentation and they say that client-server hybrid flow is okay to do where server actually gives "Long lived access token" back to the client and advises me to use HTTPS (fair).

Now all this gets me thinking if this is a security concern. Can't I as a potential hacker inject some javascript into the user's webpage that could either
a) make a getLoginStatus and get the access token or
b) just get the access token by making a request to my api server and get the access token
and then use that to post (assuming that user authorized my app to do so) to facebook as if my app was doing it?

I am a security newbie and maybe overlooking a bunch of stuff here but could someone help me understand what I'm missing?

Thanks in advance!

PS: I do know I can enable further security to ensure that I need the app secret every time I want to make a request which the client can't do as that information will never be available on client side.

like image 348
stripathi Avatar asked May 14 '17 05:05

stripathi


2 Answers

I am not a security expert, just some thoughts: in your question, you are assuming that the hacker somehow injects the script into the webpage in the user browser using malware and that script then interacts with the data you have client-side.

Now, if we imagine this actually happened and the evil script has full access to the web-page data, even if you don't have the access token on the client, what prevents the evil script to make requests to your server and interact with facebook through your server?

Moreover, if the user opens facebook itself and authorizes there, the evil script could be injected into facebook page and do any actions on behalf of the user, just sending the requests to facebook server.

This way, it looks for me that if the situation you describe happened, it would not really matter if you storing the access token client side or not - anyway the evil script will be able to do it's job.

Practically, if you are worried about security - first carefully check all the facebook docs related to authentication and security and follow their recommendations. Second - search for common known attack vectors and recommendations of how to avoid security risks in your application. If the user already has malware on his computer which is able to alter browser behavior (like inject additional scripts into pages), you probably can't do much about it.

like image 96
Boris Serebrov Avatar answered Sep 28 '22 03:09

Boris Serebrov


You can only get your access token if you have a valid redirect URI which equivalent to your Site URL on your facebook application settings..

also, it needs permissions before you can post using the facebook access_token.

You can check the API calls at https://developers.facebook.com/tools/explorer/

like image 20
Rex Adrivan Avatar answered Sep 28 '22 03:09

Rex Adrivan