Disclaimer: This is a terrible method and probably too much effort than it is worth.
Suppose that you had a method of processing the javascript code before you sent it.
First of all, every method has a ident variable which is attached to the result of every function (i.e. every function would return {ident:"special code",result:"actual useful function result"}
). You also have a testIdent()
function which would accept the function name to call as well as "test data" to give it (if any is needed). The purpose of testIdent()
would be to send the ident returned from said function to the server for verification (the idea being that the server can request a test whenever you deem it appropriate). The ident for every function should be randomized and recorded specially for the specified user before sent.
Second, before the code is sent to the client, the function order is randomized and function names are obfuscated in some random fassion. This way there is no way for a hacker to look for some variable ident in function x() as it will be named randomly. Also, it would be another plus if every variable name is obfuscated randomly as well, just to add yet another step to the complication and headaches of... well... everyone (I told you this is a terrible method).
Now, assuming proper steps are taken to make sure the code will always function correctly, hackers are very cleaver people, and there are still ways for hackers to track this code if they are determined enough. At least one way will be to search for key code structures, such as a switch
statement with a certain number of elements, or a for loop with x number of statements, etc. While each of these can be countered, say by adding dummy case
statements in the switches or a couple of if(true)
bits randomly throughout the code, countering hackers will always be a constant (and possibly a loosing) battle.
Hopefully this can give you some ideas. I don't know how someone would implement this exactly, but it is at least an idea.
Good luck!