Skip to content

Commit

Permalink
Add security headers middleware (#536)
Browse files Browse the repository at this point in the history
Co-authored-by: Hammerbeck <[email protected]>
  • Loading branch information
Andreass2 and Hammerbeck authored Sep 2, 2024
1 parent c5d669f commit 1cd468f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Altinn.Broker.API/Helpers/SecurityHeadersMiddleware.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.Extensions.Primitives;

public class SecurityHeadersMiddleware
{
private readonly RequestDelegate _next;

public SecurityHeadersMiddleware(RequestDelegate next)
{
_next = next;
}

public async Task InvokeAsync(HttpContext context)
{
context.Response.Headers.Append("X-Content-Type-Options", new StringValues("nosniff"));
context.Response.Headers.Append("Cache-Control", new StringValues("no-store"));

await _next(context);
}
}
1 change: 1 addition & 0 deletions src/Altinn.Broker.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static void BuildAndRun(string[] args)

var app = builder.Build();
app.UseMiddleware<RequestLoggingMiddleware>();
app.UseMiddleware<SecurityHeadersMiddleware>();
app.UseSerilogRequestLogging();

if (app.Environment.IsDevelopment())
Expand Down

0 comments on commit 1cd468f

Please sign in to comment.