HtmlSanitizerOptions.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using AngleSharp.Css.Dom;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace Ganss.Xss;
  5. /// <summary>
  6. /// Provides options to be used with <see cref="HtmlSanitizer"/>.
  7. /// </summary>
  8. public class HtmlSanitizerOptions
  9. {
  10. /// <summary>
  11. /// Gets or sets the allowed tag names such as "a" and "div".
  12. /// </summary>
  13. public ISet<string> AllowedTags { get; set; } = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
  14. /// <summary>
  15. /// Gets or sets the allowed HTML attributes such as "href" and "alt".
  16. /// </summary>
  17. public ISet<string> AllowedAttributes { get; set; } = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
  18. /// <summary>
  19. /// Gets or sets the allowed CSS classes.
  20. /// </summary>
  21. public ISet<string> AllowedCssClasses { get; set; } = new HashSet<string>();
  22. /// <summary>
  23. /// Gets or sets the allowed CSS properties such as "font" and "margin".
  24. /// </summary>
  25. public ISet<string> AllowedCssProperties { get; set; } = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
  26. /// <summary>
  27. /// Gets or sets the allowed CSS at-rules such as "@media" and "@font-face".
  28. /// </summary>
  29. public ISet<CssRuleType> AllowedAtRules { get; set; } = new HashSet<CssRuleType>();
  30. /// <summary>
  31. /// Gets or sets the allowed URI schemes such as "http" and "https".
  32. /// </summary>
  33. public ISet<string> AllowedSchemes { get; set; } = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
  34. /// <summary>
  35. /// Gets or sets the HTML attributes that can contain a URI such as "href".
  36. /// </summary>
  37. public ISet<string> UriAttributes { get; set; } = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
  38. /// <summary>
  39. /// Allow all custom CSS properties (variables) prefixed with <c>--</c>.
  40. /// </summary>
  41. public bool AllowCssCustomProperties { get; set; }
  42. /// <summary>
  43. /// Allow all HTML5 data attributes; the attributes prefixed with <c>data-</c>.
  44. /// </summary>
  45. public bool AllowDataAttributes { get; set; }
  46. }