I am trying to implement antiXSS as in the example http://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/avoiding-cross-site-scripting-xss-attacks-with-antixss-in/ Can anybody figure out what am i missing here. It didn't happened as expected.
This is what i am still getting.
What i have done so far is, I have added antiXSS library. I can confirm it from the reference so added antiXsslibrary and HtmlSanitazationLibrary. In web config I have added this as well httpruntime encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" (not allowing to copy paste the exact code)
In the controller class i have updated the following.
[HttpPost]
[ValidateAntiForgeryToken]
[ValidateInput(false)]
public ActionResult Create([Bind(Include = "CourseID,Title,Credits,DepartmentID,Link")]Course course)
{
try
{
if (ModelState.IsValid)
{
course.Link = Sanitizer.GetSafeHtmlFragment(course.Link);
db.Courses.Add(course);
db.SaveChanges();
return RedirectToAction("Index");
}
}
catch (DbEntityValidationException ex /* dex */)
{
string er="";
//Log the error (uncomment dex variable name and add a line here to write a log.)
foreach (var entityValidationErrors in ex.EntityValidationErrors)
{
foreach (var validationError in entityValidationErrors.ValidationErrors)
{
er+="Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage;
}
}
ModelState.AddModelError("", er);
}
PopulateDepartmentsDropDownList(course.DepartmentID);
return View(course);
}
Sanitizer.GetSafeHtmlFragment is not shaking off the html code. What on earth am i missing.
should be removed. Otherwise as i have shown in the example above if the view was allowing HTML to render then its the simplest vulnerability that AntiXSS can't handle it. – user3835887 Oct 28 '16 at 19:31