Search code examples
javascriptnode.jsnowjs-sockets

Get length of a function in javascript


I'm using nodejs and nowjs. I want to get the body length of the function that is calling the function on the server and check if it is the same. To prevent users from manipulating the client side function. And possibly excluding variables that may change. Is there a way to do this in javascript?

eg

client

now.sendMessage() {
    //Some code...
}

server

everyone.now.sendMessage() {
    //Check that the code is the exact length 
    //as the function body written in the clientside script
    //To see if it has been manipulated...
    if (codelength === ?) {
        //execute code
    } else {
       //return error
    }
}

Solution

  • It can be done: http://jsfiddle.net/RsrCB/1/.

    But in practice, it's not reliable. JavaScript code can't be checked for integrity for several reasons:

    • It's easy to obfuscate it
    • It's easy to override the integrity-checking code