Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Security: Replace NoScripts blacklist with allowlist HTML sanitization (#780)
Krzysztof Pajak41a8e349eab8
diff --git a/Directory.Packages.props b/Directory.Packages.propsindex 6fdf625a4..448f8b957 100644--- a/Directory.Packages.props+++ b/Directory.Packages.props@@ -5,6 +5,7 @@<ItemGroup><PackageVersion Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.6.0" /><PackageVersion Include="ExcelMapper" Version="6.0.641" />+ <PackageVersion Include="HtmlSanitizer" Version="9.2.995" /><PackageVersion Include="MessagePack" Version="3.1.8" /><PackageVersion Include="Microsoft.AspNetCore.Http" Version="2.3.11" /><PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.10" />diff --git a/src/Core/Grand.Infrastructure/Configuration/SecurityConfig.cs b/src/Core/Grand.Infrastructure/Configuration/SecurityConfig.csindex 2b2a2b63b..db88abcbf 100644--- a/src/Core/Grand.Infrastructure/Configuration/SecurityConfig.cs+++ b/src/Core/Grand.Infrastructure/Configuration/SecurityConfig.cs@@ -93,4 +93,21 @@ public class SecurityConfig/// The value is embedded in each stored hash, so raising it later does not break existing hashes./// </summary>public int PasswordHashIterations { get; set; }++ /// <summary>+ /// Hosts whose iframes survive HTML sanitization of rich-text content (product descriptions, blog posts, pages).+ /// An iframe pointing anywhere else is removed, because its src is otherwise attacker-controlled.+ /// Matching is case-insensitive on the host only; a leading "*." matches any subdomain.+ /// Leave empty to fall back to the built-in video-embed defaults; set to a single empty entry to block every iframe.+ /// </summary>+ public string[] SanitizerAllowedIframeHosts { get; set; }++ /// <summary>+ /// Gets or sets a value indicating whether [SanitizeHtml] and [NoHtml] reject markup on save. Default true.+ /// This is an operational escape hatch, not a security setting: turn it off only temporarily, if the+ /// allowlist is found to reject legitimate content in production, while a fix is prepared - every field+ /// these attributes guard (Vendor/Store-manager-editable rich text rendered unencoded via Html.Raw/v-html)+ /// goes back to accepting raw, unsanitized HTML the moment this is false. Re-enable as soon as possible.+ /// </summary>+ public bool EnableHtmlSanitization { get; set; } = true;}\ No newline at end of filediff --git a/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj b/src/Core/Grand.Infrastructure/Grand.Infrastructure.csprojindex 6c0003b5e..f33293af1 100644--- a/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj+++ b/src/Core/Grand.Infrastructure/Grand.Infrastructure.csproj@@ -3,6 +3,7 @@<ItemGroup><PackageReference Include="FluentValidation.DependencyInjectionExtensions" /><PackageReference Include="GoogleAuthenticator" />+ <PackageReference Include="HtmlSanitizer" /><PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" /><PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" /><PackageReference Include="Microsoft.Extensions.Caching.Memory" />diff --git a/src/Core/Grand.Infrastructure/Security/HtmlSanitizationService.cs b/src/Core/Grand.Infrastructure/Security/HtmlSanitizationService.csnew file mode 100644index 000000000..1de4e228e--- /dev/null+++ b/src/Core/Grand.Infrastructure/Security/HtmlSanitizationService.cs@@ -0,0 +1,243 @@+using Ganss.Xss;+using Grand.Infrastructure.Configuration;++namespace Grand.Infrastructure.Security;++/// <summary>+/// Allowlist-based implementation over HtmlSanitizer. Sanitizes nothing itself - it runs the library's+/// allowlist and reports whether anything would have been removed, which is all a rejecting+/// <see cref="System.ComponentModel.DataAnnotations.ValidationAttribute" /> needs.+/// Registered as a singleton, but holds no mutable shared state: the allowlists below (<see cref="ISet{T}" />+/// instances returned by a throwaway HtmlSanitizer during construction) are built once and never mutated+/// afterwards, so concurrent calls can read them freely. Each detection call builds its own short-lived+/// HtmlSanitizer around those shared, read-only allowlists, with event handlers that close over a local+/// "was anything removed" flag - so two concurrent calls can never observe or overwrite each other's result,+/// and no lock is needed.+/// <see cref="SecurityConfig.EnableHtmlSanitization" /> is an operational kill switch, read once at+/// construction: when false, both detection methods report "nothing disallowed" unconditionally, so+/// [SanitizeHtml]/[NoHtml] accept any input. Off by exception only - see that property's remarks.+/// </summary>+public class HtmlSanitizationService : IHtmlSanitizationService+{+ /// <summary>+ /// Hosts allowed to be framed when the configuration does not name any. These are the embed hosts a store+ /// realistically pastes into a page body; anything else has to be opted into explicitly.+ /// </summary>+ private static readonly string[] DefaultAllowedIframeHosts =+ [+ "youtube.com", "*.youtube.com",+ "youtube-nocookie.com", "*.youtube-nocookie.com",+ "vimeo.com", "*.vimeo.com",+ "google.com", "*.google.com"+ ];++ /// <summary>+ /// Tags that are in the library defaults but have no place in store content: they either collect input or+ /// submit it somewhere. A form rendered inside the admin panel is a credible phishing surface.+ /// </summary>+ private static readonly string[] InteractiveTags =+ [+ "form", "input", "button", "textarea", "select", "option", "optgroup", "label", "fieldset", "legend",+ "datalist", "output", "progress", "meter"+ ];++ private readonly string[] _allowedIframeHosts;+ private readonly bool _enabled;+ private readonly HtmlSanitizerOptions _richTextOptions;++ public HtmlSanitizationService(SecurityConfig securityConfig)+ {+ //defaults to enabled: a missing SecurityConfig or a config binder that never touched this property+ //must fail closed (sanitize), not open (accept anything)+ _enabled = securityConfig?.EnableHtmlSanitization ?? true;+ _allowedIframeHosts = ResolveAllowedIframeHosts(securityConfig);+ _richTextOptions = BuildRichTextOptions();+ }++ /// <summary>+ /// Built once from a throwaway sanitizer's defaults, then reused - unmutated - as the constructor+ /// argument for every sanitizer built per detection call below. HtmlSanitizerOptions only fills in what+ /// it is given (verified: leaving UriAttributes/AllowedCssProperties/AllowedAtRules unset produces empty+ /// sets, not the library defaults), so every allowlist a plain `new HtmlSanitizer()` would carry has to+ /// be copied across explicitly, not just the ones this class customizes.+ /// </summary>+ private static HtmlSanitizerOptions BuildRichTextOptions()+ {+ var defaults = new HtmlSanitizer();++ //the library defaults already exclude script, object, embed, svg, style and every on* handler, because+ //only allowlisted tags and attributes survive; these are the deviations from those defaults+ foreach (var tag in InteractiveTags) defaults.AllowedTags.Remove(tag);++ //framed media, restricted to allowlisted hosts by OnFilterUrl below+ defaults.AllowedTags.Add("iframe");+ defaults.AllowedAttributes.Add("allowfullscreen");+ defaults.AllowedAttributes.Add("frameborder");+ defaults.AllowedAttributes.Add("allow");+ defaults.AllowedAttributes.Add("loading");++ //editors emit class names for tables, images and alignment+ defaults.AllowedAttributes.Add("class");++ defaults.AllowedSchemes.Add("mailto");+ defaults.AllowedSchemes.Add("tel");+ //data: is accepted only for images, and only on img/src - enforced in OnFilterUrl+ defaults.AllowedSchemes.Add("data");++ return new HtmlSanitizerOptions {+ AllowedTags = defaults.AllowedTags,+ AllowedAttributes = defaults.AllowedAttributes,+ AllowedSchemes = defaults.AllowedSchemes,+ AllowedCssClasses = defaults.AllowedClasses,+ AllowedCssProperties = defaults.AllowedCssProperties,+ AllowedAtRules = defaults.AllowedAtRules,+ UriAttributes = defaults.UriAttributes,+ UriListAttributes = defaults.UriListAttributes,+ AllowCssCustomProperties = defaults.AllowCssCustomProperties,+ //data-* is not allowlisted per attribute, so it cannot be vetted; it is also read by the storefront+ //scripts, which makes it a way to influence behaviour from stored content+ AllowDataAttributes = false+ };+ }++ public bool ContainsDisallowedRichText(string html)+ {+ if (string.IsNullOrWhiteSpace(html)) return false;+ if (!_enabled) return false;++ var disallowedContentSeen = false;++ void MarkDisallowed(object sender, EventArgs e)+ {+ disallowedContentSeen = true;+ }++ void OnFilterUrl(object sender, FilterUrlEventArgs e)+ {+ var url = e.SanitizedUrl ?? e.OriginalUrl;+ if (string.IsNullOrWhiteSpace(url)) return;++ var tagName = e.Tag?.NodeName;++ if (url.StartsWith("data:", StringComparison.OrdinalIgnoreCase))+ {+ //data:text/html is a script execution vector; an inline image is not+ var isInlineImage = string.Equals(tagName, "IMG", StringComparison.OrdinalIgnoreCase) &&+ url.StartsWith("data:image/", StringComparison.OrdinalIgnoreCase);+ if (!isInlineImage)+ {+ e.SanitizedUrl = null;+ disallowedContentSeen = true;+ }++ return;+ }++ if (string.Equals(tagName, "IFRAME", StringComparison.OrdinalIgnoreCase) &&+ !IsAllowedIframeUrl(url, _allowedIframeHosts))+ {+ e.SanitizedUrl = null;+ disallowedContentSeen = true;+ }+ }++ var sanitizer = new HtmlSanitizer(_richTextOptions);+ sanitizer.RemovingTag += MarkDisallowed;+ sanitizer.RemovingAttribute += MarkDisallowed;+ sanitizer.RemovingStyle += MarkDisallowed;+ sanitizer.RemovingAtRule += MarkDisallowed;+ sanitizer.RemovingCssClass += MarkDisallowed;+ sanitizer.RemovingComment += MarkDisallowed;+ sanitizer.FilterUrl += OnFilterUrl;++ var document = sanitizer.SanitizeDom(html);++ //a literal <html>/<head>/<body> tag in the input is merged into the parser's own document root, which+ //sits outside the per-element sanitization loop - RemovingAttribute never fires for its own attributes+ //even though everything inside it is correctly sanitized (verified: <body onload=alert(1)> survives+ //with the handler intact). Rich-text content is always a fragment and never legitimately needs+ //attributes on that wrapper, so any attribute there means the raw input smuggled one in.+ if (HasOwnAttributes(document.DocumentElement) || HasOwnAttributes(document.Head) ||+ HasOwnAttributes(document.Body))+ disallowedContentSeen = true;++ return disallowedContentSeen;+ }++ public bool ContainsMarkup(string text)+ {+ if (string.IsNullOrWhiteSpace(text)) return false;+ if (!_enabled) return false;++ var disallowedContentSeen = false;++ void MarkDisallowed(object sender, EventArgs e)+ {+ disallowedContentSeen = true;+ }++ var sanitizer = new HtmlSanitizer(new HtmlSanitizerOptions {+ AllowedTags = new HashSet<string>(),+ AllowedAttributes = new HashSet<string>(),+ AllowedSchemes = new HashSet<string>(),+ AllowedCssProperties = new HashSet<string>(),+ UriAttributes = new HashSet<string>()+ });+ sanitizer.RemovingTag += MarkDisallowed;+ sanitizer.RemovingComment += MarkDisallowed;++ var document = sanitizer.SanitizeDom(text);++ //see the identical guard in ContainsDisallowedRichText - a literal <html>/<head>/<body> tag merges+ //into the document root and its own attributes never reach RemovingAttribute+ if (HasOwnAttributes(document.DocumentElement) || HasOwnAttributes(document.Head) ||+ HasOwnAttributes(document.Body))+ disallowedContentSeen = true;++ return disallowedContentSeen;+ }++ private static bool HasOwnAttributes(AngleSharp.Dom.IElement element)+ {+ return element is not null && element.Attributes.Length > 0;+ }++ private static string[] ResolveAllowedIframeHosts(SecurityConfig securityConfig)+ {+ //absent configuration means "use the defaults"; a configured but empty list means "frame nothing"+ if (securityConfig?.SanitizerAllowedIframeHosts is null) return DefaultAllowedIframeHosts;++ return securityConfig.SanitizerAllowedIframeHosts+ .Where(host => !string.IsNullOrWhiteSpace(host))+ .Select(host => host.Trim())+ .ToArray();+ }++ private static bool IsAllowedIframeUrl(string url, string[] allowedIframeHosts)+ {+ if (allowedIframeHosts.Length == 0) return false;++ //protocol-relative ("//host/path") is parsed as a relative Uri by .NET - IsAbsoluteUri is false - but a+ //browser resolves it against the current page's scheme, i.e. as an absolute url to an arbitrary host.+ //Reject it before the relative-url fast path below would otherwise wave it through as same-origin.+ if (url.StartsWith("//", StringComparison.Ordinal)) return false;++ if (!Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out var uri)) return false;++ //a genuinely relative url (no leading "//") cannot leave this origin - it is how the file manager+ //inserts self-hosted video+ if (!uri.IsAbsoluteUri) return true;++ if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps) return false;++ return allowedIframeHosts.Any(allowed => IsHostMatch(uri.Host, allowed));+ }++ private static bool IsHostMatch(string host, string allowed)+ {+ if (allowed.StartsWith("*.", StringComparison.Ordinal))+ return host.EndsWith(allowed[1..], StringComparison.OrdinalIgnoreCase);++ return string.Equals(host, allowed, StringComparison.OrdinalIgnoreCase);+ }+}diff --git a/src/Core/Grand.Infrastructure/Security/IHtmlSanitizationService.cs b/src/Core/Grand.Infrastructure/Security/IHtmlSanitizationService.csnew file mode 100644index 000000000..71be74555--- /dev/null+++ b/src/Core/Grand.Infrastructure/Security/IHtmlSanitizationService.cs@@ -0,0 +1,28 @@+namespace Grand.Infrastructure.Security;++/// <summary>+/// Detects markup that falls outside an allowlist. Content edited by a vendor, a store manager, or any+/// non-superadmin account is untrusted: it is rendered back into the administration panel, so markup that+/// survives here executes in an administrator's session.+/// This is detection, not rewriting: callers reject the value (see <see cref="Grand.Infrastructure.Validators.SanitizeHtmlAttribute" />+/// / <see cref="Grand.Infrastructure.Validators.NoHtmlAttribute" />) rather than silently cleaning it, so a+/// rejected save always shows the editor what needs to change.+/// </summary>+public interface IHtmlSanitizationService+{+ /// <summary>+ /// True when the rich-text allowlist would remove something from <paramref name="html" /> - a tag,+ /// attribute, style rule, class, comment, or url (script, iframe to an unlisted host, javascript:, etc.)+ /// that can execute or navigate on its own. False for markup an editor legitimately produces, even if the+ /// allowlist would reformat it (e.g. an implied <tbody> made explicit).+ /// </summary>+ /// <param name="html">Untrusted markup; may be null</param>+ bool ContainsDisallowedRichText(string html);++ /// <summary>+ /// True when <paramref name="text" /> contains any HTML markup at all. For fields that are never rich+ /// text: meta titles, meta keywords, meta descriptions, admin comments, attribute names.+ /// </summary>+ /// <param name="text">Untrusted text; may be null</param>+ bool ContainsMarkup(string text);+}diff --git a/src/Core/Grand.Infrastructure/StartupBase.cs b/src/Core/Grand.Infrastructure/StartupBase.csindex 8bee26d0b..0dd1a13a5 100644--- a/src/Core/Grand.Infrastructure/StartupBase.cs+++ b/src/Core/Grand.Infrastructure/StartupBase.cs@@ -7,6 +7,7 @@ using Grand.Infrastructure.Mapper;using Grand.Infrastructure.Modules;using Grand.Infrastructure.Plugins;using Grand.Infrastructure.Roslyn;+using Grand.Infrastructure.Security;using Grand.Infrastructure.TypeConverters;using Grand.Infrastructure.TypeSearch;using Grand.Infrastructure.Validators;@@ -175,6 +176,9 @@ public static class StartupBaseInitDatabase(services, configuration);+ //resolved by SanitizeHtmlAttribute/NoHtmlAttribute via ValidationContext.GetService - no filter needed,+ //ASP.NET Core's built-in model validation already invokes DataAnnotations attributes on every bind+ services.AddSingleton<IHtmlSanitizationService, HtmlSanitizationService>();services.AddTransient<ValidationFilter>();var mvcCoreBuilder = services.AddMvcCore(options =>{diff --git a/src/Core/Grand.Infrastructure/Validators/NoHtmlAttribute.cs b/src/Core/Grand.Infrastructure/Validators/NoHtmlAttribute.csnew file mode 100644index 000000000..d72503031--- /dev/null+++ b/src/Core/Grand.Infrastructure/Validators/NoHtmlAttribute.cs@@ -0,0 +1,35 @@+using System.ComponentModel.DataAnnotations;+using Grand.Infrastructure.Security;++namespace Grand.Infrastructure.Validators;++/// <summary>+/// Rejects a bound string property that contains any HTML markup at all - for a property that is never rich+/// text: a meta tag, a name, an internal comment. See <see cref="SanitizeHtmlAttribute" /> for why detection+/// goes through <see cref="IHtmlSanitizationService" /> resolved via <see cref="ValidationContext.GetService" />.+/// </summary>+[AttributeUsage(AttributeTargets.Property)]+public class NoHtmlAttribute() : ValidationAttribute("{0} must be plain text and cannot contain HTML markup.")+{+ protected override ValidationResult IsValid(object value, ValidationContext validationContext)+ {+ if (value is not string text || string.IsNullOrWhiteSpace(text)) return ValidationResult.Success;++ var sanitizationService = (IHtmlSanitizationService)validationContext+ .GetService(typeof(IHtmlSanitizationService));++ if (sanitizationService is null)+ throw new InvalidOperationException(+ $"{nameof(IHtmlSanitizationService)} could not be resolved - is it registered in DI?");++ return sanitizationService.ContainsMarkup(text)+ ? new ValidationResult(FormatErrorMessage(validationContext.DisplayName),+ MemberNames(validationContext))+ : ValidationResult.Success;+ }++ private static IEnumerable<string> MemberNames(ValidationContext validationContext)+ {+ return validationContext.MemberName is null ? [] : [validationContext.MemberName];+ }+}diff --git a/src/Core/Grand.Infrastructure/Validators/SanitizeHtmlAttribute.cs b/src/Core/Grand.Infrastructure/Validators/SanitizeHtmlAttribute.csnew file mode 100644index 000000000..42360c83c--- /dev/null+++ b/src/Core/Grand.Infrastructure/Validators/SanitizeHtmlAttribute.cs@@ -0,0 +1,41 @@+using System.ComponentModel.DataAnnotations;+using Grand.Infrastructure.Security;++namespace Grand.Infrastructure.Validators;++/// <summary>+/// Rejects a bound string property when it contains markup outside the rich-text allowlist - a tag,+/// attribute, style rule, or url (script, iframe to an unlisted host, javascript:, entity-encoded scheme,+/// etc.) that can execute or navigate on its own. Detection runs through <see cref="IHtmlSanitizationService" />,+/// a real HTML parser rather than a regular expression, so it is not defeated by whitespace, casing, or+/// encoding tricks the way a pattern match is.+/// <see cref="IHtmlSanitizationService" /> is resolved from <see cref="ValidationContext.GetService" /> rather+/// than constructor injection - ASP.NET Core's model validation constructs the ValidationContext with+/// HttpContext.RequestServices, so this is the supported way for a DataAnnotations attribute to reach a+/// scoped/singleton service.+/// </summary>+[AttributeUsage(AttributeTargets.Property)]+public class SanitizeHtmlAttribute() : ValidationAttribute("{0} contains HTML markup that is not allowed.")+{+ protected override ValidationResult IsValid(object value, ValidationContext validationContext)+ {+ if (value is not string html || string.IsNullOrWhiteSpace(html)) return ValidationResult.Success;++ var sanitizationService = (IHtmlSanitizationService)validationContext+ .GetService(typeof(IHtmlSanitizationService));++ if (sanitizationService is null)+ throw new InvalidOperationException(+ $"{nameof(IHtmlSanitizationService)} could not be resolved - is it registered in DI?");++ return sanitizationService.ContainsDisallowedRichText(html)+ ? new ValidationResult(FormatErrorMessage(validationContext.DisplayName),+ MemberNames(validationContext))+ : ValidationResult.Success;+ }++ private static IEnumerable<string> MemberNames(ValidationContext validationContext)+ {+ return validationContext.MemberName is null ? [] : [validationContext.MemberName];+ }+}diff --git a/src/Modules/Grand.Module.Api/DTOs/Catalog/BrandDto.cs b/src/Modules/Grand.Module.Api/DTOs/Catalog/BrandDto.csindex fd4b4b309..3a9d8057d 100644--- a/src/Modules/Grand.Module.Api/DTOs/Catalog/BrandDto.cs+++ b/src/Modules/Grand.Module.Api/DTOs/Catalog/BrandDto.cs@@ -1,4 +1,5 @@-using Grand.Module.Api.Models;+using Grand.Infrastructure.Validators;+using Grand.Module.Api.Models;namespace Grand.Module.Api.DTOs.Catalog;@@ -6,11 +7,16 @@ public class BrandDto : BaseApiEntityModel{public string Name { get; set; }public string SeName { get; set; }+ [SanitizeHtml]public string Description { get; set; }+ [SanitizeHtml]public string BottomDescription { get; set; }public string BrandLayoutId { get; set; }+ [NoHtml]public string MetaKeywords { get; set; }+ [NoHtml]public string MetaDescription { get; set; }+ [NoHtml]public string MetaTitle { get; set; }public string PictureId { get; set; }public int PageSize { get; set; }diff --git a/src/Modules/Grand.Module.Api/DTOs/Catalog/CategoryDTO.cs b/src/Modules/Grand.Module.Api/DTOs/Catalog/CategoryDTO.csindex 354675cd2..f66a0b157 100644--- a/src/Modules/Grand.Module.Api/DTOs/Catalog/CategoryDTO.cs+++ b/src/Modules/Grand.Module.Api/DTOs/Catalog/CategoryDTO.cs@@ -1,15 +1,21 @@-using Grand.Module.Api.Models;+using Grand.Infrastructure.Validators;+using Grand.Module.Api.Models;namespace Grand.Module.Api.DTOs.Catalog;public class CategoryDto : BaseApiEntityModel{public string Name { get; set; }+ [SanitizeHtml]public string Description { get; set; }+ [SanitizeHtml]public string BottomDescription { get; set; }public string CategoryLayoutId { get; set; }+ [NoHtml]public string MetaKeywords { get; set; }+ [NoHtml]public string MetaDescription { get; set; }+ [NoHtml]public string MetaTitle { get; set; }public string SeName { get; set; }public string ParentCategoryId { get; set; }diff --git a/src/Modules/Grand.Module.Api/DTOs/Catalog/CollectionDto.cs b/src/Modules/Grand.Module.Api/DTOs/Catalog/CollectionDto.csindex 6f80f0721..7a9ae94f7 100644--- a/src/Modules/Grand.Module.Api/DTOs/Catalog/CollectionDto.cs+++ b/src/Modules/Grand.Module.Api/DTOs/Catalog/CollectionDto.cs@@ -1,4 +1,5 @@-using Grand.Module.Api.Models;+using Grand.Infrastructure.Validators;+using Grand.Module.Api.Models;namespace Grand.Module.Api.DTOs.Catalog;@@ -6,11 +7,16 @@ public class CollectionDto : BaseApiEntityModel{public string Name { get; set; }public string SeName { get; set; }+ [SanitizeHtml]public string Description { get; set; }+ [SanitizeHtml]public string BottomDescription { get; set; }public string CollectionLayoutId { get; set; }+ [NoHtml]public string MetaKeywords { get; set; }+ [NoHtml]public string MetaDescription { get; set; }+ [NoHtml]public string MetaTitle { get; set; }public string PictureId { get; set; }public int PageSize { get; set; }diff --git a/src/Modules/Grand.Module.Api/DTOs/Catalog/ProductAttributeDto.cs b/src/Modules/Grand.Module.Api/DTOs/Catalog/ProductAttributeDto.csindex 413d67032..f9436ca70 100644--- a/src/Modules/Grand.Module.Api/DTOs/Catalog/ProductAttributeDto.cs+++ b/src/Modules/Grand.Module.Api/DTOs/Catalog/ProductAttributeDto.cs@@ -1,10 +1,12 @@-using Grand.Module.Api.Models;+using Grand.Infrastructure.Validators;+using Grand.Module.Api.Models;namespace Grand.Module.Api.DTOs.Catalog;public class ProductAttributeDto : BaseApiEntityModel{public string Name { get; set; }+ [SanitizeHtml]public string Description { get; set; }public IList<PredefinedProductAttributeValueDto> PredefinedProductAttributeValues { get; set; } =diff --git a/src/Modules/Grand.Module.Api/DTOs/Catalog/ProductDto.cs b/src/Modules/Grand.Module.Api/DTOs/Catalog/ProductDto.csindex 7ca07b308..595de72d8 100644--- a/src/Modules/Grand.Module.Api/DTOs/Catalog/ProductDto.cs+++ b/src/Modules/Grand.Module.Api/DTOs/Catalog/ProductDto.cs@@ -1,4 +1,5 @@-using Grand.Module.Api.Models;+using Grand.Infrastructure.Validators;+using Grand.Module.Api.Models;using Grand.Domain.Catalog;namespace Grand.Module.Api.DTOs.Catalog;@@ -10,15 +11,21 @@ public class ProductDto : BaseApiEntityModelpublic bool VisibleIndividually { get; set; }public string Name { get; set; }public string SeName { get; set; }+ [SanitizeHtml]public string ShortDescription { get; set; }+ [SanitizeHtml]public string FullDescription { get; set; }+ [NoHtml]public string AdminComment { get; set; }public string ProductLayoutId { get; set; }public string BrandId { get; set; }public string VendorId { get; set; }public bool ShowOnHomePage { get; set; }+ [NoHtml]public string MetaKeywords { get; set; }+ [NoHtml]public string MetaDescription { get; set; }+ [NoHtml]public string MetaTitle { get; set; }public bool AllowCustomerReviews { get; set; }public int ApprovedRatingSum { get; set; }@@ -44,6 +51,7 @@ public class ProductDto : BaseApiEntityModelpublic bool HasSampleDownload { get; set; }public string SampleDownloadId { get; set; }public bool HasUserAgreement { get; set; }+ [SanitizeHtml]public string UserAgreementText { get; set; }public bool IsRecurring { get; set; }public int RecurringCycleLength { get; set; }diff --git a/src/Modules/Grand.Module.Api/DTOs/Customers/CustomerDto.cs b/src/Modules/Grand.Module.Api/DTOs/Customers/CustomerDto.csindex ff312c5c1..6936e161f 100644--- a/src/Modules/Grand.Module.Api/DTOs/Customers/CustomerDto.cs+++ b/src/Modules/Grand.Module.Api/DTOs/Customers/CustomerDto.cs@@ -1,4 +1,5 @@-using Grand.Module.Api.Models;+using Grand.Infrastructure.Validators;+using Grand.Module.Api.Models;using System.ComponentModel.DataAnnotations;namespace Grand.Module.Api.DTOs.Customers;@@ -10,6 +11,7 @@ public class CustomerDto : BaseApiEntityModel[Key] public string Email { get; set; }+ [NoHtml]public string AdminComment { get; set; }public bool IsTaxExempt { get; set; }public bool FreeShipping { get; set; }diff --git a/src/Modules/Grand.Module.Api/DTOs/Customers/VendorDto.cs b/src/Modules/Grand.Module.Api/DTOs/Customers/VendorDto.csindex 448181bc4..c2be84194 100644--- a/src/Modules/Grand.Module.Api/DTOs/Customers/VendorDto.cs+++ b/src/Modules/Grand.Module.Api/DTOs/Customers/VendorDto.cs@@ -1,4 +1,5 @@-using Grand.Module.Api.Models;+using Grand.Infrastructure.Validators;+using Grand.Module.Api.Models;namespace Grand.Module.Api.DTOs.Customers;@@ -8,8 +9,10 @@ public class VendorDto : BaseApiEntityModelpublic string SeName { get; set; }public string PictureId { get; set; }public string Email { get; set; }+ [SanitizeHtml]public string Description { get; set; }public string StoreId { get; set; }+ [NoHtml]public string AdminComment { get; set; }public bool Active { get; set; }public bool Deleted { get; set; }diff --git a/src/Modules/Grand.Module.Api/DTOs/Shipping/PickupPointDto.cs b/src/Modules/Grand.Module.Api/DTOs/Shipping/PickupPointDto.csindex dbc272e23..c52e22b36 100644--- a/src/Modules/Grand.Module.Api/DTOs/Shipping/PickupPointDto.cs+++ b/src/Modules/Grand.Module.Api/DTOs/Shipping/PickupPointDto.cs@@ -1,11 +1,14 @@-using Grand.Module.Api.Models;+using Grand.Infrastructure.Validators;+using Grand.Module.Api.Models;namespace Grand.Module.Api.DTOs.Shipping;public class PickupPointDto : BaseApiEntityModel{public string Name { get; set; }+ [SanitizeHtml]public string Description { get; set; }+ [NoHtml]public string AdminComment { get; set; }public string WarehouseId { get; set; }public string StoreId { get; set; }diff --git a/src/Modules/Grand.Module.Api/DTOs/Shipping/ShippingMethodDto.cs b/src/Modules/Grand.Module.Api/DTOs/Shipping/ShippingMethodDto.csindex 6df456578..cb68ec09d 100644--- a/src/Modules/Grand.Module.Api/DTOs/Shipping/ShippingMethodDto.cs+++ b/src/Modules/Grand.Module.Api/DTOs/Shipping/ShippingMethodDto.cs@@ -1,10 +1,12 @@-using Grand.Module.Api.Models;+using Grand.Infrastructure.Validators;+using Grand.Module.Api.Models;namespace Grand.Module.Api.DTOs.Shipping;public class ShippingMethodDto : BaseApiEntityModel{public string Name { get; set; }+ [SanitizeHtml]public string Description { get; set; }public int DisplayOrder { get; set; }}\ No newline at end of filediff --git a/src/Modules/Grand.Module.Api/DTOs/Shipping/WarehouseDto.cs b/src/Modules/Grand.Module.Api/DTOs/Shipping/WarehouseDto.csindex d31e55e43..b52d49240 100644--- a/src/Modules/Grand.Module.Api/DTOs/Shipping/WarehouseDto.cs+++ b/src/Modules/Grand.Module.Api/DTOs/Shipping/WarehouseDto.cs@@ -1,9 +1,11 @@-using Grand.Module.Api.Models;+using Grand.Infrastructure.Validators;+using Grand.Module.Api.Models;namespace Grand.Module.Api.DTOs.Shipping;public class WarehouseDto : BaseApiEntityModel{public string Name { get; set; }+ [NoHtml]public string AdminComment { get; set; }}\ No newline at end of filediff --git a/src/Tests/Grand.Infrastructure.Tests/Security/HtmlSanitizationServiceTests.cs b/src/Tests/Grand.Infrastructure.Tests/Security/HtmlSanitizationServiceTests.csnew file mode 100644index 000000000..f62eb043c--- /dev/null+++ b/src/Tests/Grand.Infrastructure.Tests/Security/HtmlSanitizationServiceTests.cs@@ -0,0 +1,220 @@+using Grand.Infrastructure.Configuration;+using Grand.Infrastructure.Security;+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Infrastructure.Tests.Security;++[TestClass]+public class HtmlSanitizationServiceTests+{+ private HtmlSanitizationService _service;++ [TestInitialize]+ public void Init()+ {+ _service = new HtmlSanitizationService(new SecurityConfig());+ }++ /// <summary>+ /// Every payload here defeated the regex blacklist that this service replaces.+ /// </summary>+ [TestMethod]+ [DataRow("<script>alert(1)</script>", DisplayName = "script element")]+ [DataRow("<script\nsrc=\"//evil.tld/x.js\"></script>", DisplayName = "script src across a newline")]+ [DataRow("<script>\nalert(1)\n</script>", DisplayName = "script body across newlines")]+ [DataRow("<img src=x onerror=alert(1)>", DisplayName = "onerror")]+ [DataRow("<img src=x onerror\n=alert(1)>", DisplayName = "onerror with newline before =")]+ [DataRow("<img src=x OnErRoR = alert(1)>", DisplayName = "onerror mixed case and spaced")]+ [DataRow("<svg onload=alert(1)>", DisplayName = "svg onload")]+ [DataRow("<input onfocus=alert(1) autofocus>", DisplayName = "onfocus autofocus")]+ [DataRow("<div onpointerover=alert(1)>x</div>", DisplayName = "onpointerover")]+ [DataRow("<div onanimationstart=alert(1)>x</div>", DisplayName = "onanimationstart")]+ [DataRow("<details ontoggle=alert(1) open>x</details>", DisplayName = "ontoggle")]+ [DataRow("<body onload=alert(1)>", DisplayName = "body onload")]+ [DataRow("<a href=\"javascript:alert(1)\">x</a>", DisplayName = "javascript scheme")]+ [DataRow("<a href=\"javascript:alert(1)\">x</a>", DisplayName = "entity-encoded javascript scheme")]+ [DataRow("<a href=\"JaVaScRiPt:alert(1)\">x</a>", DisplayName = "javascript scheme mixed case")]+ [DataRow("<iframe srcdoc=\"<script>alert(1)</script>\"></iframe>", DisplayName = "iframe srcdoc")]+ [DataRow("<object data=\"evil.swf\"></object>", DisplayName = "object")]+ [DataRow("<embed src=\"evil.swf\">", DisplayName = "embed")]+ [DataRow("<form action=\"//evil.tld\"><input name=\"pw\"></form>", DisplayName = "phishing form")]+ [DataRow("<button formaction=\"javascript:alert(1)\">x</button>", DisplayName = "formaction")]+ [DataRow("<a href=\"data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==\">x</a>",+ DisplayName = "data:text/html")]+ [DataRow("<div style=\"background:url(javascript:alert(1))\">x</div>", DisplayName = "css url javascript")]+ [DataRow("<base href=\"//evil.tld/\">", DisplayName = "base tag")]+ [DataRow("<div v-html=\"x\" @click=\"y\" :id=\"z\">x</div>", DisplayName = "vue directives")]+ [DataRow("<iframe src=\"https://evil.tld/frame\"></iframe>", DisplayName = "iframe from unlisted host")]+ [DataRow("<iframe src=\"//evil.tld/frame\"></iframe>", DisplayName = "iframe protocol-relative unlisted host")]+ public void ContainsDisallowedRichText_FlagsExecutableMarkup(string payload)+ {+ Assert.IsTrue(_service.ContainsDisallowedRichText(payload), $"payload was not flagged: {payload}");+ }++ /// <summary>+ /// Ordinary editor output must not be rejected, even the parts the allowlist reformats (e.g. an implied+ /// <tbody> made explicit, or a css declaration re-spaced) - those are not removals.+ /// </summary>+ [TestMethod]+ [DataRow("<p>Hello <strong>world</strong></p>")]+ [DataRow("<ul><li>one</li><li>two</li></ul>")]+ [DataRow("<a href=\"https://grandnode.com\" target=\"_blank\">link</a>")]+ [DataRow("<a href=\"mailto:[email protected]\">mail</a>")]+ [DataRow("<img src=\"/content/images/p.jpg\" alt=\"product\" width=\"200\">")]+ [DataRow("<h2>Heading</h2><blockquote>quote</blockquote>")]+ [DataRow("<table class=\"table\"><tr><td>cell</td></tr></table>")]+ [DataRow("<p style=\"text-align:center\">centered</p>")]+ public void ContainsDisallowedRichText_AllowsLegitimateEditorOutput(string html)+ {+ Assert.IsFalse(_service.ContainsDisallowedRichText(html), $"legitimate markup was flagged: {html}");+ }++ [TestMethod]+ public void ContainsDisallowedRichText_AllowsIframeFromAllowedHost()+ {+ Assert.IsFalse(_service.ContainsDisallowedRichText(+ "<iframe src=\"https://www.youtube.com/embed/abc123\"></iframe>"));+ }++ [TestMethod]+ public void ContainsDisallowedRichText_AllowsRelativeIframe()+ {+ //the file manager inserts self-hosted video as a relative url; it cannot leave this origin+ Assert.IsFalse(_service.ContainsDisallowedRichText("<iframe src=\"/assets/media/promo.mp4\"></iframe>"));+ }++ [TestMethod]+ public void ContainsDisallowedRichText_FlagsEveryIframeWhenHostListIsConfiguredEmpty()+ {+ var service = new HtmlSanitizationService(new SecurityConfig { SanitizerAllowedIframeHosts = [] });++ Assert.IsTrue(service.ContainsDisallowedRichText(+ "<iframe src=\"https://www.youtube.com/embed/a\"></iframe>"));+ }++ [TestMethod]+ public void ContainsDisallowedRichText_HonoursConfiguredHosts()+ {+ var service = new HtmlSanitizationService(new SecurityConfig {+ SanitizerAllowedIframeHosts = ["*.trusted.tld"]+ });++ Assert.IsFalse(service.ContainsDisallowedRichText("<iframe src=\"https://cdn.trusted.tld/x\"></iframe>"));+ Assert.IsTrue(service.ContainsDisallowedRichText("<iframe src=\"https://www.youtube.com/embed/a\"></iframe>"));+ }++ [TestMethod]+ public void ContainsDisallowedRichText_AllowsInlineImageButNotInlineDocument()+ {+ Assert.IsFalse(_service.ContainsDisallowedRichText("<img src=\"data:image/png;base64,iVBORw0KGgo=\">"));+ Assert.IsTrue(_service.ContainsDisallowedRichText(+ "<a href=\"data:text/html,<script>alert(1)</script>\">x</a>"));+ }++ [TestMethod]+ [DataRow(null)]+ [DataRow("")]+ [DataRow(" ")]+ public void ContainsDisallowedRichText_TreatsEmptyInputAsClean(string value)+ {+ Assert.IsFalse(_service.ContainsDisallowedRichText(value));+ }++ [TestMethod]+ public void ContainsMarkup_FlagsAnyTag()+ {+ Assert.IsTrue(_service.ContainsMarkup("<b>Bold</b> title"));+ Assert.IsTrue(_service.ContainsMarkup("<script>alert(1)</script>"));+ Assert.IsTrue(_service.ContainsMarkup("plain<br>text"));+ }++ [TestMethod]+ public void ContainsMarkup_AllowsPlainText()+ {+ Assert.IsFalse(_service.ContainsMarkup("Just a title"));+ Assert.IsFalse(_service.ContainsMarkup("Tea & Coffee"));+ Assert.IsFalse(_service.ContainsMarkup("Price < 10 and > 2"));+ }++ [TestMethod]+ [DataRow(null)]+ [DataRow("")]+ public void ContainsMarkup_TreatsEmptyInputAsClean(string value)+ {+ Assert.IsFalse(_service.ContainsMarkup(value));+ }++ /// <summary>+ /// The per-call detection flag must not leak between unrelated calls on the same thread.+ /// </summary>+ [TestMethod]+ public void ContainsDisallowedRichText_DoesNotLeakStateBetweenCalls()+ {+ Assert.IsTrue(_service.ContainsDisallowedRichText("<script>alert(1)</script>"));+ Assert.IsFalse(_service.ContainsDisallowedRichText("<p>clean</p>"));+ Assert.IsTrue(_service.ContainsDisallowedRichText("<script>alert(1)</script>"));+ }++ /// <summary>+ /// The singleton holds no mutable shared state - each call builds its own HtmlSanitizer around read-only+ /// allowlists, with a result flag captured in a local closure - so concurrent calls on different threads+ /// must never see each other's result, without needing a lock. Runs enough iterations across enough+ /// threads that the old [ThreadStatic]-without-serialization design (and a naive shared mutable-field+ /// design) would reliably produce a wrong verdict here.+ /// </summary>+ [TestMethod]+ public void ContainsDisallowedRichText_IsCorrectUnderConcurrentCalls()+ {+ const string dangerous = "<script>alert(1)</script>";+ const string clean = "<p>clean</p>";++ var wrongVerdicts = 0;+ Parallel.For(0, 2000, i =>+ {+ var service = _service; // shared singleton instance, as it is registered in DI+ if (i % 2 == 0)+ {+ if (!service.ContainsDisallowedRichText(dangerous)) Interlocked.Increment(ref wrongVerdicts);+ }+ else+ {+ if (service.ContainsDisallowedRichText(clean)) Interlocked.Increment(ref wrongVerdicts);+ }+ });++ Assert.AreEqual(0, wrongVerdicts, "a concurrent call observed another call's detection result");+ }++ /// <summary>+ /// SecurityConfig.EnableHtmlSanitization is an operational kill switch: false must make both detection+ /// methods report "nothing disallowed" even for payloads that are otherwise always flagged.+ /// </summary>+ [TestMethod]+ [DataRow("<script>alert(1)</script>")]+ [DataRow("<iframe src=\"https://evil.tld/frame\"></iframe>")]+ public void ContainsDisallowedRichText_AcceptsEverything_WhenSanitizationDisabled(string payload)+ {+ var service = new HtmlSanitizationService(new SecurityConfig { EnableHtmlSanitization = false });++ Assert.IsFalse(service.ContainsDisallowedRichText(payload));+ }++ [TestMethod]+ [DataRow("<script>alert(1)</script>")]+ [DataRow("<b>bold</b>")]+ public void ContainsMarkup_AcceptsEverything_WhenSanitizationDisabled(string payload)+ {+ var service = new HtmlSanitizationService(new SecurityConfig { EnableHtmlSanitization = false });++ Assert.IsFalse(service.ContainsMarkup(payload));+ }++ [TestMethod]+ public void EnableHtmlSanitization_DefaultsToTrue_WhenNotSetExplicitly()+ {+ // mirrors what configuration binding leaves behind when the appsettings.json key is absent+ var service = new HtmlSanitizationService(new SecurityConfig());++ Assert.IsTrue(service.ContainsDisallowedRichText("<script>alert(1)</script>"));+ }+}diff --git a/src/Tests/Grand.Infrastructure.Tests/Validators/SanitizeHtmlAttributeTests.cs b/src/Tests/Grand.Infrastructure.Tests/Validators/SanitizeHtmlAttributeTests.csnew file mode 100644index 000000000..bf84ce980--- /dev/null+++ b/src/Tests/Grand.Infrastructure.Tests/Validators/SanitizeHtmlAttributeTests.cs@@ -0,0 +1,100 @@+using System.ComponentModel.DataAnnotations;+using Grand.Infrastructure.Configuration;+using Grand.Infrastructure.Security;+using Grand.Infrastructure.Validators;+using Microsoft.Extensions.DependencyInjection;+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Infrastructure.Tests.Validators;++/// <summary>+/// Exercises SanitizeHtmlAttribute/NoHtmlAttribute the way ASP.NET Core's model validation exercises any+/// ValidationAttribute: through ValidationContext.GetService, backed by a real service provider - not through+/// a live MVC pipeline (that path was covered manually against a running app earlier in this change).+/// </summary>+[TestClass]+public class SanitizeHtmlAttributeTests+{+ private IServiceProvider _serviceProvider;++ [TestInitialize]+ public void Init()+ {+ var services = new ServiceCollection();+ services.AddSingleton<IHtmlSanitizationService>(new HtmlSanitizationService(new SecurityConfig()));+ _serviceProvider = services.BuildServiceProvider();+ }++ [TestMethod]+ public void SanitizeHtml_AcceptsCleanMarkup()+ {+ var model = new SanitizeHtmlSourceTest { FullDescription = "<p>Hello <strong>world</strong></p>" };++ var results = Validate(model);++ Assert.AreEqual(0, results.Count);+ }++ [TestMethod]+ public void SanitizeHtml_RejectsExecutableMarkup()+ {+ var model = new SanitizeHtmlSourceTest { FullDescription = "<img src=x onerror=alert(1)>" };++ var results = Validate(model);++ Assert.AreEqual(1, results.Count);+ StringAssert.Contains(results[0].MemberNames.FirstOrDefault() ?? "", "FullDescription");+ }++ [TestMethod]+ public void SanitizeHtml_AcceptsNullOrEmpty()+ {+ Assert.AreEqual(0, Validate(new SanitizeHtmlSourceTest { FullDescription = null }).Count);+ Assert.AreEqual(0, Validate(new SanitizeHtmlSourceTest { FullDescription = "" }).Count);+ }++ [TestMethod]+ public void NoHtml_AcceptsPlainText()+ {+ var model = new SanitizeHtmlSourceTest { MetaTitle = "Shoes & Boots" };++ Assert.AreEqual(0, Validate(model).Count);+ }++ [TestMethod]+ public void NoHtml_RejectsAnyMarkup()+ {+ var model = new SanitizeHtmlSourceTest { MetaTitle = "<b>Shoes</b>" };++ var results = Validate(model);++ Assert.AreEqual(1, results.Count);+ StringAssert.Contains(results[0].MemberNames.FirstOrDefault() ?? "", "MetaTitle");+ }++ [TestMethod]+ public void ThrowsWhenSanitizationServiceIsNotRegistered()+ {+ var emptyProvider = new ServiceCollection().BuildServiceProvider();+ var model = new SanitizeHtmlSourceTest { FullDescription = "<p>x</p>" };+ var context = new ValidationContext(model, emptyProvider, null) { MemberName = nameof(model.FullDescription) };++ Assert.ThrowsExactly<InvalidOperationException>(() =>+ new SanitizeHtmlAttribute().GetValidationResult(model.FullDescription, context));+ }++ private List<ValidationResult> Validate(SanitizeHtmlSourceTest model)+ {+ var results = new List<ValidationResult>();+ Validator.TryValidateObject(model,+ new ValidationContext(model, _serviceProvider, null), results, validateAllProperties: true);+ return results;+ }+}++public class SanitizeHtmlSourceTest+{+ [SanitizeHtml] public string FullDescription { get; set; }++ [NoHtml] public string MetaTitle { get; set; }+}diff --git a/src/Web/Grand.Web.Admin/App_Data/appsettings.json b/src/Web/Grand.Web.Admin/App_Data/appsettings.jsonindex ffb1a975d..abc2b81cc 100644--- a/src/Web/Grand.Web.Admin/App_Data/appsettings.json+++ b/src/Web/Grand.Web.Admin/App_Data/appsettings.json@@ -78,7 +78,15 @@"CookieSameSite": "Lax","CookieSameSiteExternalAuth": "None",//Enabling this setting allows for verification of access to a specific controller and action in the admin panel using menu configuration.- "AuthorizeAdminMenu": false+ "AuthorizeAdminMenu": false,+ //Hosts whose iframes survive sanitization of rich-text content (product descriptions, blog posts, pages).+ //An iframe pointing anywhere else is removed, because its src is otherwise attacker-controlled. A leading "*." matches any subdomain.+ //Remove the key entirely to use the built-in video-embed defaults (youtube, youtube-nocookie, vimeo, google); set it to [] to block every iframe.+ "SanitizerAllowedIframeHosts": [ "youtube.com", "*.youtube.com", "youtube-nocookie.com", "*.youtube-nocookie.com", "vimeo.com", "*.vimeo.com", "google.com", "*.google.com" ],+ //Operational escape hatch, not a security setting: when [SanitizeHtml]/[NoHtml] wrongly reject legitimate+ //content in production, set this to false to accept input unsanitized while a fix is prepared, then set it+ //back to true as soon as possible. Default true.+ "EnableHtmlSanitization": true},"Cache": {//Gets or sets a value indicating for default cache time in minutes"diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Discount/Partials/CreateOrUpdate.TabRequirements.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Discount/Partials/CreateOrUpdate.TabRequirements.cshtmlindex 790794e0d..975ddf4dd 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Discount/Partials/CreateOrUpdate.TabRequirements.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Discount/Partials/CreateOrUpdate.TabRequirements.cshtml@@ -1,4 +1,5 @@-@model DiscountModel+@using System.Text.Encodings.Web+@model DiscountModel@{<vc:admin-widget widget-zone="discount_details_requirements_top" additional-data="Model"/>@@ -100,7 +101,7 @@@for (var i = 0; i < Model.DiscountRequirementMetaInfos.Count; i++){var drmi = Model.DiscountRequirementMetaInfos[i];- <text>{ discountRequirementId: "@(drmi.DiscountRequirementId)", ruleName: "@(drmi.RuleName)", url: "@(Html.Raw(drmi.ConfigurationUrl))" } </text>+ <text>{ discountRequirementId: "@(drmi.DiscountRequirementId)", ruleName: "@(drmi.RuleName)", url: "@(Html.Raw(JavaScriptEncoder.Default.Encode(drmi.ConfigurationUrl)))" } </text>if (i != Model.DiscountRequirementMetaInfos.Count - 1){<text>, </text>diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Language/Partials/CreateOrUpdate.TabResources.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Language/Partials/CreateOrUpdate.TabResources.cshtmlindex 1efa53a47..31525fac8 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Language/Partials/CreateOrUpdate.TabResources.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Language/Partials/CreateOrUpdate.TabResources.cshtml@@ -1,4 +1,5 @@-@using Grand.Domain.Localization+@using System.Text.Encodings.Web+@using Grand.Domain.Localization@model LanguageModel@inject AdminAreaSettings adminAreaSettings<vc:admin-widget widget-zone="language_details_resources_top" additional-data="Model"/>@@ -50,7 +51,7 @@<text>{Id: '@(method.Value)',- Name: "@Html.Raw(method.Text)"+ Name: "@Html.Raw(JavaScriptEncoder.Default.Encode(method.Text))"},</text>}diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/BulkEdit.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/BulkEdit.cshtmlindex a60287c10..12a09140c 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/BulkEdit.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/BulkEdit.cshtml@@ -1,4 +1,5 @@-@model BulkEditListModel+@using System.Text.Encodings.Web+@model BulkEditListModel@inject AdminAreaSettings adminAreaSettings@{//page title@@ -95,7 +96,7 @@<text>{Id: '@(method.Value)',- Name: "@Html.Raw(method.Text)"+ Name: "@Html.Raw(JavaScriptEncoder.Default.Encode(method.Text))"},</text>}diff --git a/src/Web/Grand.Web.AdminShared/Models/Blogs/BlogPostModel.cs b/src/Web/Grand.Web.AdminShared/Models/Blogs/BlogPostModel.csindex f416d7700..27a27a805 100644--- a/src/Web/Grand.Web.AdminShared/Models/Blogs/BlogPostModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Blogs/BlogPostModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.Common.Link;using Grand.Web.Common.Models;using System.ComponentModel.DataAnnotations;@@ -16,11 +17,11 @@ public class BlogPostModel : BaseEntityModel, ILocalizedModel<BlogLocalizedModelpublic string PictureId { get; set; }[GrandResourceDisplayName("Admin.Content.Blog.BlogPosts.Fields.Body")]-+ [SanitizeHtml]public string Body { get; set; }[GrandResourceDisplayName("Admin.Content.Blog.BlogPosts.Fields.BodyOverview")]-+ [SanitizeHtml]public string BodyOverview { get; set; }[GrandResourceDisplayName("Admin.Content.Blog.BlogPosts.Fields.AllowComments")]@@ -46,15 +47,15 @@ public class BlogPostModel : BaseEntityModel, ILocalizedModel<BlogLocalizedModelpublic DateTime? EndDate { get; set; }[GrandResourceDisplayName("Admin.Content.Blog.BlogPosts.Fields.MetaKeywords")]-+ [NoHtml]public string MetaKeywords { get; set; }[GrandResourceDisplayName("Admin.Content.Blog.BlogPosts.Fields.MetaDescription")]-+ [NoHtml]public string MetaDescription { get; set; }[GrandResourceDisplayName("Admin.Content.Blog.BlogPosts.Fields.MetaTitle")]-+ [NoHtml]public string MetaTitle { get; set; }[GrandResourceDisplayName("Admin.Content.Blog.BlogPosts.Fields.SeName")]@@ -78,23 +79,23 @@ public class BlogLocalizedModel : ILocalizedModelLocal, ISlugModelLocalpublic string Title { get; set; }[GrandResourceDisplayName("Admin.Content.Blog.BlogPosts.Fields.BodyOverview")]-+ [SanitizeHtml]public string BodyOverview { get; set; }[GrandResourceDisplayName("Admin.Content.Blog.BlogPosts.Fields.Body")]-+ [SanitizeHtml]public string Body { get; set; }[GrandResourceDisplayName("Admin.Content.Blog.BlogPosts.Fields.MetaKeywords")]-+ [NoHtml]public string MetaKeywords { get; set; }[GrandResourceDisplayName("Admin.Content.Blog.BlogPosts.Fields.MetaDescription")]-+ [NoHtml]public string MetaDescription { get; set; }[GrandResourceDisplayName("Admin.Content.Blog.BlogPosts.Fields.MetaTitle")]-+ [NoHtml]public string MetaTitle { get; set; }public string LanguageId { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Catalog/BrandModel.cs b/src/Web/Grand.Web.AdminShared/Models/Catalog/BrandModel.csindex 87bca6298..74a0b9260 100644--- a/src/Web/Grand.Web.AdminShared/Models/Catalog/BrandModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Catalog/BrandModel.cs@@ -3,7 +3,7 @@ using Grand.Infrastructure.Models;using Grand.Web.AdminShared.Models.Discounts;using Grand.Web.Common.Link;using Grand.Web.Common.Models;-using Grand.Web.Common.Validators;+using Grand.Infrastructure.Validators;using Microsoft.AspNetCore.Mvc.Rendering;using System.ComponentModel.DataAnnotations;@@ -19,11 +19,11 @@ public class BrandModel : BaseEntityModel, ILocalizedModel<BrandLocalizedModel>,[GrandResourceDisplayName("Admin.Catalog.Brands.Fields.Name")]public string Name { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Brands.Fields.Description")]public string Description { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Brands.Fields.BottomDescription")]public string BottomDescription { get; set; }@@ -32,15 +32,15 @@ public class BrandModel : BaseEntityModel, ILocalizedModel<BrandLocalizedModel>,public IList<SelectListItem> AvailableBrandLayouts { get; set; } = [];- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Brands.Fields.MetaKeywords")]public string MetaKeywords { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Brands.Fields.MetaDescription")]public string MetaDescription { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Brands.Fields.MetaTitle")]public string MetaTitle { get; set; }@@ -105,23 +105,23 @@ public class BrandLocalizedModel : ILocalizedModelLocal, ISlugModelLocal[GrandResourceDisplayName("Admin.Catalog.Brands.Fields.Name")]public string Name { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Brands.Fields.Description")]public string Description { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Brands.Fields.BottomDescription")]public string BottomDescription { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Brands.Fields.MetaKeywords")]public string MetaKeywords { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Brands.Fields.MetaDescription")]public string MetaDescription { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Brands.Fields.MetaTitle")]public string MetaTitle { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Catalog/CategoryModel.cs b/src/Web/Grand.Web.AdminShared/Models/Catalog/CategoryModel.csindex 51faf9e70..698a5ec5c 100644--- a/src/Web/Grand.Web.AdminShared/Models/Catalog/CategoryModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Catalog/CategoryModel.cs@@ -3,7 +3,7 @@ using Grand.Infrastructure.Models;using Grand.Web.AdminShared.Models.Discounts;using Grand.Web.Common.Link;using Grand.Web.Common.Models;-using Grand.Web.Common.Validators;+using Grand.Infrastructure.Validators;using Microsoft.AspNetCore.Mvc.Rendering;using System.ComponentModel.DataAnnotations;@@ -22,11 +22,11 @@ public class CategoryModel : BaseEntityModel, ILocalizedModel<CategoryLocalizedM[GrandResourceDisplayName("Admin.Catalog.Categories.Fields.Name")]public string Name { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Categories.Fields.Description")]public string Description { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Categories.Fields.BottomDescription")]public string BottomDescription { get; set; }@@ -35,15 +35,15 @@ public class CategoryModel : BaseEntityModel, ILocalizedModel<CategoryLocalizedMpublic IList<SelectListItem> AvailableCategoryLayouts { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Categories.Fields.MetaKeywords")]public string MetaKeywords { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Categories.Fields.MetaDescription")]public string MetaDescription { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Categories.Fields.MetaTitle")]public string MetaTitle { get; set; }@@ -191,23 +191,23 @@ public class CategoryLocalizedModel : ILocalizedModelLocal, ISlugModelLocal[GrandResourceDisplayName("Admin.Catalog.Categories.Fields.Name")]public string Name { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Categories.Fields.Description")]public string Description { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Categories.Fields.BottomDescription")]public string BottomDescription { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Categories.Fields.MetaKeywords")]public string MetaKeywords { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Categories.Fields.MetaDescription")]public string MetaDescription { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Categories.Fields.MetaTitle")]public string MetaTitle { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Catalog/CollectionModel.cs b/src/Web/Grand.Web.AdminShared/Models/Catalog/CollectionModel.csindex bfee5ed70..5e6d9303f 100644--- a/src/Web/Grand.Web.AdminShared/Models/Catalog/CollectionModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Catalog/CollectionModel.cs@@ -3,7 +3,7 @@ using Grand.Infrastructure.Models;using Grand.Web.AdminShared.Models.Discounts;using Grand.Web.Common.Link;using Grand.Web.Common.Models;-using Grand.Web.Common.Validators;+using Grand.Infrastructure.Validators;using Microsoft.AspNetCore.Mvc.Rendering;using System.ComponentModel.DataAnnotations;@@ -23,11 +23,11 @@ public class CollectionModel : BaseEntityModel, ILocalizedModel<CollectionLocali[GrandResourceDisplayName("Admin.Catalog.Collections.Fields.Name")]public string Name { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Collections.Fields.Description")]public string Description { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Collections.Fields.BottomDescription")]public string BottomDescription { get; set; }@@ -36,15 +36,15 @@ public class CollectionModel : BaseEntityModel, ILocalizedModel<CollectionLocalipublic IList<SelectListItem> AvailableCollectionLayouts { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Collections.Fields.MetaKeywords")]public string MetaKeywords { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Collections.Fields.MetaDescription")]public string MetaDescription { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Collections.Fields.MetaTitle")]public string MetaTitle { get; set; }@@ -169,23 +169,23 @@ public class CollectionLocalizedModel : ILocalizedModelLocal, ISlugModelLocal[GrandResourceDisplayName("Admin.Catalog.Collections.Fields.Name")]public string Name { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Collections.Fields.Description")]public string Description { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Collections.Fields.BottomDescription")]public string BottomDescription { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Collections.Fields.MetaKeywords")]public string MetaKeywords { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Collections.Fields.MetaDescription")]public string MetaDescription { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Collections.Fields.MetaTitle")]public string MetaTitle { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Catalog/ProductAttributeModel.cs b/src/Web/Grand.Web.AdminShared/Models/Catalog/ProductAttributeModel.csindex b27fb0d90..a3d7f7803 100644--- a/src/Web/Grand.Web.AdminShared/Models/Catalog/ProductAttributeModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Catalog/ProductAttributeModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.Common.Link;using Grand.Web.Common.Models;using System.ComponentModel.DataAnnotations;@@ -14,6 +15,7 @@ public class ProductAttributeModel : BaseEntityModel, ILocalizedModel<ProductAtt[GrandResourceDisplayName("Admin.Catalog.Attributes.ProductAttributes.Fields.SeName")]public string SeName { get; set; }+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Attributes.ProductAttributes.Fields.Description")]public string Description { get; set; }@@ -45,7 +47,7 @@ public class ProductAttributeLocalizedModel : ILocalizedModelLocalpublic string Name { get; set; }[GrandResourceDisplayName("Admin.Catalog.Attributes.ProductAttributes.Fields.Description")]-+ [SanitizeHtml]public string Description { get; set; }public string LanguageId { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Catalog/ProductModel.cs b/src/Web/Grand.Web.AdminShared/Models/Catalog/ProductModel.csindex 4efd46107..40ac9ed68 100644--- a/src/Web/Grand.Web.AdminShared/Models/Catalog/ProductModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Catalog/ProductModel.cs@@ -4,7 +4,7 @@ using Grand.Infrastructure.Models;using Grand.Web.AdminShared.Models.Discounts;using Grand.Web.Common.Link;using Grand.Web.Common.Models;-using Grand.Web.Common.Validators;+using Grand.Infrastructure.Validators;using Microsoft.AspNetCore.Mvc.Rendering;using System.ComponentModel.DataAnnotations;@@ -44,18 +44,18 @@ public class ProductModel : BaseEntityModel, ILocalizedModel<ProductLocalizedMod[GrandResourceDisplayName("Admin.Catalog.Products.Fields.Name")]public string Name { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Products.Fields.ShortDescription")]public string ShortDescription { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Products.Fields.FullDescription")]public string FullDescription { get; set; }[GrandResourceDisplayName("Admin.Catalog.Products.Fields.Flag")]public string Flag { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Products.Fields.AdminComment")]public string AdminComment { get; set; }@@ -73,15 +73,15 @@ public class ProductModel : BaseEntityModel, ILocalizedModel<ProductLocalizedMod[GrandResourceDisplayName("Admin.Catalog.Products.Fields.BestSeller")]public bool BestSeller { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Products.Fields.MetaKeywords")]public string MetaKeywords { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Products.Fields.MetaDescription")]public string MetaDescription { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Products.Fields.MetaTitle")]public string MetaTitle { get; set; }@@ -152,7 +152,7 @@ public class ProductModel : BaseEntityModel, ILocalizedModel<ProductLocalizedMod[GrandResourceDisplayName("Admin.Catalog.Products.Fields.HasUserAgreement")]public bool HasUserAgreement { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Products.Fields.UserAgreementText")]public string UserAgreementText { get; set; }@@ -1058,23 +1058,23 @@ public class ProductLocalizedModel : ILocalizedModelLocal, ISlugModelLocal[GrandResourceDisplayName("Admin.Catalog.Products.Fields.Name")]public string Name { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Products.Fields.ShortDescription")]public string ShortDescription { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Admin.Catalog.Products.Fields.FullDescription")]public string FullDescription { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Products.Fields.MetaKeywords")]public string MetaKeywords { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Products.Fields.MetaDescription")]public string MetaDescription { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Admin.Catalog.Products.Fields.MetaTitle")]public string MetaTitle { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Courses/CourseLessonModel.cs b/src/Web/Grand.Web.AdminShared/Models/Courses/CourseLessonModel.csindex 83db54b40..58e00d249 100644--- a/src/Web/Grand.Web.AdminShared/Models/Courses/CourseLessonModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Courses/CourseLessonModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Microsoft.AspNetCore.Mvc.Rendering;using System.ComponentModel.DataAnnotations;@@ -13,6 +14,7 @@ public class CourseLessonModel : BaseEntityModel[GrandResourceDisplayName("Admin.Courses.Course.Lesson.Fields.ShortDescription")]public string ShortDescription { get; set; }+ [SanitizeHtml][GrandResourceDisplayName("Admin.Courses.Course.Lesson.Fields.Description")]public string Description { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Courses/CourseModel.cs b/src/Web/Grand.Web.AdminShared/Models/Courses/CourseModel.csindex cae21ea1d..40d88e55d 100644--- a/src/Web/Grand.Web.AdminShared/Models/Courses/CourseModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Courses/CourseModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.Common.Link;using Grand.Web.Common.Models;using Microsoft.AspNetCore.Mvc.Rendering;@@ -15,6 +16,7 @@ public class CourseModel : BaseEntityModel, ILocalizedModel<CourseLocalizedModel[GrandResourceDisplayName("Admin.Courses.Course.Fields.ShortDescription")]public string ShortDescription { get; set; }+ [SanitizeHtml][GrandResourceDisplayName("Admin.Courses.Course.Fields.Description")]public string Description { get; set; }@@ -33,15 +35,16 @@ public class CourseModel : BaseEntityModel, ILocalizedModel<CourseLocalizedModelpublic IList<SelectListItem> AvailableLevels { get; set; } = new List<SelectListItem>();+ [NoHtml][GrandResourceDisplayName("Admin.Courses.Course.Fields.MetaKeywords")]public string MetaKeywords { get; set; }[GrandResourceDisplayName("Admin.Courses.Course.Fields.MetaDescription")]-+ [NoHtml]public string MetaDescription { get; set; }[GrandResourceDisplayName("Admin.Courses.Course.Fields.MetaTitle")]-+ [NoHtml]public string MetaTitle { get; set; }[GrandResourceDisplayName("Admin.Courses.Course.Fields.SeName")]@@ -114,19 +117,19 @@ public class CourseLocalizedModel : ILocalizedModelLocal, ISlugModelLocalpublic string ShortDescription { get; set; }[GrandResourceDisplayName("Admin.Courses.Course.Fields.Description")]-+ [SanitizeHtml]public string Description { get; set; }[GrandResourceDisplayName("Admin.Courses.Course.MetaKeywords")]-+ [NoHtml]public string MetaKeywords { get; set; }[GrandResourceDisplayName("Admin.Courses.Course.Fields.MetaDescription")]-+ [NoHtml]public string MetaDescription { get; set; }[GrandResourceDisplayName("Admin.Courses.Course.Fields.MetaTitle")]-+ [NoHtml]public string MetaTitle { get; set; }public string LanguageId { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Customers/CustomerModel.cs b/src/Web/Grand.Web.AdminShared/Models/Customers/CustomerModel.csindex d866dce47..1c794ca16 100644--- a/src/Web/Grand.Web.AdminShared/Models/Customers/CustomerModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Customers/CustomerModel.cs@@ -2,6 +2,7 @@using Grand.Domain.Common;using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.Common.Binders;using Grand.Web.Common.Models;using Microsoft.AspNetCore.Mvc;@@ -193,6 +194,7 @@ public class CustomerModel : BaseEntityModelpublic int AddLoyaltyPointsValue { get; set; }[GrandResourceDisplayName("Admin.Customers.Customers.LoyaltyPoints.Fields.AddLoyaltyPointsMessage")]+ [NoHtml]public string AddLoyaltyPointsMessage { get; set; }[GrandResourceDisplayName("Admin.Customers.Customers.LoyaltyPoints.Fields.AddLoyaltyPointsStore")]@@ -272,6 +274,7 @@ public class CustomerModel : BaseEntityModelpublic string Subject { get; set; }[GrandResourceDisplayName("Admin.Customers.Customers.SendEmail.Body")]+ [NoHtml]public string Body { get; set; }[GrandResourceDisplayName("Admin.Customers.Customers.SendEmail.SendImmediately")]diff --git a/src/Web/Grand.Web.AdminShared/Models/Documents/DocumentModel.cs b/src/Web/Grand.Web.AdminShared/Models/Documents/DocumentModel.csindex fe49ed56c..66c202875 100644--- a/src/Web/Grand.Web.AdminShared/Models/Documents/DocumentModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Documents/DocumentModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.Common.Link;using Microsoft.AspNetCore.Mvc.Rendering;using System.ComponentModel.DataAnnotations;@@ -19,6 +20,7 @@ public class DocumentModel : BaseEntityModel, IGroupLinkModel, IStoreLinkModelpublic IList<SelectListItem> AvailableSelesEmployees { get; set; } = new List<SelectListItem>();+ [SanitizeHtml][GrandResourceDisplayName("Admin.Documents.Document.Fields.Description")]public string Description { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Documents/DocumentTypeModel.cs b/src/Web/Grand.Web.AdminShared/Models/Documents/DocumentTypeModel.csindex 4e09735fa..a6e644bd3 100644--- a/src/Web/Grand.Web.AdminShared/Models/Documents/DocumentTypeModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Documents/DocumentTypeModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;namespace Grand.Web.AdminShared.Models.Documents;@@ -10,7 +11,7 @@ public class DocumentTypeModel : BaseEntityModelpublic string Name { get; set; }[GrandResourceDisplayName("Admin.Documents.Type.Fields.Description")]-+ [SanitizeHtml]public string Description { get; set; }[GrandResourceDisplayName("Admin.Documents.Type.Fields.DisplayOrder")]diff --git a/src/Web/Grand.Web.AdminShared/Models/Knowledgebase/KnowledgebaseArticleModel.cs b/src/Web/Grand.Web.AdminShared/Models/Knowledgebase/KnowledgebaseArticleModel.csindex b03db2ec7..d57229a3d 100644--- a/src/Web/Grand.Web.AdminShared/Models/Knowledgebase/KnowledgebaseArticleModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Knowledgebase/KnowledgebaseArticleModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.Common.Link;using Grand.Web.Common.Models;using Microsoft.AspNetCore.Mvc.Rendering;@@ -13,6 +14,7 @@ public class KnowledgebaseArticleModel : BaseEntityModel, ILocalizedModel<Knowle[GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseArticle.Fields.Name")]public string Name { get; set; }+ [SanitizeHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseArticle.Fields.Content")]public string Content { get; set; }@@ -25,12 +27,15 @@ public class KnowledgebaseArticleModel : BaseEntityModel, ILocalizedModel<Knowle[GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseArticle.Fields.Published")]public bool Published { get; set; }+ [NoHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseArticle.Fields.MetaKeywords")]public string MetaKeywords { get; set; }+ [NoHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseArticle.Fields.MetaDescription")]public string MetaDescription { get; set; }+ [NoHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseArticle.Fields.MetaTitle")]public string MetaTitle { get; set; }@@ -75,15 +80,19 @@ public class KnowledgebaseArticleLocalizedModel : ILocalizedModelLocal, ISlugMod[GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseArticle.Fields.Name")]public string Name { get; set; }+ [SanitizeHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseArticle.Fields.Content")]public string Content { get; set; }+ [NoHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseArticle.Fields.MetaKeywords")]public string MetaKeywords { get; set; }+ [NoHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseArticle.Fields.MetaDescription")]public string MetaDescription { get; set; }+ [NoHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseArticle.Fields.MetaTitle")]public string MetaTitle { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Knowledgebase/KnowledgebaseCategoryModel.cs b/src/Web/Grand.Web.AdminShared/Models/Knowledgebase/KnowledgebaseCategoryModel.csindex 11c3223bb..481d2411c 100644--- a/src/Web/Grand.Web.AdminShared/Models/Knowledgebase/KnowledgebaseCategoryModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Knowledgebase/KnowledgebaseCategoryModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.Common.Link;using Grand.Web.Common.Models;using Microsoft.AspNetCore.Mvc.Rendering;@@ -19,6 +20,7 @@ public class KnowledgebaseCategoryModel : BaseEntityModel, ILocalizedModel<Knowl[GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseCategory.Fields.DisplayOrder")]public int DisplayOrder { get; set; }+ [SanitizeHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseCategory.Fields.Description")]public string Description { get; set; }@@ -27,12 +29,15 @@ public class KnowledgebaseCategoryModel : BaseEntityModel, ILocalizedModel<Knowlpublic List<SelectListItem> Categories { get; set; } = new();+ [NoHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseCategory.Fields.MetaKeywords")]public string MetaKeywords { get; set; }+ [NoHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseCategory.Fields.MetaDescription")]public string MetaDescription { get; set; }+ [NoHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseCategory.Fields.MetaTitle")]public string MetaTitle { get; set; }@@ -59,15 +64,19 @@ public class KnowledgebaseCategoryLocalizedModel : ILocalizedModelLocal, ISlugMo[GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseCategory.Fields.Name")]public string Name { get; set; }+ [SanitizeHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseCategory.Fields.Description")]public string Description { get; set; }+ [NoHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseCategory.Fields.MetaKeywords")]public string MetaKeywords { get; set; }+ [NoHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseCategory.Fields.MetaDescription")]public string MetaDescription { get; set; }+ [NoHtml][GrandResourceDisplayName("Admin.Content.Knowledgebase.KnowledgebaseCategory.Fields.MetaTitle")]public string MetaTitle { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Messages/NewsletterCategoryModel.cs b/src/Web/Grand.Web.AdminShared/Models/Messages/NewsletterCategoryModel.csindex e58ef258e..1bd85f438 100644--- a/src/Web/Grand.Web.AdminShared/Models/Messages/NewsletterCategoryModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Messages/NewsletterCategoryModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.Common.Link;using Grand.Web.Common.Models;using System.ComponentModel.DataAnnotations;@@ -14,7 +15,7 @@ public class NewsletterCategoryModel : BaseEntityModel, ILocalizedModel<Newslettpublic string Name { get; set; }[GrandResourceDisplayName("admin.marketing.NewsletterCategory.Fields.Description")]-+ [SanitizeHtml]public string Description { get; set; }[GrandResourceDisplayName("admin.marketing.NewsletterCategory.Fields.Selected")]@@ -37,7 +38,7 @@ public class NewsletterCategoryLocalizedModel : ILocalizedModelLocalpublic string Name { get; set; }[GrandResourceDisplayName("admin.marketing.NewsletterCategory.Fields.Description")]-+ [SanitizeHtml]public string Description { get; set; }public string LanguageId { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/News/NewsItemModel.cs b/src/Web/Grand.Web.AdminShared/Models/News/NewsItemModel.csindex 825fffe46..2bc030b9f 100644--- a/src/Web/Grand.Web.AdminShared/Models/News/NewsItemModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/News/NewsItemModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.Common.Link;using Grand.Web.Common.Models;using System.ComponentModel.DataAnnotations;@@ -15,9 +16,11 @@ public class NewsItemModel : BaseEntityModel, ILocalizedModel<NewsLocalizedModel[GrandResourceDisplayName("Admin.Content.News.NewsItems.Fields.Picture")]public string PictureId { get; set; }+ [SanitizeHtml][GrandResourceDisplayName("Admin.Content.News.NewsItems.Fields.Short")]public string Short { get; set; }+ [SanitizeHtml][GrandResourceDisplayName("Admin.Content.News.NewsItems.Fields.Full")]public string Full { get; set; }@@ -32,12 +35,15 @@ public class NewsItemModel : BaseEntityModel, ILocalizedModel<NewsLocalizedModel[UIHint("DateTimeNullable")]public DateTime? EndDate { get; set; }+ [NoHtml][GrandResourceDisplayName("Admin.Content.News.NewsItems.Fields.MetaKeywords")]public string MetaKeywords { get; set; }+ [NoHtml][GrandResourceDisplayName("Admin.Content.News.NewsItems.Fields.MetaDescription")]public string MetaDescription { get; set; }+ [NoHtml][GrandResourceDisplayName("Admin.Content.News.NewsItems.Fields.MetaTitle")]public string MetaTitle { get; set; }@@ -73,23 +79,23 @@ public class NewsLocalizedModel : ILocalizedModelLocal, ISlugModelLocalpublic string Title { get; set; }[GrandResourceDisplayName("Admin.Content.News.NewsItems.Fields.Short")]-+ [SanitizeHtml]public string Short { get; set; }[GrandResourceDisplayName("Admin.Content.News.NewsItems.Fields.Full")]-+ [SanitizeHtml]public string Full { get; set; }[GrandResourceDisplayName("Admin.Content.News.NewsItems.Fields.MetaKeywords")]-+ [NoHtml]public string MetaKeywords { get; set; }[GrandResourceDisplayName("Admin.Content.News.NewsItems.Fields.MetaDescription")]-+ [NoHtml]public string MetaDescription { get; set; }[GrandResourceDisplayName("Admin.Content.News.NewsItems.Fields.MetaTitle")]-+ [NoHtml]public string MetaTitle { get; set; }public string LanguageId { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Orders/GiftVoucherModel.cs b/src/Web/Grand.Web.AdminShared/Models/Orders/GiftVoucherModel.csindex 66487cbaf..598aaa560 100644--- a/src/Web/Grand.Web.AdminShared/Models/Orders/GiftVoucherModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Orders/GiftVoucherModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Microsoft.AspNetCore.Mvc.Rendering;using System.ComponentModel.DataAnnotations;@@ -59,7 +60,7 @@ public class GiftVoucherModel : BaseEntityModelpublic string SenderEmail { get; set; }[GrandResourceDisplayName("Admin.GiftVouchers.Fields.Message")]-+ [NoHtml]public string Message { get; set; }[GrandResourceDisplayName("Admin.GiftVouchers.Fields.IsRecipientNotified")]diff --git a/src/Web/Grand.Web.AdminShared/Models/Orders/MerchandiseReturnModel.cs b/src/Web/Grand.Web.AdminShared/Models/Orders/MerchandiseReturnModel.csindex 52045a631..2c606fce0 100644--- a/src/Web/Grand.Web.AdminShared/Models/Orders/MerchandiseReturnModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Orders/MerchandiseReturnModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.AdminShared.Models.Common;using System.ComponentModel.DataAnnotations;@@ -65,6 +66,7 @@ public class MerchandiseReturnModel : BaseEntityModelpublic bool AddMerchandiseReturnNoteDisplayToCustomer { get; set; }[GrandResourceDisplayName("Admin.Orders.MerchandiseReturns.MerchandiseReturnNotes.Fields.Note")]+ [NoHtml]public string AddMerchandiseReturnNoteMessage { get; set; }public bool AddMerchandiseReturnNoteHasDownload { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Orders/OrderModel.cs b/src/Web/Grand.Web.AdminShared/Models/Orders/OrderModel.csindex f64743d3c..a5e8aff0d 100644--- a/src/Web/Grand.Web.AdminShared/Models/Orders/OrderModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Orders/OrderModel.cs@@ -3,6 +3,7 @@ using Grand.Domain.Payments;using Grand.Domain.Tax;using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.AdminShared.Models.Common;using Microsoft.AspNetCore.Mvc.Rendering;using System.ComponentModel.DataAnnotations;@@ -228,7 +229,7 @@ public class OrderModel : BaseEntityModelpublic bool AddOrderNoteDisplayToCustomer { get; set; }[GrandResourceDisplayName("Admin.Orders.OrderNotes.Fields.Note")]-+ [NoHtml]public string AddOrderNoteMessage { get; set; }public bool AddOrderNoteHasDownload { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Orders/ShipmentModel.cs b/src/Web/Grand.Web.AdminShared/Models/Orders/ShipmentModel.csindex 603192e95..4f881afa7 100644--- a/src/Web/Grand.Web.AdminShared/Models/Orders/ShipmentModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Orders/ShipmentModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using System.ComponentModel.DataAnnotations;namespace Grand.Web.AdminShared.Models.Orders;@@ -49,7 +50,7 @@ public class ShipmentModel : BaseEntityModelpublic bool AddShipmentNoteDisplayToCustomer { get; set; }[GrandResourceDisplayName("Admin.Orders.Shipments.ShipmentNotes.Fields.Note")]-+ [NoHtml]public string AddShipmentNoteMessage { get; set; }public bool AddShipmentNoteHasDownload { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Pages/PageModel.cs b/src/Web/Grand.Web.AdminShared/Models/Pages/PageModel.csindex a2cec7839..c8320b104 100644--- a/src/Web/Grand.Web.AdminShared/Models/Pages/PageModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Pages/PageModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.Common.Link;using Grand.Web.Common.Models;using Microsoft.AspNetCore.Mvc.Rendering;@@ -52,7 +53,7 @@ public class PageModel : BaseEntityModel, ILocalizedModel<PageLocalizedModel>, Ipublic string Title { get; set; }[GrandResourceDisplayName("Admin.Content.Pages.Fields.Body")]-+ [SanitizeHtml]public string Body { get; set; }[GrandResourceDisplayName("Admin.Content.Pages.Fields.PageLayout")]@@ -61,15 +62,15 @@ public class PageModel : BaseEntityModel, ILocalizedModel<PageLocalizedModel>, Ipublic IList<SelectListItem> AvailablePageLayouts { get; set; } = new List<SelectListItem>();[GrandResourceDisplayName("Admin.Content.Pages.Fields.MetaKeywords")]-+ [NoHtml]public string MetaKeywords { get; set; }[GrandResourceDisplayName("Admin.Content.Pages.Fields.MetaDescription")]-+ [NoHtml]public string MetaDescription { get; set; }[GrandResourceDisplayName("Admin.Content.Pages.Fields.MetaTitle")]-+ [NoHtml]public string MetaTitle { get; set; }[GrandResourceDisplayName("Admin.Content.Pages.Fields.SeName")]@@ -104,19 +105,19 @@ public class PageLocalizedModel : ILocalizedModelLocal, ISlugModelLocalpublic string Title { get; set; }[GrandResourceDisplayName("Admin.Content.Pages.Fields.Body")]-+ [SanitizeHtml]public string Body { get; set; }[GrandResourceDisplayName("Admin.Content.Pages.Fields.MetaKeywords")]-+ [NoHtml]public string MetaKeywords { get; set; }[GrandResourceDisplayName("Admin.Content.Pages.Fields.MetaDescription")]-+ [NoHtml]public string MetaDescription { get; set; }[GrandResourceDisplayName("Admin.Content.Pages.Fields.MetaTitle")]-+ [NoHtml]public string MetaTitle { get; set; }public string LanguageId { get; set; }diff --git a/src/Web/Grand.Web.AdminShared/Models/Shipping/PickupPointModel.cs b/src/Web/Grand.Web.AdminShared/Models/Shipping/PickupPointModel.csindex 2ef2d8501..7220cbcb4 100644--- a/src/Web/Grand.Web.AdminShared/Models/Shipping/PickupPointModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Shipping/PickupPointModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.AdminShared.Models.Common;using Microsoft.AspNetCore.Mvc.Rendering;@@ -12,11 +13,11 @@ public class PickupPointModel : BaseEntityModelpublic string Name { get; set; }[GrandResourceDisplayName("Admin.Configuration.Shipping.PickupPoint.Fields.Description")]-+ [NoHtml]public string Description { get; set; }[GrandResourceDisplayName("Admin.Configuration.Shipping.PickupPoint.Fields.AdminComment")]-+ [NoHtml]public string AdminComment { get; set; }[GrandResourceDisplayName("Admin.Configuration.Shipping.PickupPoint.Fields.Address")]diff --git a/src/Web/Grand.Web.AdminShared/Models/Shipping/ShippingMethodModel.cs b/src/Web/Grand.Web.AdminShared/Models/Shipping/ShippingMethodModel.csindex b6b994647..2d7da6570 100644--- a/src/Web/Grand.Web.AdminShared/Models/Shipping/ShippingMethodModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Shipping/ShippingMethodModel.cs@@ -1,5 +1,6 @@-using Grand.Infrastructure.ModelBinding;+using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.Common.Models;using Microsoft.AspNetCore.Mvc.Rendering;@@ -12,7 +13,7 @@ public class ShippingMethodModel : BaseEntityModel, ILocalizedModel<ShippingMethpublic string Name { get; set; }[GrandResourceDisplayName("Admin.Configuration.Shipping.Methods.Fields.Description")]-+ [NoHtml]public string Description { get; set; }[GrandResourceDisplayName("Admin.Configuration.Shipping.Methods.Fields.DisplayOrder")]@@ -35,8 +36,8 @@ public class ShippingMethodLocalizedModel : ILocalizedModelLocalpublic string Name { get; set; }[GrandResourceDisplayName("Admin.Configuration.Shipping.Methods.Fields.Description")]-+ [NoHtml]public string Description { get; set; }public string LanguageId { get; set; }-}\ No newline at end of file+}diff --git a/src/Web/Grand.Web.AdminShared/Models/Vendors/VendorModel.cs b/src/Web/Grand.Web.AdminShared/Models/Vendors/VendorModel.csindex 54cec5586..727f9d02b 100644--- a/src/Web/Grand.Web.AdminShared/Models/Vendors/VendorModel.cs+++ b/src/Web/Grand.Web.AdminShared/Models/Vendors/VendorModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.AdminShared.Models.Common;using Grand.Web.AdminShared.Models.Discounts;using Grand.Web.Common.Models;@@ -28,7 +29,7 @@ public class VendorModel : BaseEntityModel, ILocalizedModel<VendorLocalizedModelpublic string Email { get; set; }[GrandResourceDisplayName("Admin.Vendors.Fields.Description")]-+ [SanitizeHtml]public string Description { get; set; }[UIHint("Picture")]@@ -41,7 +42,7 @@ public class VendorModel : BaseEntityModel, ILocalizedModel<VendorLocalizedModelpublic List<SelectListItem> AvailableStores { get; set; }[GrandResourceDisplayName("Admin.Vendors.Fields.AdminComment")]-+ [NoHtml]public string AdminComment { get; set; }[GrandResourceDisplayName("Admin.Vendors.Fields.Active")]@@ -54,15 +55,15 @@ public class VendorModel : BaseEntityModel, ILocalizedModel<VendorLocalizedModelpublic bool AllowCustomerReviews { get; set; }[GrandResourceDisplayName("Admin.Vendors.Fields.MetaKeywords")]-+ [NoHtml]public string MetaKeywords { get; set; }[GrandResourceDisplayName("Admin.Vendors.Fields.MetaDescription")]-+ [NoHtml]public string MetaDescription { get; set; }[GrandResourceDisplayName("Admin.Vendors.Fields.MetaTitle")]-+ [NoHtml]public string MetaTitle { get; set; }[GrandResourceDisplayName("Admin.Vendors.Fields.SeName")]@@ -125,19 +126,19 @@ public class VendorLocalizedModel : ILocalizedModelLocal, ISlugModelLocalpublic string Name { get; set; }[GrandResourceDisplayName("Admin.Vendors.Fields.Description")]-+ [SanitizeHtml]public string Description { get; set; }[GrandResourceDisplayName("Admin.Vendors.Fields.MetaKeywords")]-+ [NoHtml]public string MetaKeywords { get; set; }[GrandResourceDisplayName("Admin.Vendors.Fields.MetaDescription")]-+ [NoHtml]public string MetaDescription { get; set; }[GrandResourceDisplayName("Admin.Vendors.Fields.MetaTitle")]-+ [NoHtml]public string MetaTitle { get; set; }public string LanguageId { get; set; }diff --git a/src/Web/Grand.Web.Common/Validators/NoScriptsAttribute.cs b/src/Web/Grand.Web.Common/Validators/NoScriptsAttribute.csdeleted file mode 100644index 1ab398b32..000000000--- a/src/Web/Grand.Web.Common/Validators/NoScriptsAttribute.cs+++ /dev/null@@ -1,27 +0,0 @@-using System.ComponentModel.DataAnnotations;-using System.Text.RegularExpressions;--namespace Grand.Web.Common.Validators;--public class NoScriptsAttribute : ValidationAttribute-{- // Simple regular expression to detect potential scripts- private const string Pattern =- "<script.*?>.*?</script>|javascript:[^\\s]*|onload=|onerror=|onmouseover=|onclick=|onchange=|onsubmit=";-- protected override ValidationResult IsValid(object value, ValidationContext validationContext)- {- if (value == null) return ValidationResult.Success;- var valueAsString = value.ToString();- // Check if the value contains a script- return ContainsScript(valueAsString)- ? new ValidationResult("JavaScript scripts are not allowed.")- : ValidationResult.Success;- }-- private static bool ContainsScript(string input)- {- var scriptRegex = new Regex(Pattern, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(1));- return scriptRegex.IsMatch(input);- }-}\ No newline at end of filediff --git a/src/Web/Grand.Web.Store/App_Data/appsettings.json b/src/Web/Grand.Web.Store/App_Data/appsettings.jsonindex 8de0a2c9c..7d37b6440 100644--- a/src/Web/Grand.Web.Store/App_Data/appsettings.json+++ b/src/Web/Grand.Web.Store/App_Data/appsettings.json@@ -78,7 +78,15 @@"CookieSameSite": "Lax","CookieSameSiteExternalAuth": "None",//Enabling this setting allows for verification of access to a specific controller and action in the admin panel using menu configuration.- "AuthorizeAdminMenu": false+ "AuthorizeAdminMenu": false,+ //Hosts whose iframes survive sanitization of rich-text content (product descriptions, blog posts, pages).+ //An iframe pointing anywhere else is removed, because its src is otherwise attacker-controlled. A leading "*." matches any subdomain.+ //Remove the key entirely to use the built-in video-embed defaults (youtube, youtube-nocookie, vimeo, google); set it to [] to block every iframe.+ "SanitizerAllowedIframeHosts": [ "youtube.com", "*.youtube.com", "youtube-nocookie.com", "*.youtube-nocookie.com", "vimeo.com", "*.vimeo.com", "google.com", "*.google.com" ],+ //Operational escape hatch, not a security setting: when [SanitizeHtml]/[NoHtml] wrongly reject legitimate+ //content in production, set this to false to accept input unsanitized while a fix is prepared, then set it+ //back to true as soon as possible. Default true.+ "EnableHtmlSanitization": true},"Cache": {//Gets or sets a value indicating for default cache time in minutes"diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Preview.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Preview.cshtmlindex 7181f83b4..bf79f4933 100644--- a/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Preview.cshtml+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Blog/Preview.cshtml@@ -1,4 +1,4 @@-@model BlogPostModel+@model BlogPostModel@{//page titleViewBag.Title = Loc["Admin.Content.Blog.BlogPosts.Preview"];diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Discount/Partials/CreateOrUpdate.TabRequirements.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Discount/Partials/CreateOrUpdate.TabRequirements.cshtmlindex fe615efa4..4b0588aef 100644--- a/src/Web/Grand.Web.Store/Areas/Store/Views/Discount/Partials/CreateOrUpdate.TabRequirements.cshtml+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Discount/Partials/CreateOrUpdate.TabRequirements.cshtml@@ -1,3 +1,4 @@+@using System.Text.Encodings.Web@model DiscountModel@{@@ -99,7 +100,7 @@@for (var i = 0; i < Model.DiscountRequirementMetaInfos.Count; i++){var drmi = Model.DiscountRequirementMetaInfos[i];- <text>{ discountRequirementId: "@(drmi.DiscountRequirementId)", ruleName: "@(drmi.RuleName)", url: "@(Html.Raw(drmi.ConfigurationUrl))" } </text>+ <text>{ discountRequirementId: "@(drmi.DiscountRequirementId)", ruleName: "@(drmi.RuleName)", url: "@(Html.Raw(JavaScriptEncoder.Default.Encode(drmi.ConfigurationUrl)))" } </text>if (i != Model.DiscountRequirementMetaInfos.Count - 1){<text>, </text>diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Product/BulkEdit.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Product/BulkEdit.cshtmlindex 38ae21002..1a586280c 100644--- a/src/Web/Grand.Web.Store/Areas/Store/Views/Product/BulkEdit.cshtml+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Product/BulkEdit.cshtml@@ -1,4 +1,5 @@-@model BulkEditListModel+@using System.Text.Encodings.Web+@model BulkEditListModel@inject AdminAreaSettings adminAreaSettings@{//page title@@ -89,7 +90,7 @@<text>{Id: '@(method.Value)',- Name: "@Html.Raw(method.Text)"+ Name: "@Html.Raw(JavaScriptEncoder.Default.Encode(method.Text))"},</text>}diff --git a/src/Web/Grand.Web.Vendor/App_Data/appsettings.json b/src/Web/Grand.Web.Vendor/App_Data/appsettings.jsonindex ffb1a975d..abc2b81cc 100644--- a/src/Web/Grand.Web.Vendor/App_Data/appsettings.json+++ b/src/Web/Grand.Web.Vendor/App_Data/appsettings.json@@ -78,7 +78,15 @@"CookieSameSite": "Lax","CookieSameSiteExternalAuth": "None",//Enabling this setting allows for verification of access to a specific controller and action in the admin panel using menu configuration.- "AuthorizeAdminMenu": false+ "AuthorizeAdminMenu": false,+ //Hosts whose iframes survive sanitization of rich-text content (product descriptions, blog posts, pages).+ //An iframe pointing anywhere else is removed, because its src is otherwise attacker-controlled. A leading "*." matches any subdomain.+ //Remove the key entirely to use the built-in video-embed defaults (youtube, youtube-nocookie, vimeo, google); set it to [] to block every iframe.+ "SanitizerAllowedIframeHosts": [ "youtube.com", "*.youtube.com", "youtube-nocookie.com", "*.youtube-nocookie.com", "vimeo.com", "*.vimeo.com", "google.com", "*.google.com" ],+ //Operational escape hatch, not a security setting: when [SanitizeHtml]/[NoHtml] wrongly reject legitimate+ //content in production, set this to false to accept input unsanitized while a fix is prepared, then set it+ //back to true as soon as possible. Default true.+ "EnableHtmlSanitization": true},"Cache": {//Gets or sets a value indicating for default cache time in minutes"diff --git a/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Product/BulkEdit.cshtml b/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Product/BulkEdit.cshtmlindex 66f0ee2a6..307256c14 100644--- a/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Product/BulkEdit.cshtml+++ b/src/Web/Grand.Web.Vendor/Areas/Vendor/Views/Product/BulkEdit.cshtml@@ -1,4 +1,5 @@-@model BulkEditListModel+@using System.Text.Encodings.Web+@model BulkEditListModel@inject AdminAreaSettings adminAreaSettings@{//page title@@ -89,7 +90,7 @@<text>{Id: '@(method.Value)',- Name: "@Html.Raw(method.Text)"+ Name: "@Html.Raw(JavaScriptEncoder.Default.Encode(method.Text))"},</text>}diff --git a/src/Web/Grand.Web.Vendor/Models/Catalog/ProductAttributeModel.cs b/src/Web/Grand.Web.Vendor/Models/Catalog/ProductAttributeModel.csindex a809e6de8..19ad1555b 100644--- a/src/Web/Grand.Web.Vendor/Models/Catalog/ProductAttributeModel.cs+++ b/src/Web/Grand.Web.Vendor/Models/Catalog/ProductAttributeModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.Common.Models;namespace Grand.Web.Vendor.Models.Catalog;@@ -11,7 +12,7 @@ public class ProductAttributeLocalizedModel : ILocalizedModelLocalpublic string Name { get; set; }[GrandResourceDisplayName("Vendor.Catalog.Attributes.ProductAttributes.Fields.Description")]-+ [SanitizeHtml]public string Description { get; set; }public string LanguageId { get; set; }diff --git a/src/Web/Grand.Web.Vendor/Models/Catalog/ProductModel.cs b/src/Web/Grand.Web.Vendor/Models/Catalog/ProductModel.csindex 9eae35c5f..4f87d65ee 100644--- a/src/Web/Grand.Web.Vendor/Models/Catalog/ProductModel.cs+++ b/src/Web/Grand.Web.Vendor/Models/Catalog/ProductModel.cs@@ -2,7 +2,7 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;using Grand.Web.Common.Models;-using Grand.Web.Common.Validators;+using Grand.Infrastructure.Validators;using Microsoft.AspNetCore.Mvc.Rendering;using System.ComponentModel.DataAnnotations;@@ -42,18 +42,18 @@ public class ProductModel : BaseEntityModel, ILocalizedModel<ProductLocalizedMod[GrandResourceDisplayName("Vendor.Catalog.Products.Fields.Name")]public string Name { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Vendor.Catalog.Products.Fields.ShortDescription")]public string ShortDescription { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Vendor.Catalog.Products.Fields.FullDescription")]public string FullDescription { get; set; }[GrandResourceDisplayName("Vendor.Catalog.Products.Fields.Flag")]public string Flag { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Vendor.Catalog.Products.Fields.AdminComment")]public string AdminComment { get; set; }@@ -62,15 +62,15 @@ public class ProductModel : BaseEntityModel, ILocalizedModel<ProductLocalizedModpublic string BrandId { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Vendor.Catalog.Products.Fields.MetaKeywords")]public string MetaKeywords { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Vendor.Catalog.Products.Fields.MetaDescription")]public string MetaDescription { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Vendor.Catalog.Products.Fields.MetaTitle")]public string MetaTitle { get; set; }@@ -389,11 +389,11 @@ public class ProductModel : BaseEntityModel, ILocalizedModel<ProductLocalizedMod"Vendor.Catalog.Products.SpecificationAttributes.Fields.SpecificationAttributeOption")]public string SpecificationAttributeOptionId { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Vendor.Catalog.Products.SpecificationAttributes.Fields.CustomName")]public string CustomName { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Vendor.Catalog.Products.SpecificationAttributes.Fields.CustomValue")]public string CustomValue { get; set; }@@ -965,23 +965,23 @@ public class ProductLocalizedModel : ILocalizedModelLocal, ISlugModelLocalpublic string Name { get; set; }- [NoScripts]+ [SanitizeHtml][GrandResourceDisplayName("Vendor.Catalog.Products.Fields.ShortDescription")]public string ShortDescription { get; set; }[GrandResourceDisplayName("Vendor.Catalog.Products.Fields.FullDescription")]- [NoScripts]+ [SanitizeHtml]public string FullDescription { get; set; }[GrandResourceDisplayName("Vendor.Catalog.Products.Fields.MetaKeywords")]- [NoScripts]+ [NoHtml]public string MetaKeywords { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Vendor.Catalog.Products.Fields.MetaDescription")]public string MetaDescription { get; set; }- [NoScripts]+ [NoHtml][GrandResourceDisplayName("Vendor.Catalog.Products.Fields.MetaTitle")]public string MetaTitle { get; set; }diff --git a/src/Web/Grand.Web.Vendor/Models/Shipment/AddShipmentModel.cs b/src/Web/Grand.Web.Vendor/Models/Shipment/AddShipmentModel.csindex 06e969bb1..53aeee068 100644--- a/src/Web/Grand.Web.Vendor/Models/Shipment/AddShipmentModel.cs+++ b/src/Web/Grand.Web.Vendor/Models/Shipment/AddShipmentModel.cs@@ -1,9 +1,11 @@-namespace Grand.Web.Vendor.Models.Shipment;+using Grand.Infrastructure.Validators;+namespace Grand.Web.Vendor.Models.Shipment;public class AddShipmentModel{public string OrderId { get; set; }public string TrackingNumber { get; set; }+ [NoHtml]public string AdminComment { get; set; }public IList<ShipmentItemModel> Items { get; set; } = new List<ShipmentItemModel>();diff --git a/src/Web/Grand.Web.Vendor/Models/Shipment/ShipmentModel.cs b/src/Web/Grand.Web.Vendor/Models/Shipment/ShipmentModel.csindex f151cda35..837a37be7 100644--- a/src/Web/Grand.Web.Vendor/Models/Shipment/ShipmentModel.cs+++ b/src/Web/Grand.Web.Vendor/Models/Shipment/ShipmentModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;namespace Grand.Web.Vendor.Models.Shipment;@@ -36,6 +37,7 @@ public class ShipmentModel : BaseEntityModelpublic bool CanDeliver { get; set; }public DateTime? DeliveryDateUtc { get; set; }+ [NoHtml][GrandResourceDisplayName("Vendor.Orders.Shipments.AdminComment")]public string AdminComment { get; set; }@@ -48,7 +50,7 @@ public class ShipmentModel : BaseEntityModelpublic bool AddShipmentNoteDisplayToCustomer { get; set; }[GrandResourceDisplayName("Vendor.Orders.Shipments.ShipmentNotes.Fields.Note")]-+ [NoHtml]public string AddShipmentNoteMessage { get; set; }diff --git a/src/Web/Grand.Web.Vendor/Models/Vendor/VendorModel.cs b/src/Web/Grand.Web.Vendor/Models/Vendor/VendorModel.csindex 08bd4c99c..6f9bb2c57 100644--- a/src/Web/Grand.Web.Vendor/Models/Vendor/VendorModel.cs+++ b/src/Web/Grand.Web.Vendor/Models/Vendor/VendorModel.cs@@ -1,5 +1,6 @@using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;using Grand.Web.Common.Models;using Grand.Web.Vendor.Models.Common;@@ -16,19 +17,19 @@ public class VendorModel : BaseEntityModel, ILocalizedModel<VendorLocalizedModelpublic string Email { get; set; }[GrandResourceDisplayName("Vendor.Fields.Description")]-+ [SanitizeHtml]public string Description { get; set; }[GrandResourceDisplayName("Vendor.Fields.MetaKeywords")]-+ [NoHtml]public string MetaKeywords { get; set; }[GrandResourceDisplayName("Vendor.Fields.MetaDescription")]-+ [NoHtml]public string MetaDescription { get; set; }[GrandResourceDisplayName("Vendor.Fields.MetaTitle")]-+ [NoHtml]public string MetaTitle { get; set; }[GrandResourceDisplayName("Vendor.Fields.SeName")]@@ -56,19 +57,19 @@ public class VendorLocalizedModel : ILocalizedModelLocal, ISlugModelLocalpublic string Name { get; set; }[GrandResourceDisplayName("Vendor.Fields.Description")]-+ [SanitizeHtml]public string Description { get; set; }[GrandResourceDisplayName("Vendor.Fields.MetaKeywords")]-+ [NoHtml]public string MetaKeywords { get; set; }[GrandResourceDisplayName("Vendor.Fields.MetaDescription")]-+ [NoHtml]public string MetaDescription { get; set; }[GrandResourceDisplayName("Vendor.Fields.MetaTitle")]-+ [NoHtml]public string MetaTitle { get; set; }public string LanguageId { get; set; }diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.jsonindex 09dbf5898..124777464 100644--- a/src/Web/Grand.Web/App_Data/appsettings.json+++ b/src/Web/Grand.Web/App_Data/appsettings.json@@ -94,7 +94,15 @@//legacy SHA hashes are not affected. Set it once, before going live. Empty = hash without a pepper."PasswordHashKey": "",//PBKDF2 (HMAC-SHA256) iteration count for new/upgraded password hashes. Default 210000 (OWASP). Embedded per-hash, so it can be raised safely later.- "PasswordHashIterations": 210000+ "PasswordHashIterations": 210000,+ //Hosts whose iframes survive sanitization of rich-text content (product descriptions, blog posts, pages).+ //An iframe pointing anywhere else is removed, because its src is otherwise attacker-controlled. A leading "*." matches any subdomain.+ //Remove the key entirely to use the built-in video-embed defaults (youtube, youtube-nocookie, vimeo, google); set it to [] to block every iframe.+ "SanitizerAllowedIframeHosts": [ "youtube.com", "*.youtube.com", "youtube-nocookie.com", "*.youtube-nocookie.com", "vimeo.com", "*.vimeo.com", "google.com", "*.google.com" ],+ //Operational escape hatch, not a security setting: when [SanitizeHtml]/[NoHtml] wrongly reject legitimate+ //content in production, set this to false to accept input unsanitized while a fix is prepared, then set it+ //back to true as soon as possible. Default true.+ "EnableHtmlSanitization": true},"Cache": {//Gets or sets a value indicating for default cache time in minutes"