I need to add some Xss protection in an application MVC views, that are currently using Json.Net and Javascript Widgets. The ViewModels are extremely big and complex, so i can't use the Microsoft AntiXss library to javascriptEncode properties, so i need to do this in the View.
dataBindings: new
{
inputs = new
{
widgetType = "textbox",
value = new JRaw("myPropertyName")
}
}
The Javascript widget controls currently consume json data in the form of JRaw objects. I would like to create a wrapper around the JRaw object, either in form of subclass or utility method to javascript encode string properties before sending to the control to bind.
public static JRaw JRawEncode(JRaw rawObj)
{
if (rawObj != null && rawObj.Value.GetType() == typeof (String))
{
//Microsoft.Security.Application.Encoder.JavaScriptEncode(rawValue);
}
return rawObj;
}
Is this possible to do on the JRaw object or am i way off? Is there another way to do this with Json.NET? I am new to Json.Net and Xss encoding here, so be gentle please.