Skip to content

Commit

Permalink
feat: or-2035 remove HtmlSanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintenGreenstack committed Jan 11, 2024
1 parent d25ef42 commit 709f6e8
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 21 deletions.
1 change: 0 additions & 1 deletion AssociationRegistry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".Solution Items", ".Solutio
build.fsx = build.fsx
global.json = global.json
paket.dependencies = paket.dependencies
paket.lock = paket.lock
SolutionInfo.cs = SolutionInfo.cs
.gitignore = .gitignore
package.json = package.json
Expand Down
2 changes: 0 additions & 2 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ nuget Be.Vlaanderen.Basisregisters.DataDog.Tracing.Sql 5.0.0
nuget Be.Vlaanderen.Basisregisters.DataDog.Tracing.SqlStreamStore 5.0.0

nuget Destructurama.JsonNet 2.0.0
nuget HtmlSanitizer

// FIX SWASHBUCKLE ASSEMBLY VERSION MISMATCH
nuget Swashbuckle.AspNetCore.SwaggerGen 6.3.0
Expand Down Expand Up @@ -135,4 +134,3 @@ group Testing

nuget Microsoft.Extensions.DependencyInjection 6.0.0
nuget System.Collections.Immutable ~> 7.0

10 changes: 1 addition & 9 deletions paket.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
RESTRICTION: || (== net472) (== net6.0)
NUGET
remote: https://api.nuget.org/v3/index.json
AngleSharp (0.16.1)
System.Buffers (>= 4.5.1)
System.Text.Encoding.CodePages (>= 5.0)
AngleSharp.Css (0.16.1)
AngleSharp (>= 0.16)
AspNetCore.HealthChecks.SqlServer (6.0.2)
Microsoft.Data.SqlClient (>= 3.0.1)
Microsoft.Extensions.Diagnostics.HealthChecks (>= 6.0)
Expand Down Expand Up @@ -469,9 +464,6 @@ NUGET
Microsoft.Extensions.Logging.Abstractions (>= 3.0.3)
Grpc.Net.Common (2.50) - restriction: || (&& (== net472) (>= netstandard2.1)) (== net6.0)
Grpc.Core.Api (>= 2.50)
HtmlSanitizer (6.0.453)
AngleSharp (0.16.1)
AngleSharp.Css (0.16.1)
Humanizer.Core (2.14.1) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
IdentityModel (6.0) - restriction: || (&& (== net472) (>= netcoreapp3.1)) (== net6.0)
IdentityModel.AspNetCore.OAuth2Introspection (6.0)
Expand Down Expand Up @@ -1423,7 +1415,7 @@ NUGET
Microsoft.NETCore.Platforms (>= 1.1) - restriction: || (&& (== net472) (< net45)) (== net6.0)
Microsoft.NETCore.Targets (>= 1.1) - restriction: || (&& (== net472) (< net45)) (== net6.0)
System.Runtime (>= 4.3) - restriction: || (&& (== net472) (< net45)) (== net6.0)
System.Text.Encoding.CodePages (6.0)
System.Text.Encoding.CodePages (6.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
System.Runtime.CompilerServices.Unsafe (>= 6.0)
System.Text.Encoding.Extensions (4.3) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Microsoft.NETCore.Platforms (>= 1.1) - restriction: || (&& (== net472) (< net45)) (== net6.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,5 @@ public static async Task NullValidateAndThrowAsync<T>(
await validator.ValidateAndThrowAsync(instance, cancellationToken);
}

public static IRuleBuilder<T, string?> MustNotContainHtml<T>(this IRuleBuilder<T, string?> ruleBuilder)
=> ruleBuilder
.Must(NotContainHtml)
.WithErrorCode(StatusCodes.Status400BadRequest.ToString())
.WithMessage(ExceptionMessages.UnsupportedContent);

private static bool NotContainHtml(string? propertyValue)
=> propertyValue is null ? true : !Regex.IsMatch(propertyValue, pattern: "<.*?>");
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace AssociationRegistry.Admin.Api.Infrastructure.Validation;
using System.Linq.Expressions;
using FluentValidation;
using FluentValidation.Internal;
using Microsoft.AspNetCore.Http;
using System.Text.RegularExpressions;

public static class ValidatorHelpers
{
Expand Down Expand Up @@ -35,4 +37,13 @@ public static void RequireValidKboNummer<T>(this AbstractValidator<T> validator,
.WithMessage($"'{expression.GetMember().Name}' moet 10 cijfers bevatten.")
.When(request => !string.IsNullOrEmpty(expression.Compile().Invoke(request)));
}

public static IRuleBuilder<T, string?> MustNotContainHtml<T>(this IRuleBuilder<T, string?> ruleBuilder)
=> ruleBuilder
.Must(NotContainHtml)
.WithErrorCode(StatusCodes.Status400BadRequest.ToString())
.WithMessage(ExceptionMessages.UnsupportedContent);

private static bool NotContainHtml(string? propertyValue)
=> propertyValue is null || !Regex.IsMatch(propertyValue, pattern: "<.*?>");
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using FluentValidation;
using Infrastructure.Extensions;
using Infrastructure.Validation;

public class TeWijzigenMaatschappelijkeZetelValidator : AbstractValidator<TeWijzigenMaatschappelijkeZetel>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using FluentValidation;
using Infrastructure.Extensions;
using Infrastructure.Validation;

public class TeWijzigenVertegenwoordigerValidator : AbstractValidator<TeWijzigenVertegenwoordiger>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace AssociationRegistry.Admin.Api.Verenigingen.WijzigBasisgegevens.Feiteli
using Common;
using FluentValidation;
using Infrastructure.Extensions;
using Infrastructure.Validation;
using System.Linq;

public class WijzigBasisgegevensRequestValidator : AbstractValidator<WijzigBasisgegevensRequest>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace AssociationRegistry.Admin.Api.Verenigingen.WijzigBasisgegevens.MetRech
using Common;
using FluentValidation;
using Infrastructure.Extensions;
using Infrastructure.Validation;
using System.Linq;

public class WijzigBasisgegevensRequestValidator : AbstractValidator<WijzigBasisgegevensRequest>
Expand Down
1 change: 0 additions & 1 deletion src/AssociationRegistry.Admin.Api/paket.references
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Be.Vlaanderen.Basisregisters.DataDog.Tracing.Autofac
Be.Vlaanderen.Basisregisters.BlobStore

AspNetCore.HealthChecks.SqlServer
HtmlSanitizer
IdentityModel.AspNetCore.OAuth2Introspection
Marten
Marten.CommandLine
Expand Down
1 change: 0 additions & 1 deletion test/AssociationRegistry.Test/paket.references
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Be.Vlaanderen.Basisregisters.EventHandling.Autofac
AutoFixture
FluentAssertions
FluentAssertions.Json
HtmlSanitizer
Marten
Moq
Microsoft.AspNetCore.Mvc.Testing
Expand Down

0 comments on commit 709f6e8

Please sign in to comment.