views:

94

answers:

1

Hi,

I'm planning work on a new project and am now tempted to use ASP.NET MVC. My project plans to use JQuery and AJAX (although non-JS clients will also be supported). Coming from a standard ASP.NET background, I'm still trying to get my head around the MVC paradigm (with great help from Scott Guthrie). However, my main concern with using MVC is the security aspects. I've done quite a bit of security with ASP.NET and I know how to handle various attack vectors. Will I need to re-learn security with ASP.NET MVC? Are there new threats, or even new ways of handling old threats, that I will have to read up on? I've ordered a couple of ASP.NET MVC books (which have chapters on security), but I would like to know of anyone else's experience of this.

Thanks

+2  A: 

Depends on what you mean by security.

Authorization is basically the same, if not easier. Forms Authentication is supported and encouraged and you need only stick an [Authorize] attribute on controllers or controller actions. Not too much to learn there.

ViewState is gone, so you don't need to worry about ViewState validation or any of that kludge.

If you're referring to XSS, I would say that it's about the same; you need to escape your data on the output and it's very easy to do:

<%= Html.Encode(Model.SomeString) %>

The only thing I can think of that you might find a bit different is handling CSRF/XSRF. Fortunately, most of this is already built in to the framework.

So on the whole I'd say no, the learning curve for security in ASP.NET MVC should not be nearly as steep as the learning curve for the architecture itself.

Aaronaught
Thanks, this makes it that much easier to get over the learning curve. On a side note, if I use `UpdateModel()`, does it automatically HTMLEncode my data? I understand I have to do it manually when passing model objects, but not quite sure what to do when using UpdateModel. Thanks again.
keyboardP
@TenaciousImpy: You only need to worry about encoding/escaping on the way out, when the data you are presenting may have come from an untrusted source. With few exceptions, it's not really necessary to sanitize what's coming in (I assume you parameterize your SQL queries and all that). But to answer your exact question, no, `UpdateModel` does not HTML Encode your data, because then you would have encoded it twice by the time it gets displayed and your site visitors would see weird escaped `>`s in the middle of words.
Aaronaught
With ASP.NET MVC 2, `<%: Model.SomeString %>` auto encodes text for you. Note the `:` instead of `=`.
Baddie
Yup, using parameterized queries. Thanks for the help!
keyboardP