Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent other iOS/Android apps from using my RESTful API?

I have a pre-existing iOS & Android app, that I'm making an update for that includes a RESTful services API and Facebook login for user authentication. The general flow of the app is:

  1. Users "logs in" to my app, via Facebook's SDKs, which return an access token to my app.
  2. App calls a RESTful service, including the Facebook access token as a parameter (using HTTPS and SSL)
  3. Service that is called, sends the received access token (and app secret stored only on my servers) to Facebook to verify who the user is, and performs actions based on that. Facebook is set to require app secret from server-side calls.

My app has gained popularity and has several clones already, and I want to prevent these clones from being able to use my RESTful API (as I am sure that they will try to do when I release the update). Let's assume that the clones are smart, are using the same Facebook access tokens that my app does (if this is possible), and are following a similar pattern & frequency of calling the API that my app does.

Is there anyway to ensure, or nearly ensure, that calls to my services are coming only from my app, and not the clones?

Thanks in advance!

like image 874
user3483090 Avatar asked Apr 01 '14 00:04

user3483090


People also ask

How do you prevent unauthorized API access?

Never pass input from an API through to the endpoint without validating it first. Use rate limiting. Setting a threshold above which subsequent requests will be rejected (for example, 10,000 requests per day per account) can prevent denial-of-service attacks. Use a web application firewall.

Do mobile apps use rest APIs?

For mobile apps, the RESTful APIs use the HTTPS protocol, which is more secure for using a Secure Socket Layer (SSL). Since mobile apps undergo a lot of updates they should have a robust process for version control to manage the changes better.

Do Android apps use API?

In fact, the vast majority of successful apps on the Play Store will use at least one web API! In this post, we'll explore how to use a web API from within an Android app.


1 Answers

You can do this by including a signature in the request, and verifying it.

App Side:

  1. do something like: signature = md5( md5(url + data) + MY_RANDOM_KEY)

  2. append signature to the data, or url, etc.

  3. send call to REST api (as usual)

Server Side:

  1. extract the signature from the body/url (and remove it from there).

  2. calculate what you think it should be: signature_should_be = md5( md5(url + data) + MY_RANDOM_KEY) [keep in mind you've removed signature from url/data so that you get url/data in its original pre-hash state]

  3. verify that signature and signature_should_be are equal

Doing this, along with SSL, should make your API secure enough.

like image 118
Tommy Crush Avatar answered Oct 16 '22 05:10

Tommy Crush