How to submit scores securely from app that uses only facebook login?

烂漫一生 提交于 2019-12-11 07:13:57

问题


Our android app only has facebook login.

Here's what happens in server:

A user is created when a POST request is sent using facebook's user access token in body.

Whenever a user gets created via POST request, an api token is generated and sent as a response as follows:

{"message":"User Successfully Created","api_token":"ACITyBKf0jKrfqOFumTMcaEEJ8jU151crRdESMPmBj8zbeENslULHfNXlKeo"}

I did this because the api token that is generated in the server is stored in android app's local storage and is needed to make other requests.

Now, if the user already exists in the server, the response would be

{"message":"User Already Exists!!","api_token":"ACITyBKf0jKrfqOFumTMcaEEJ8jU151crRdESMPmBj8zbeENslULHfNXlKeo"}

This is in case the user deletes the app and installs again.

Now, to submit score, a PATCH request is to be sent with:

Headers:

Content-Type:application/x-www-form-urlencoded
api_token:ACITyBKf0jKrfqOFumTMcaEEJ8jU151crRdESMPmBj8zbeENslULHfNXlKeo
fb_id:xxxxxxxxxx

Body:

distance:2
golds:19
xp:23

(Note: I tested the above request using postman)

Now, the problem is that I spotted a loophole.

A person can find out their facebook user access token and their facebook id anytime. So, if they make a POST request with that user access token, they will receive the api_token (In the "User Already Exists!!" response). And once they have api_token and fb_id, they can make a PATCH request to modify their scores to whatever they want.

What am I doing wrong? How can I secure my server from being hacked like this?

Please help me. I am a beginner in api design.

Thanks


回答1:


If their API token is available to them in the app at all, that's probably a bad thing. If its not available to them in the app, say they're just forging in-app POST requests and retrieving the raw data, then they're probably trying to hack or pentest the system.

If that's the case, maybe sending the unencrypted API key via POST in the first place is a bad idea. If their API key is all they need to start doing bad things to your system, why ever give it to them in the first place?

Because your app needs it to remember them. What about something like this:

New user, server md5 hashes their API key and sends it to them to be stored. Existing user, server md5 hashes their api key and sends it to them to be stored (if needed) Official Existing Score change occurs: app re-md5 hashes the already hashed api key, sends that with the PATCH request. Server has database with doubly hashed api keys which it finds yours and identifies you as the user, and things go on normally from there.



来源:https://stackoverflow.com/questions/42818503/how-to-submit-scores-securely-from-app-that-uses-only-facebook-login

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!