aspnetcore security headers
1.0.1
AdamBarclay.AspNetCore.SecurityHeaders nugetパッケージをインストールします。
Install-Package AdamBarclay.AspNetCore.SecurityHeadersASP.NETパイプラインにセキュリティヘッダーミドルウェアを含めるには、アプリケーションの構成中に次のものがあります。
using AdamBarclay . AspNetCore . SecurityHeaders ;と電話:
app . UseSecurityHeaders ( ) app.UseSecurityHeaders()を呼び出すことは、呼び出しに相当します。
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 。