The data browser is built for Chrome, Firefox, Safari, and IE9 and above. Please upgrade your browser, or download Google Chrome to get the best experience.
Back to Questions

Prohibit user from changing their own game score?

19 votes     3 answers     6.69k views     

19

In a typical gaming app, a client needs to update a high score, and it has to do so by changing an object to which the user has write access. Since API keys are not secret (especially in javascript the user can simply look in the cource code), how do we prevent the user from making his own api call outside of the official client, in order to up his high score (or any other object whose ACL matches his credentials)?

3 Answers

6

You can track the game score on a separate class that is not writeable by any user. You can then use a Cloud Function to update the user's game score using the Master Key, which would let you modify the score even though it is not writeable by any user.

Héctor, how would go about enabling the Master Key for specific methods defined for Cloud Function. It seems to me that you either toggle it ON/OFF?

- Jamie Chapman over 1 year ago

Parse.Cloud.useMasterKey() will enable master key access only during the execution of the specific Cloud Code or beforeSave function where it is used: https://www.parse.com/docs/cloud_code/symbols/Parse.Cloud.html

- Héctor Ramos over 1 year ago

Héctor, correct me if im wrong. This still doesnt prevent any user from changing ones high score. Since the call to the cloud code is made in javascript, anyone can still see the CloudCode function call and call it at anytime from outside of the official client! if im right, what would you suggest us?

- Newton Guimarães Filho over 1 year ago

I'm also interested in the answer to Newton's question, how would we prevent the user from executing the javascript after logging in with its own credentials?

- Schmeuk Studios over 1 year ago

@newton, @marcos. There's nothing you can do about it. If the user can see the request, then they can spoof it. You would have the same problem using your own backend, or parse. Instead of having the function saveHighScore(score), you can have something like _shs(binary_score). This way makes it harder, but still if someone spend enough time, gonna figure it out.

- kev89431 over 1 year ago

This is a vulnerability that exists in using any non-compiled client code language like Javascript. Since the user can see the code, there's really no way to fully prevent a "man-in-the-middle" attack when saving your high score.

- David Rodriguez over 1 year ago

I see with what you @David and @kev mean. But I think i found a solution to this, its using a synchronous ajax request from the index file (home of the webSite) to a custom .php file hosted in my server, so the php file will return the keys. Synchronous because this request will be made right before the time that the parse credentials are set. Also, I made the possibility to change the http url not possible. BUT since im not a php/ajax/web programmer i don't know if this solution will work because i dont know if the "heartless cracker" will be able to make any requests to this php file (holds the master and javascript key) and then make his own call to my cloudCode. So any Suggestions?

- Newton Guimarães Filho over 1 year ago

Newton, there is fundamentally nothing you can do to mitigate this attack. It's not for lack of trying either, it's simply the architecture of Parse is such that clients do have the ability to script on top of your application and make API calls in the context of the logged in user. This could potentially be a target for DDOS attacks from clients sending large amounts of data.

- GN over 1 year ago

Wouldn't support for a SSL/TLS connection to the server mitigate this by removing the plain-text of the code from view? Or am I missing something?

- Creed Erickson over 1 year ago
-2

I would implement this in with sockets and encrypt the score.

-6

I would think using REST with PHP or Python would be more secure than Javascript?