I have created this web app and I created have this API. For the sake of this example, let's keep it simple:
My app needs to know how many "credits" the user has.
The API has a call get_credits
that returns { credits: 1000 }
.
Now, how do I prevent somebody to use a hostfile (or some other method) to create his own API that returns { credits: 2000 }
.
I was thinking of inserting a hash of some sort, but because it is JavaScript, the hash is easily extracted from the source. Same goes for a handshake I guess.
So, how do I make the API secure enough?
If it's client side there is not much you can do - make a best effort. BUT you must ensure that on the post back you validate the reply. Never trust users :-)