获取javascript中函数的长度
我正在使用nodejs和nowjs。我想获取调用服务器上函数的函数的主体长度并检查它是否相同。防止用户操纵客户端功能。并且可能排除可能改变的变量。有没有办法在 JavaScript 中做到这一点?
例如
客户端
now.sendMessage() {
//Some code...
}
服务器
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
}
}
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
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可以这样做:http://jsfiddle.net/RsrCB/1/。
但在实践中,它并不可靠。由于多种原因,无法检查 JavaScript 代码的完整性:
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:
尝试一下:
有了这些知识,您还可以计算函数体的一些哈希值并进行比较。
Try this:
With that knowledge you can also calculate some hash over the body of the function and compare those.
你现在的使用是错误的。您不能信任该用户。
现在,您只需在客户端定义过程并使用一些数据调用它们即可。您不会像这样传递敏感数据。
您发送给客户端的任何数据都属于客户端,您无法屏蔽劫持。
现在在底层使用 websockets 或 XHR。您只需通过套接字向客户端发送数据,它就可以被拦截。
Your using now wrong. You cannot trust the user.
With now you just define procedures on the client and call them with some data. You do not pass sensitive data like this.
Any data you send to the client belongs to the client, you cannot shield against hijacking.
now uses websockets or XHR underneath. Your simply sending data to a client on a socket, it can be intercepted.