-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-gvpc-3pj6-4m9w
* Add MarkDownPropertyValueEditor with html sanitizer * Implement IMarkdownSanitizer.
- Loading branch information
Showing
5 changed files
with
71 additions
and
1 deletion.
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
39 changes: 39 additions & 0 deletions
39
src/Umbraco.Core/PropertyEditors/MarkDownPropertyValueEditor.cs
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,39 @@ | ||
using Umbraco.Cms.Core.IO; | ||
using Umbraco.Cms.Core.Models.Editors; | ||
using Umbraco.Cms.Core.Security; | ||
using Umbraco.Cms.Core.Serialization; | ||
using Umbraco.Cms.Core.Services; | ||
using Umbraco.Cms.Core.Strings; | ||
using Umbraco.Extensions; | ||
|
||
namespace Umbraco.Cms.Core.PropertyEditors; | ||
|
||
/// <summary> | ||
/// A custom value editor to ensure that macro syntax is parsed when being persisted and formatted correctly for | ||
/// display in the editor | ||
/// </summary> | ||
internal class MarkDownPropertyValueEditor : DataValueEditor | ||
{ | ||
private readonly IMarkdownSanitizer _markdownSanitizer; | ||
|
||
public MarkDownPropertyValueEditor( | ||
ILocalizedTextService localizedTextService, | ||
IShortStringHelper shortStringHelper, | ||
IJsonSerializer jsonSerializer, | ||
IIOHelper ioHelper, | ||
DataEditorAttribute attribute, | ||
IMarkdownSanitizer markdownSanitizer) | ||
: base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) => _markdownSanitizer = markdownSanitizer; | ||
|
||
public override object? FromEditor(ContentPropertyData editorValue, object? currentValue) | ||
{ | ||
if (string.IsNullOrWhiteSpace(editorValue.Value?.ToString())) | ||
{ | ||
return null; | ||
} | ||
|
||
var sanitized = _markdownSanitizer.Sanitize(editorValue.Value.ToString()!); | ||
|
||
return sanitized.NullOrWhiteSpaceAsNull(); | ||
} | ||
} |
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,14 @@ | ||
namespace Umbraco.Cms.Core.Security; | ||
|
||
/// <summary> | ||
/// Sanitizer service for the markdown editor. | ||
/// </summary> | ||
public interface IMarkdownSanitizer | ||
{ | ||
/// <summary> | ||
/// Sanitizes Markdown | ||
/// </summary> | ||
/// <param name="markdown">Markdown to be sanitized</param> | ||
/// <returns>Sanitized Markdown</returns> | ||
string Sanitize(string markdown); | ||
} |
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,8 @@ | ||
namespace Umbraco.Cms.Core.Security; | ||
|
||
/// <inheritdoc /> | ||
public class NoopMarkdownSanitizer : IMarkdownSanitizer | ||
{ | ||
/// <inheritdoc /> | ||
public string Sanitize(string markdown) => markdown; | ||
} |