c# - How to sanitize input from MCE in ASP.NET? -
is there utility/function in c# sanitize source code of tinymce rich text. remove dangerous tags whitelist safe html tags.
i don't think there built-in sanitizer c# can use here did when had same issue. used htmlagilitypacksanitizerprovider comes ajaxcontroltoolkit. code looks this:
private static ajaxcontroltoolkit.sanitizer.htmlagilitypacksanitizerprovider sanitizer = new ajaxcontroltoolkit.sanitizer.htmlagilitypacksanitizerprovider(); private static dictionary<string, string[]> elementwhitelist = new dictionary<string, string[]> { {"b" , new string[] { "style" }}, {"strong" , new string[] { "style" }}, {"i" , new string[] { "style" }}, {"em" , new string[] { "style" }}, {"u" , new string[] { "style" }}, {"strike" , new string[] { "style" }}, {"sub" , new string[] { "style" }}, {"sup" , new string[] { "style" }}, {"p" , new string[] { "align" }}, {"div" , new string[] { "style", "align" }}, {"ol" , new string[] { }}, {"li" , new string[] { }}, {"ul" , new string[] { }}, {"a" , new string[] { "href" }}, {"font" , new string[] { "style", "face", "size", "color" }}, {"span" , new string[] { "style" }}, {"blockquote" , new string[] { "style", "dir" }}, {"hr" , new string[] { "size", "width", "id" }}, {"img" , new string[] { "src" }}, {"h1" , new string[] { "style" }}, {"h2" , new string[] { "style" }}, {"h3" , new string[] { "style" }}, {"h4" , new string[] { "style" }}, {"h5" , new string[] { "style" }}, {"h6" , new string[] { "style" }} }; private static dictionary<string, string[]> attributewhitelist = new dictionary<string, string[]> { {"style" , new string[] {}}, {"align" , new string[] {}}, {"href" , new string[] {}}, {"face" , new string[] {}}, {"size" , new string[] {}}, {"color" , new string[] {}}, {"dir" , new string[] {}}, {"width" , new string[] {}}, {"id" , new string[] {}}, {"src" , new string[] {}} }; public string sanitizehtmlinput(string unsafestr) { return sanitizer.getsafehtmlfragment(unsafestr, elementwhitelist, attributewhitelist); }
hope helps.
Comments
Post a Comment