WikiCode WikiCode - 1 month ago 18
Android Question

Mobile APP - API Authentication concept

I have a conceptual question and wanted to know if anyone would be kind enough to help.

I will use a simple example to explain my point of view.

I have developed a simple RESTFul API with Node.JS + Express + MongoDB as a backend. The API saves hightscores from an Android game app. I use token-based authentication, where the tokens are generated from a secret and a trusted username/password (hardcoded or not).

But I still have a doubt thinking about safety...

Reverse engineering is a piece of cake since any developer can easily find the backend endpoint of the API and use it with his username and password (or the hardcoded one) to obtain the token.

Then the token ca be used for insert fake highscores via the API.

My questions are:


  • Is there any way to avoid this security hole?

  • Is using a RESTFull API the correct way to connect a mobile app with a backend in server?

  • If not, which is the correct way to develop an APP-Server comunication to save data in a backend DB?.



I think I can ofuscate the code which includes the hardcoded username and password but this dont solve the situation.

Answer

There is no full-proof way to do this. In theory, everything can be debugged - including your verification mechanism (token generation).

Using a web API is a good way to have your mobile app communicate with a backend and works fine in most cases. However, it your case, you basically want to make sure that the API is used only via the Android app you have. This is typically done by encrypting the communication protocol and making it hard for others to debug it. So, your app will encrypt the communication in a way, which is hard to decrypt if you don't know the internals of the app/server. However, this is hard to do from scratch.

If you want a ready-made solution, you could use Google's Play Game Services, for highscores, achievements, etc. That should be secure enough, but I can't say what the implications would be for your current situation.