Skip to content

Commit

Permalink
Redact PII from request URLs in logs (#1406)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad authored Jul 4, 2024
1 parent 0335897 commit 0ac5831
Show file tree
Hide file tree
Showing 29 changed files with 273 additions and 286 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using TeachingRecordSystem.Api.Infrastructure.ApplicationModel;
using TeachingRecordSystem.Api.Infrastructure.Filters;
using TeachingRecordSystem.Api.Infrastructure.Json;
using TeachingRecordSystem.Api.Infrastructure.Logging;
using TeachingRecordSystem.Api.Infrastructure.Mapping;
using TeachingRecordSystem.Api.Infrastructure.Middleware;
using TeachingRecordSystem.Api.Infrastructure.ModelBinding;
Expand All @@ -28,6 +27,7 @@
using TeachingRecordSystem.Core.Services.NameSynonyms;
using TeachingRecordSystem.Core.Services.TrnGenerationApi;
using TeachingRecordSystem.ServiceDefaults;
using TeachingRecordSystem.ServiceDefaults.Infrastructure.Logging;

[assembly: ApiController]
namespace TeachingRecordSystem.Api;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -10,13 +10,10 @@
<PackageReference Include="FluentValidation.AspNetCore" />
<PackageReference Include="idunno.Authentication.Basic" />
<PackageReference Include="MediatR" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" />
<PackageReference Include="Moq" />
<PackageReference Include="RedisRateLimiting.AspNetCore" />
<PackageReference Include="Sentry.AspNetCore" />
<PackageReference Include="Serilog.AspNetCore" />
<PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using TeachingRecordSystem.Api.Infrastructure.Logging;
using TeachingRecordSystem.Api.Infrastructure.Security;
using TeachingRecordSystem.Api.V1.Requests;
using TeachingRecordSystem.Api.V1.Responses;
Expand All @@ -28,7 +27,6 @@ public TeachersController(IMediator mediator)
[ProducesResponseType(typeof(GetTeacherResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
[RedactQueryParam("birthdate"), RedactQueryParam("nino")]
public async Task<IActionResult> GetTeacher([FromRoute] GetTeacherRequest request)
{
var response = await _mediator.Send(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using TeachingRecordSystem.Api.Infrastructure.Logging;
using TeachingRecordSystem.Api.Infrastructure.Security;
using TeachingRecordSystem.Api.V2.Requests;
using TeachingRecordSystem.Api.V2.Responses;
Expand Down Expand Up @@ -30,7 +29,6 @@ public IttOutcomeController(IMediator mediator)
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status409Conflict)]
[MapError(10001, statusCode: StatusCodes.Status404NotFound)]
[MapError(10002, statusCode: StatusCodes.Status409Conflict)]
[RedactQueryParam("birthdate")]
public async Task<IActionResult> SetIttOutcome([FromBody] SetIttOutcomeRequest request)
{
var response = await _mediator.Send(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using TeachingRecordSystem.Api.Infrastructure.Logging;
using TeachingRecordSystem.Api.Infrastructure.Security;
using TeachingRecordSystem.Api.V2.Requests;
using TeachingRecordSystem.Api.V2.Responses;
Expand Down Expand Up @@ -53,7 +52,6 @@ public async Task<IActionResult> GetTeacher([FromRoute] GetTeacherRequest reques
[ProducesResponseType(StatusCodes.Status204NoContent)]
[MapError(10001, statusCode: StatusCodes.Status404NotFound)]
[MapError(10002, statusCode: StatusCodes.Status409Conflict)]
[RedactQueryParam("birthdate")]
[Authorize(Policy = AuthorizationPolicies.UpdatePerson)]
public async Task<IActionResult> Update([FromBody] UpdateTeacherRequest request)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using TeachingRecordSystem.AuthorizeAccess;
using TeachingRecordSystem.AuthorizeAccess.Infrastructure.Filters;
using TeachingRecordSystem.AuthorizeAccess.Infrastructure.FormFlow;
using TeachingRecordSystem.AuthorizeAccess.Infrastructure.Logging;
using TeachingRecordSystem.AuthorizeAccess.Infrastructure.Middleware;
using TeachingRecordSystem.AuthorizeAccess.Infrastructure.Oidc;
using TeachingRecordSystem.AuthorizeAccess.Infrastructure.Security;
Expand All @@ -28,6 +27,7 @@
using TeachingRecordSystem.Core.Services.Files;
using TeachingRecordSystem.Core.Services.PersonMatching;
using TeachingRecordSystem.ServiceDefaults;
using TeachingRecordSystem.ServiceDefaults.Infrastructure.Logging;
using TeachingRecordSystem.SupportUi.Infrastructure.FormFlow;
using TeachingRecordSystem.UiCommon.Filters;
using TeachingRecordSystem.UiCommon.FormFlow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
<PackageReference Include="GovUk.OneLogin.AspNetCore" />
<PackageReference Include="Humanizer.Core" />
<PackageReference Include="Joonasw.AspNetCore.SecurityHeaders" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" />
<PackageReference Include="OpenIddict.AspNetCore" />
<PackageReference Include="Sentry.AspNetCore" />
<PackageReference Include="Serilog.AspNetCore" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft.AspNetCore": "Warning"
}
"Default": "Information"
},
"Enrich": [ "FromLogContext" ],
"Using": [ "Serilog.Expressions" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Extensions.Hosting;
using Prometheus;
using TeachingRecordSystem.Core.Infrastructure.Configuration;
using TeachingRecordSystem.ServiceDefaults.Infrastructure.Logging;

namespace TeachingRecordSystem.ServiceDefaults;

Expand All @@ -24,6 +25,7 @@ public static IHostApplicationBuilder AddServiceDefaults(

builder.Services.AddHealthChecks().AddNpgSql(builder.Configuration.GetPostgresConnectionString());
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddSingleton<UrlRedactor>();

if (builder.Environment.IsProduction())
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
using TeachingRecordSystem.ServiceDefaults.Infrastructure.Logging;

namespace TeachingRecordSystem.ServiceDefaults.Infrastructure.ApplicationInsights;

public class RedactedUrlTelemetryProcessor(ITelemetryProcessor next, UrlRedactor urlRedactor) : ITelemetryProcessor
{
public void Process(ITelemetry item)
{
if (item is RequestTelemetry requestTelemetry)
{
requestTelemetry.Url = new Uri(urlRedactor.GetScrubbedRequestUrl());
}

next.Process(item);
}
}
Loading

0 comments on commit 0ac5831

Please sign in to comment.