What are some methods for preventing users from tampering with game properties (i.e. hacking the game) in Javascript based games?
Consider the game to be a Javascript-based (MEAN stack) multiplayer RPG where you can walk around a map, open chests, etc.
Properties are stored server-side. These properties include things about a character's state such as: current position, current HP, items in inventory, etc. Updates to the server are performed to save client property changes (i.e. character position changed, picked up an item, etc).
As a game hacker, I could modify the properties on the client side so that when the game saves to the server, it saves my modified properties (i.e. set game.player.hp = 99999). Btw, I don't believe that using things like revealing module pattern could prevent access to 'private' properties, it would just make it a bit more difficult as it could be re-instantiated by the hacker.
How can this be prevented? What are the best practices?
I have read that server-side validation is required to prevent forgery. This might require recording a "transaction tape" of commands since the last update, then simulating these commands and assessing their validity against the game's rules. This validation seems like it would be extremely difficult to perfect.
I wonder if there could be some sort of token service that is passed from the server to the client to guarantee that an update is coming from an authorized source. However I feel like this would have enough client-side interaction that would allow a hacker to emulate this process and circumvent it.
The other option would be to leave every single property update to the server on every single modification (no timed polling or anything). For example, not just upon opening a treasure chest, but even on player movement. If the player presses 'W' to move forward, it would execute a function playerMove('forward') which sends up to the server for validation/storage. Infrequent changes like opening a chest would be simple in this model, but frequent changes, like player movement, don't seem feasible.