-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add HtmlSanitizerOptions #359
Merged
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1ad5bc5
Add a constructor that takes HtmlSanitizerOptions
vanillajonathan 15f3438
Create HtmlSanitizerOptions.cs
vanillajonathan f695457
Update HtmlSanitizerOptions.cs
vanillajonathan c48510c
Update HtmlSanitizerOptions.cs
vanillajonathan a4cb09f
Update HtmlSanitizerOptions.cs
vanillajonathan c546954
Update HtmlSanitizer.cs
vanillajonathan 3de042b
Update HtmlSanitizerOptions.cs
vanillajonathan 4310587
Update HtmlSanitizer.cs
vanillajonathan 02beb04
Update HtmlSanitizerOptions.cs
vanillajonathan 454b5d7
Update HtmlSanitizerOptions.cs
vanillajonathan 3530ba6
Update HtmlSanitizerOptions.cs
vanillajonathan 96cef32
Update HtmlSanitizerOptions.cs
vanillajonathan d46e769
Update Tests.cs
vanillajonathan b21e34a
Set comparer
vanillajonathan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using AngleSharp.Css.Dom; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Ganss.XSS | ||
{ | ||
/// <summary> | ||
/// Provides options to be used with <see cref="HtmlSanitizer"/>. | ||
/// </summary> | ||
public class HtmlSanitizerOptions | ||
{ | ||
/// <summary> | ||
/// Gets or sets the allowed tag names such as "a" and "div". | ||
/// </summary> | ||
public ISet<string> AllowedTags { get; set; } = new HashSet<string>(); | ||
|
||
/// <summary> | ||
/// Gets or sets the allowed HTML attributes such as "href" and "alt". | ||
/// </summary> | ||
public ISet<string> AllowedAttributes { get; set; } = new HashSet<string>(); | ||
|
||
/// <summary> | ||
/// Gets or sets the allowed CSS classes. | ||
/// </summary> | ||
public ISet<string> AllowedCssClasses { get; set; } = new HashSet<string>(); | ||
|
||
/// <summary> | ||
/// Gets or sets the allowed CSS properties such as "font" and "margin". | ||
/// </summary> | ||
public ISet<string> AllowedCssProperties { get; set; } = new HashSet<string>(); | ||
|
||
/// <summary> | ||
/// Gets or sets the allowed CSS at-rules such as "@media" and "@font-face". | ||
/// </summary> | ||
public ISet<CssRuleType> AllowedAtRules { get; set; } = new HashSet<CssRuleType>(); | ||
|
||
/// <summary> | ||
/// Gets or sets the allowed URI schemes such as "http" and "https". | ||
/// </summary> | ||
public ISet<string> AllowedSchemes { get; set; } = new HashSet<string>(); | ||
|
||
/// <summary> | ||
/// Gets or sets the HTML attributes that can contain a URI such as "href". | ||
/// </summary> | ||
public ISet<string> UriAttributes { get; set; } = new HashSet<string>(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't these have private setters? Also, they should be initialized with
StringComparer.OrdinalIgnoreCase
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I would want public setters because then I can easily assign a set to the properties using object initializer syntax. Without a setter, I would have to loop over a set and append each item in the set using the
Add
method.Yes, it should probably be initialized with
StringComparer.OrdinalIgnoreCase
if we want it to be case-insensitive, which we probably do want.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use object and collection initializer syntax even if the setter is private. Collection initializer syntax works with the
Add()
method so you can do this:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. but you cannot assign from a predefined set like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, then how about making them init-only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! I like that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's this problem now. Not sure how to deal with it or if it's even worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems easier to just skip
init
and just have public setters instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah ok, I agree.