-
Notifications
You must be signed in to change notification settings - Fork 106
Fix stored XSS in TextHTML plugin via HTML sanitization #2406
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| else | ||
| { | ||
| <div class="f-html-content"> | ||
| @((MarkupString)Item.Content) | ||
| @((MarkupString)_sanitizedContent) | ||
| </div> | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,16 +1,22 @@ | ||||||||||||||||||||||||||
| using Ganss.Xss; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| namespace FluentCMS.Web.Plugins.TextHTML; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| public partial class TextHTMLViewPlugin | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| private const string CONTENT_TYPE_NAME = nameof(TextHTMLContent); | ||||||||||||||||||||||||||
| private TextHTMLContent? Item { get; set; } | ||||||||||||||||||||||||||
| private static readonly HtmlSanitizer Sanitizer = new(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private string _sanitizedContent = string.Empty; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private async Task UpdateContent(string content) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| if (Item is null) | ||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Item.Content = content; | ||||||||||||||||||||||||||
| _sanitizedContent = Sanitizer.Sanitize(Item.Content); | ||||||||||||||||||||||||||
|
Comment on lines
18
to
+19
|
||||||||||||||||||||||||||
| Item.Content = content; | |
| _sanitizedContent = Sanitizer.Sanitize(Item.Content); | |
| var sanitized = Sanitizer.Sanitize(content); | |
| Item.Content = sanitized; | |
| _sanitizedContent = sanitized; |
Copilot
AI
Mar 30, 2026
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.
response.Data.ToContentList<TextHTMLContent>() is computed multiple times in this block. Consider materializing it once into a local variable (e.g., var items = ...) and then using items.Count/items.FirstOrDefault() to reduce repeated work and simplify the conditionals.
| if (response?.Data != null && response.Data.ToContentList<TextHTMLContent>().Count != 0) | |
| { | |
| Item = response.Data.ToContentList<TextHTMLContent>().FirstOrDefault() ?? default!; | |
| _sanitizedContent = Item is not null ? Sanitizer.Sanitize(Item.Content) : string.Empty; | |
| if (response?.Data != null) | |
| { | |
| var items = response.Data.ToContentList<TextHTMLContent>(); | |
| if (items.Count != 0) | |
| { | |
| Item = items.FirstOrDefault() ?? default!; | |
| _sanitizedContent = Item is not null ? Sanitizer.Sanitize(Item.Content) : string.Empty; | |
| } |
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.
This change sanitizes the non-admin render path, but the admin preview path still passes
Item.ContentintoInlineEditor.InlineEditorinitializes by assigninginnerHTML = content(seeInlineEditor.razor.js), so stored XSS will still execute for admins when previewing/editing. Consider feeding_sanitizedContenttoInlineEditoras well (or sanitizing insideInlineEditorbefore settinginnerHTML).