From 2a0dab9a2e030045056207aaea174a80f36ea583 Mon Sep 17 00:00:00 2001 From: Engincan VESKE <43685404+EngincanV@users.noreply.github.com> Date: Thu, 20 Apr 2023 10:07:27 +0300 Subject: [PATCH] Add custom security header support to security header middleware --- .../Security/AbpSecurityHeadersMiddleware.cs | 21 ++++++++++++++----- .../Security/AbpSecurityHeadersOptions.cs | 9 ++++++++ .../SecurityHeadersTestController_Tests.cs | 9 ++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/AbpSecurityHeadersMiddleware.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/AbpSecurityHeadersMiddleware.cs index 37c18f6b70..29e05b9bdc 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/AbpSecurityHeadersMiddleware.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/AbpSecurityHeadersMiddleware.cs @@ -20,27 +20,38 @@ public class AbpSecurityHeadersMiddleware : IMiddleware, ITransientDependency public async Task InvokeAsync(HttpContext context, RequestDelegate next) { /*X-Content-Type-Options header tells the browser to not try and “guess” what a mimetype of a resource might be, and to just take what mimetype the server has returned as fact.*/ - AddHeaderIfNotExists(context, "X-Content-Type-Options", "nosniff"); + AddHeader(context, "X-Content-Type-Options", "nosniff"); /*X-XSS-Protection is a feature of Internet Explorer, Chrome and Safari that stops pages from loading when they detect reflected cross-site scripting (XSS) attacks*/ - AddHeaderIfNotExists(context, "X-XSS-Protection", "1; mode=block"); + AddHeader(context, "X-XSS-Protection", "1; mode=block"); /*The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a ,