How to prevent variable injection in javascript and html5 games

I used this html5 Snake game on my website, but the problem is that it can be easily hacked.

http://cssdeck.com/labs/classic-snake-game-with-html5-canvas

Hackers can enter ratings and submit their own ratings.

In any case, in order to protect the counter variable inside the script that cannot be entered by clients?

+6
source share
1 answer

While the game is fully implemented on the client side. The "solution" is to implement the rules of the game and storage on the server side, and the client should be mainly a user interface, but this may be redundant for such a simple browser game.

You could make it harder by messing up the code, but this will stop people who don't really care.

If the game is deterministic, you can keep a log of all game "events" and send them to the server, where the score will be calculated. This would make more work to fake the bill, but you could still fake it, and there would be a lot of work to create such a system.

+7
source

Source: https://habr.com/ru/post/973078/


All Articles