views:

247

answers:

1

I have a pretty simple ASP.NET MVC page and am using TinyMCE to allow users to enter comments. However, when I pass the data to a controller I receive the following error message:

A potentially dangerous Request.Form value was detected from the client

The consensus is that ValidateInput("false") should be set on the Action method but somehow that does not sit well with me. I have tried to intercept this by ordering my action methods and sanitizing the data through my ActionExecitomgContext ActionParameters however this error keeps occurring time and again. Does anyone know of a way to allow this content through (or properly intercept it) without disabling ValidateInput

+1  A: 

Do you have specifics on why it doesn't sit well? ValidateInput("false") on the one action that accepts HTML is the proper way to go. The input validation is an old ASP.NET feature that is on by default for security in depth, but is like a sledge hammer. It doesn't understand the nuances of allowed HTML.

For that one action method, you could write your own ValidateSafeHtmlAttribute action filter and put that on the method instead. Maybe that one internally encapsulates a ValidateInput set to false and then does its own validation specific to your scenario. That'd be my recommendation.

Haacked
Thanks for the advice. My concern was essentially the hole you leave when you remove the sledgehammer...Wherever possible I prefer to leave in-built security mechanisms intact rather than plugging my own...it looks like in this case, especially because validateInput acts as an IAuthorizationFilter, I'll have to roll my own. Thanks again!
JP
Well, in this case, the sledgehammer is protecting a Faberge egg and in protecting it, it destroys the thing you're protecting. ;) (ok, bad analogy).You might also look at http://www.codeplex.com/AntiXSS library which you could call to try and scrub the input manually.
Haacked