[Owasp-dotnet] Are .NET WebServices vulnerable to CSRF?

146 views
Skip to first unread message

dinis cruz

unread,
Feb 3, 2012, 11:43:20 AM2/3/12
to OWASP .NET, owasp-o2...@lists.owasp.org
While developing TeamMentor I implemented a number of WebServices (consumed via jQuery) and now on its final push for release I want to double check that they are not vulnerable to CSRF.

There isn't a lot of good information out there and it seems that in .NET, *.asmx are protected by default to CSRF, with a possible exception of an exploit scenario using Flash (to set the cookies)

Barry Dorrans

unread,
Feb 3, 2012, 11:45:22 AM2/3/12
to dinis cruz, OWASP .NET, owasp-o2...@lists.owasp.org

Is there a reason you went the asmx route and not with WCF?

dinis cruz

unread,
Feb 6, 2012, 6:19:24 AM2/6/12
to Barry Dorrans, owasp-o2...@lists.owasp.org, OWASP .NET
I choose asmx because:
  • They where simpler to setup
  • TeamMentor already had a couple *.asmx based webservices which where easier to extend (which I didn't want to re-write)
  • I wanted to have a dynamic compilation environment (created around App_Code folder), which seemed easier to set-up via *.asmx
  • I wanted to have as little dependencies on web.config fire, again something that *.asmx seemed easier to do via WCF
  • I also wanted to implement a CAS based Security Demand solution, which again seemed simpler to created in *.asmx
Note that I have used WCF in the past, and I really like its flexibly, but it did felt overkill for this project

Dinis Cruz

dinis cruz

unread,
Feb 6, 2012, 7:03:37 AM2/6/12
to Róbert Tézli, OWASP .NET, owasp-o2...@lists.owasp.org
I Robert, thanks for your comments (bellow).

You can actually see the app running and get its source code :) 

The whole thing is at GitHub, and here is the source code of the version with a test Library (OWASP Top 10):  https://github.com/TeamMentor-OWASP/Master  (just download the zip file and click on the 'Start webserver.bat' to have a locally running copy)

If you just want to take a look at it, check out this test server: 
In terms of CSRF for ASMX, my current understanding comes mainly from this Scott Guthrie article http://weblogs.asp.net/scottgu/archive/2007/04/04/json-hijacking-and-how-asp-net-ajax-1-0-mitigates-these-attacks.aspx (also referenced here AJAX Hacker Attacks - Cross Site Request Forgery )

Those articles imply that asmx webservices are not vulnerable to CSRF due to the extra application/json ContentType header.
On 3 February 2012 18:38, Róbert Tézli <tezli....@live.de> wrote:
I think without seeing the application nobody can help you finding out
if your application is vulnerable to attacks like CSRF.
A good point to start is checking XSS first since an attacker have to
perform the request against your web service as
trusted user. In ASP.Net Mvc 3 unique CSRF tokens are used to make sure
the request was made is unique. Since you want use JavaScript with Asp.Net
 Web Services you won't have this advantage but you could generate and
deliver CSRF token challenges with the JavaScript the user loads with
the page
assuming that you are not caching anything.

I doubt that web services are not vulnerable to CSRF since the request
that is performed against it comes from within the users browser which
has the session cookie,
the same ip and the referrer can be spoofed easily. How should the web
service know that this specific request did not came from the user but
from an other script
within the page?

Like i said, without seeing the source code (at least from the website
where the JavaScript is embedded) nobody(at least not me) could give you
an answer on that.

Regards,

Robert

> While developing TeamMentor <http://teammentor.github.com> I implemented a
> _______________________________________________
> Owasp-dotnet mailing list
> Owasp-...@lists.owasp.org
> https://lists.owasp.org/mailman/listinfo/owasp-dotnet

--
Robert Tezli
Voigstraße 39
10247 Berlin
Germany

Mail : tezli....@live.de
Phone: +4916094989708
Web  : pixills.com


dinis cruz

unread,
Feb 7, 2012, 6:56:06 AM2/7/12
to Jaideep Jha, owasp-o2...@lists.owasp.org, OWASP .NET
Hi Jaideep

I agree that the content-type header defence makes me nervous, and btw that 307 attack looks pretty interesting :)  (does it work in .NET asmx?)

But my key question remains, are .NET ASMX WebServices vulnerable to CSRF? 

There are two things that must happen for this to be a problem (in TeamMentor or other ASPX webservices)
  1. It is possible to invoke those WebServices from another domain (note that this is actually a current business/user-requirement)
  2. Will the browser send the user's cookies via the CSRF (these cookies are used by the WebService to authenticate the user)
If this is possible then we have a problem (and I need to make the required code changes)

But is it a problem?

And if so, wouldn't this be a big issue with tons of vulnerable websites out there?

Finally, are there any recommended solutions?
On 7 February 2012 05:19, Jaideep Jha <jaide...@gmail.com> wrote:
Why should content-type header be considered good enough CSRF defense ?

Many sites have incorrectly configured crossdomain.xml files (allow-access-from domain="*") - thus making cross domain requests with arbitrary header / header values from swf files a trivial attack vector.

Also, even if the cross domain policy files are correctly configured, I have seen the 307 redirect attack - as explained here - working well till very recently across browsers.

Regards,
Jaideep

_______________________________________________
Owasp-o2-platform mailing list
Owasp-o2...@lists.owasp.org
https://lists.owasp.org/mailman/listinfo/owasp-o2-platform



Reply all
Reply to author
Forward
0 new messages