Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the possible threats while calling web services by using JQuery and how can avoid them?

I know this question can be too generic but for purposes of narrowing the question, here is a brief description:

I'm planning to forget about ASP.net UpdatePanel and move to use ajax via JQuery. I am afraid that because of the plain, client-side nature of JavaScript (and consequently JQuery code), any one looking to my web page's source can realize what is the URL of the web services I'm calling and also what are being passed to those web services.

When using UpdatePanel for these types of operations, I'm sure that calling web services is done on server-side and I have no concern regarding issues of information on calling sensitive web services being exposed publicly but now that I'm planning to use Ajax via JQuery, It worries me alot.

Are my concerns reasonable and if true, what are the best solutions for avoiding the threats of web-service-calling-info being exposed?

Clarification: when saying UpdatePanel, I mean utilizing a chain of techiques including ASP.net AJAX, code-behind and relying on server-side Dlls for performing async server-side operations instead of jquery Ajax which requires web services for intracting with server.

like image 658
Farshid Avatar asked Apr 05 '13 10:04

Farshid


3 Answers

There is no way on the internet to protect your web services all the time by just hiding the URL. I am not sure when you say your updatepanel does the web service call from the server you are not taking the true power of AJAX.

One way to secure your web service is to use the authentication in the web service side. For example you need to send some authentication key every time you access the source, and this is very common, you have so many public web service who protects it self using auth key like OpenId implementation. In case you do not want to change the web service logic I think jquery way of AJAX is not a secure option.

Here's a thought, you can have two levels of web service, one which will open for all that you can use in the jquery. From the current web service, from the server side call the other secure web service. Even now you can configure your incoming request for some specific machine IP.

In this case other than your own server no body else can access to the web service securely kept behind the firewall. It is something similar we do while connecting to database server from application server.

Let me know if this helps.

like image 167
Devesh Avatar answered Oct 13 '22 02:10

Devesh


I'm going to state the problems my answer is hoping to solve:

  1. Assuming you host your services on a machine other than the web server, the problem is you give potential attackers the name/address of those machines.

  2. Attackers can write scripts/bots to scrape your data.

  3. Attackers can focus on your web services and try to hack them/gain access to your network.

  4. Attackers can try to perform a DoS/DDoS on your web services.

The solution I've used in the past is to create a light weight proxy on the web server such that all AJAX calls simply point back to the current domain. Then when a call comes in, it is simply routed to the appropriate web service, which is hosted somewhere internally on the network.

It creates one additional hop on the network, but it also has these benefits:

  1. It hides the actual IP of the machine hosting your services.
  2. You can easily lock down that one web server and monitor unusual activity. If you see a spike in activity, you can potentially shut down the web services. (If you use a different machine, you'd have to monitor two boxes. Not a huge problem, but easier to monitor just one.)
  3. You can easily put a distributed caching layer in the proxy. This protects you from load/denial of service (DoS) attacks and obviously supports normal web service traffic.
  4. You can hide the authentication at the proxy level. The public calls won't betray your authentication scheme. Otherwise an attacker can see what tokens or keys or secrets or whatever that you use. Making a proxy on the web server hides that information. The data will still flow through, but again you can monitor it.

The real benefit in my opinion is that it reduces the surface area of your application which narrows what an attacker can do.

like image 21
ryan1234 Avatar answered Oct 13 '22 00:10

ryan1234


Since you refer to ASP.Net, know its viewstate can easily be decrypted. There's no failproof ways to protect your code (not to say urls called). If you're web services are called with some parameters that could allow unrestricted and dangerous actions, then you'd better start using some users/roles/rights management.

If you're worried about "man in the middle" attacks, you best option is to use https.

like image 2
Serge Avatar answered Oct 13 '22 00:10

Serge