I’d like to restrict access to a PHP file on my server. This PHP file takes data from an HTTP GET request and appends it to a file. Simple. But I don’t want this PHP file executed unless the HTTP request is generated from within the smartphone app I’ve developed.
I don’t want to authenticate each user individually. I want my app, and only my app, to be able to send the request to the PHP file. I don’t want people typing in a similarly formed request (http://www.mydomain.com/check.php?string=blahblahblah) into a browser and have the same impact.
I have thought about checking the HTTP_USER_AGENT, or some other variable, but I fear that they might be easy to spoof too. I could embed a key into my app that I look for, but that key could also be compromised.
The next step would be to have the server send me a challenge to which I respond appropriately. Or I could even look into PKI. But what’s a relatively easy way to do this, given that I am not trying to protect anything of real value, just to prevent minor vandalism.
Am I trying to reinvent the wheel here? Is there already an easy, proven way to do this?
FWIW, here is the most secure method I can think of without seriously affecting performance – essentially the RESTful(ish) way, as to ramp it up any further would require multiple requests and connection state information stored on the server:
In order to break through this system and successfully spoof a request, an attacker would need to know the following:
Obviously if you are working with the mobile device 1 – 3 are easy to extract, but 4 and 5 cannot be found without reverse engineering the app (which there is literally nothing you can do to prevent, for people with the knowledge and the patience to do it).
A man-in-the-middle attack would be basically impossible – even after breaking through the SSL (which is non-trivial, to say the least) and reverse engineering the app to get 4 and 5, 1-3 cannot be retrieved without a brute force attack on the hash, which is sufficiently complex that this would take an average of several hundred million years (see this page to see how I arrived at that figure), especially if one of the three is of a variable length – which the app version string could easily be.