HTML sanitizationSitefinity CMS leverages the out-of-the-box HTML sanitizer to ensure HTML content, for example, scripts or tags, is safe and does not cause security vulnerabilities to your system. The reason is that raw HTML data may come from a variety of sources. The HTML sanitizer avoids cross-site scripting (XSS) attacks while in the meantime allowing users to contribute with HTML markup and content. The HTML sanitizer is configured to work out-of-the-box with built-in widgets to ensure elements from untrusted sources are stripped and are not displayed. The sanitizer identifies elements as untrusted if they are not included in the whitelist.
NOTE: If you are upgrading from versions older than Sitefinity CMS 10.2 and you want to leverage the HTML sanitizer whitelist capabilities, you need to manually switch on the sanitizer. To do so, navigate to Administration » Settings » Advanced » Security. Make sure the Disable HTML sanitization checkbox is not selected. We recommend that once you switch on the HTML sanitizer, you test your website for potential issues with HTML content and content editing.
Enable HTML sanitizer for custom widgets
You use the HTML sanitizer API for your custom widgets, widget templates, and views, so that untrusted content is filtered out.
Web Forms Sanitizer API
To use the HTML sanitizer in Web Form widgets, you call the following static methods in the Telerik.Sitefinity.Web.UI.ControlUtilities class:
- string Sanitize(string), string Sanitize(object)
You use these methods to remove or encode parts of the HTML content in the provided parameter. This content may include dangerous or potentially dangerous elements, for example, <script> tags or unescaped attribute values, so that the HTML content returned is safe to be displayed.
- string SanitizeUrl(string)
Feather Sanitizer API
When working with Feather, you need to use the following helper methods in the Telerik.Sitefinity.Frontend.Mvc.Helpers namespace:
Modify the HTML sanitizer configuration
In case your website scenario requires you to change the list with whitelisted elements, you can modify the default configuration of the HTML sanitizer. To do this, you create a new HTML sanitizer that extends the out-of-the-box capabilities of the default sanitizer and adds more elements to the whitelist. The following sample demonstrates how to add a custom_attribute
to the HTML sanitizer whitelist:
Modify the HTML sanitizer configuration with the .NET Core application renderer
If you have the .NET Core application setup as your renderer, in addition to the changes made in Sitefinity CMS, changes to the .NET core application must be made as well. This sample shows how to add attributes to the whitelesited elements:
After that you register the dependency injection in the
For more information you can review this sample project in GitHub.