HtmlSanitizerOptions.cs 2.2 KB

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