How do I make sure the data sent to WebService using jQuery AJAX is through my site and not some attack

自闭症网瘾萝莉.ら 提交于 2019-11-28 14:17:01

You could implement a lightweight MAC-ing mechanism using a Hash Key (known only to you)

  1. Before each call to the webservice feed the first n bytes of your message payload to the hash key and compute a hash value.
  2. Make the call to your webservice, sending the hash value in an http header (I recommend the authorization header, you can create a custom header tho.
  3. In your webservice, before honouring any service request, you verify the authenticity of the message by computing the hashvalue using the same data i.e. the first N bytes and compare with the hash value in the authorization header. Honour the request only if the value checks out.

There is a little processing overhead here and it assumes that the transmission is happening over a secure line, otherwise, the message could still be hijacked. But you solve the problem of bogus calls.

Sessions might be the easiest solution to this problem, depending on your server framework.

After a successful login, open a session on the server and set a value; check for the session value before processing any of your other web service APIs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!