If one wishes to sanitize HTML input, he has to use a library like HtmlSanitizer. Example:
var sanitizer = new HtmlSanitizer();
var sanitized = sanitizer.Sanitize(model.htmlInput);
Is it possible to instead declare that this member should be sanitized with an attribute:
public class Model
{
[HtmlSanitizer]
public string HtmlInput {get; set;}
}
Then sanitize the html and pass it along? Similar to how we do with [Required] or [Range(1,Int32.MaxValue)], which enforces constraints in the model.
private string _description; public string Description { get => _description; set => _description = _sanitizer.Sanitize(value); }but I'm leaving this as it is a valuable question. Sanitisation is easily forgotten if we run it manually on each class member in each service...