22using System . IO ;
33using System . Linq ;
44using System . Threading . Tasks ;
5+ using Ganss . Xss ;
56using Microsoft . AspNetCore . Authorization ;
67using Microsoft . AspNetCore . Http ;
78using 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