Browse Source
Skip to add security headers if endpoint has `IgnoreAbpSecurityHeaderAttribute`.
pull/21725/head
maliming
2 years ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
1 changed files with
8 additions and
8 deletions
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Security/AbpSecurityHeadersMiddleware.cs
@ -23,6 +23,14 @@ public class AbpSecurityHeadersMiddleware : AbpMiddlewareBase, ITransientDepende
public async override Task InvokeAsync ( HttpContext context , RequestDelegate next )
{
var endpoint = context . GetEndpoint ( ) ;
if ( endpoint ? . Metadata . GetMetadata < IgnoreAbpSecurityHeaderAttribute > ( ) ! = null )
{
await next . Invoke ( context ) ;
return ;
}
/*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.*/
AddHeader ( context , "X-Content-Type-Options" , "nosniff" ) ;
@ -35,14 +43,6 @@ public class AbpSecurityHeadersMiddleware : AbpMiddlewareBase, ITransientDepende
var requestAcceptTypeHtml = context . Request . Headers [ "Accept" ] . Any ( x = >
x ! . Contains ( "text/html" ) | | x . Contains ( "*/*" ) | | x . Contains ( "application/xhtml+xml" ) ) ;
var endpoint = context . GetEndpoint ( ) ;
if ( endpoint ? . Metadata . GetMetadata < IgnoreAbpSecurityHeaderAttribute > ( ) ! = null )
{
await next . Invoke ( context ) ;
return ;
}
if ( ! requestAcceptTypeHtml
| | ! Options . Value . UseContentSecurityPolicyHeader
| | await AlwaysIgnoreContentTypes ( context )