Skip to content

Commit 6142d3b

Browse files
committed
Use HtmlSanitizer in NewsItemApiController
1 parent 6233d73 commit 6142d3b

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/Modules/SimplCommerce.Module.News/Areas/News/Controllers/NewsItemApiController.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.Linq;
44
using System.Threading.Tasks;
5+
using Ganss.Xss;
56
using Microsoft.AspNetCore.Authorization;
67
using Microsoft.AspNetCore.Http;
78
using Microsoft.AspNetCore.Mvc;
@@ -27,6 +28,7 @@ public class NewsItemApiController : Controller
2728
private readonly INewsItemService _newsItemService;
2829
private readonly IMediaService _mediaService;
2930
private readonly IWorkContext _workContext;
31+
private readonly HtmlSanitizer _htmlSanitizer = new();
3032

3133
public NewsItemApiController(IRepository<NewsItem> newsItemRepository, INewsItemService newsItemService, IMediaService mediaService, IWorkContext workContext)
3234
{
@@ -127,8 +129,8 @@ public async Task<IActionResult> Post(NewsItemForm model)
127129
MetaTitle = model.MetaTitle,
128130
MetaKeywords = model.MetaKeywords,
129131
MetaDescription = model.MetaDescription,
130-
ShortContent = model.ShortContent,
131-
FullContent = model.FullContent,
132+
ShortContent = _htmlSanitizer.Sanitize(model.ShortContent),
133+
FullContent = _htmlSanitizer.Sanitize(model.FullContent),
132134
IsPublished = model.IsPublished,
133135
CreatedBy = currentUser,
134136
LatestUpdatedBy = currentUser
@@ -172,8 +174,8 @@ public async Task<IActionResult> Put(long id, NewsItemForm model)
172174
newsItem.MetaTitle = model.MetaTitle;
173175
newsItem.MetaKeywords = model.MetaKeywords;
174176
newsItem.MetaDescription = model.MetaDescription;
175-
newsItem.ShortContent = model.ShortContent;
176-
newsItem.FullContent = model.FullContent;
177+
newsItem.ShortContent = _htmlSanitizer.Sanitize(model.ShortContent);
178+
newsItem.FullContent = _htmlSanitizer.Sanitize(model.FullContent);
177179
newsItem.IsPublished = model.IsPublished;
178180
newsItem.LatestUpdatedOn = DateTimeOffset.Now;
179181
newsItem.LatestUpdatedBy = currentUser;

0 commit comments

Comments
 (0)