CsQuery
CsQuery copied to clipboard
Sanitize HTML - Feature
It would be nice to add some method for easy sanitizing HTML - remove any javascript, forms and other dangerous stuff.
var doc = CQ.Create(original);
doc[selector].RemoveUnsafeHTML();
var html = doc.Render();
I know I can write it myself with existing library, but I don't think a newbie like me can prevent some 'advanced' XSS techniques because I don't know HTML well enough.
I think this would be a good idea for an extension method. I'm not totally convinced it belongs in the core library because it's really an application of its own, and I would think something like this could have a lot of configuration, etc.
But there is no question it's a very common application and belongs somewhere nearby, along with some other useful add-ons (like something to pretty-format HTML). I will think about this for the next version.
Just an FYI, this has already been done in a project that uses CsQuery: https://github.com/mganss/HtmlSanitizer - perhaps it would be worth creating a combined project?