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 。