Think Before Coding

To content | To menu | To search

Thursday, January 8, 2009

Asp.net MVC binding security issue

There’s a post on CodeThinked about a serious potential security issue.

The problem comes from an MVC convenience that when using an object as a controller action parameter, Asp.net MVC will bind the form fields to object properties auto-magically. Read the full post for a complete description.

I would recommend a solution using a presentation only model. There is a good reason for this.

The model object passed to the view should not be directly the domain/business object. I always create a thin adaptation layer for presentation, even when it doesn’t add much value. I lets me decouple presentation concerns from domain concerns.

The object coming back from the form should follow the same rule as part of this presentation concerns. There is no problem if those presentation objects provide only non sensitive fields.

 

But it’s sure that not anyone will know about the risks.

Monday, December 29, 2008

Asp.Net authentication cookie oddities...

Back to low level considerations.

In order to use a specific and shareable encryption scheme between sites, we had to bypass the FormsAuthentication.Encrypt method an write a new one.

Something strange happened then. When using our implementation, the cookie disappeared !

The cookie was added to the Response.Cookies, but was not present in the Request.Cookies of the following request.

After deep search, it appeared that the cookie was actually sent to the browser. Why wouldn’t it be sent back ?

The really weird thing was that the cookie data was in the Response.Headers, but not in Response.Cookies !!!

It seems that when parsing the Cookie header, Asp.net strips off the .ASPXAUTH cookie if it cannot be decrypted by FormsAuthentication.Decrypt !

The solution was to use another cookie name, and everything was working again !

If it can save 2 hours of your precious time…