aspnetcore security headers
1.0.1
安装AdamBarclay.AspNetCore.SecurityHeaders nuget软件包。
Install-Package AdamBarclay.AspNetCore.SecurityHeaders为了在ASP.NET管道中包括安全标头中间件,在应用程序配置期间包括:
using AdamBarclay . AspNetCore . SecurityHeaders ;并致电:
app . UseSecurityHeaders ( ) 呼叫app.UseSecurityHeaders()是neqvalent呼叫:
app . UseSecurityHeaders (
c =>
{
c . ContentSecurityPolicy ( o =>
{
o . ConfigureDefault ( ) . Self ( ) ;
o . ConfigureObject ( ) . None ( ) ;
o . ConfigureDirective ( "frame-ancestors" ) . None ( ) ;
} ) ;
c . FrameOptions ( o => o . Deny ( ) ) ;
c . ReferrerPolicy ( o => o . StrictOriginWhenCrossOrigin ( ) ) ;
c . StrictTransportSecurity ( o => o . MaxAge ( TimeSpan . FromDays ( 365 ) ) . IncludeSubdomains ( ) ) ;
} ) ;默认情况下,包括所有安全标头。要禁用任何标头,请在该标头配置构建器上调用Disable() 。
app . UseSecurityHeaders (
c =>
{
c . ContentSecurityPolicy ( o => o . Disable ( ) ) ;
c . ContentTypeOptions ( o => o . Disable ( ) ) ;
c . FrameOptions ( o => o . Disable ( ) ) ;
c . ReferrerPolicy ( o => o . Disable ( ) ) ;
c . StrictTransportSecurity ( o => o . Disable ( ) ) ;
} ) ; content-security-policy的默认值是default-src 'self';frame-ancestors 'none';object-src 'none' 。
x-content-type-options的默认值是nosniff 。
没有其他值可以配置。
x-frame-options的默认值是deny 。
使用FrameOptions()配置构建器配置值。
致电Deny()将值设置为deny 。
app . UseSecurityHeaders ( c => c . FrameOptions ( o => o . Deny ( ) ) ) ;致电SameOrigin()将值设置为sameorigin 。
app . UseSecurityHeaders ( c => c . FrameOptions ( o => o . SameOrigin ( ) ) ) ; referrer-policy的默认值是strict-origin-when-cross-origin 。
strict-transport-security的默认值为max-age=31536000;includeSubdomains 。