How to protect JS from user events

I am writing a Javascript game with canvas and easeljs and I am wondering if there are ways to protect it. For example, I use stage.Addchild(index) to add a new object to the scene. Just editing the DOM, I can hook up a new event handler and run it, something like <body onclick="stage.removeChild(0)"> , and this will delete all the objects in the scene one by one.

I thought to filter out all upcoming events and check what worked. But I'm not sure how to do this, and there may be better ways to do this ... Please point me in the right direction ...

0
source share
1 answer

The best way to protect your Javascript is to put all your initialization code in closure and not set anything against global variables.

However, this provides only some guarantees against namespace conflicts at run time and is intended to be used as a good development practice.

You cannot trust client-side code; for anti-cheat behavior, you need to check the server-side incoming inputs. Users have 100% control over what works in their browsers, and this includes controls to change your code as they see fit.

+2
source

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


All Articles