@@ -143,8 +143,11 @@ public void ConfigureServices(IServiceCollection services)
143143 } ) ;
144144 }
145145
146- public void Configure ( IApplicationBuilder app )
146+ public void Configure ( IApplicationBuilder app , IWebHostEnvironment env )
147147 {
148+ app . UseSecurityHeaders (
149+ SecurityHeadersDefinitions . GetHeaderPolicyCollection ( env . IsDevelopment ( ) ) ) ;
150+
148151 app . UseCookiePolicy ( ) ;
149152
150153 if ( _environment . IsDevelopment ( ) )
@@ -157,22 +160,7 @@ public void Configure(IApplicationBuilder app)
157160 app . UseExceptionHandler ( "/Home/Error" ) ;
158161 }
159162
160- app . UseHsts ( hsts => hsts . MaxAge ( 365 ) . IncludeSubdomains ( ) ) ;
161- app . UseXContentTypeOptions ( ) ;
162- app . UseReferrerPolicy ( opts => opts . NoReferrer ( ) ) ;
163- app . UseXXssProtection ( options => options . EnabledWithBlockMode ( ) ) ;
164-
165- app . UseCsp ( opts => opts
166- . BlockAllMixedContent ( )
167- . StyleSources ( s => s . Self ( ) )
168- . StyleSources ( s => s . UnsafeInline ( ) )
169- . FontSources ( s => s . Self ( ) )
170- . FrameAncestors ( s => s . Self ( ) )
171- . ImageSources ( imageSrc => imageSrc . Self ( ) )
172- . ImageSources ( imageSrc => imageSrc . CustomSources ( "data:" ) )
173- . ScriptSources ( s => s . Self ( ) )
174- . ScriptSources ( s => s . UnsafeInline ( ) )
175- ) ;
163+
176164
177165 var locOptions = app . ApplicationServices . GetService < IOptions < RequestLocalizationOptions > > ( ) ;
178166 app . UseRequestLocalization ( locOptions . Value ) ;
@@ -181,25 +169,7 @@ public void Configure(IApplicationBuilder app)
181169 // https://nblumhardt.com/2019/10/serilog-mvc-logging/
182170 app . UseSerilogRequestLogging ( ) ;
183171
184- app . UseStaticFiles ( new StaticFileOptions ( )
185- {
186- OnPrepareResponse = context =>
187- {
188- if ( context . Context . Response . Headers [ "feature-policy" ] . Count == 0 )
189- {
190- var featurePolicy = "accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'" ;
191-
192- context . Context . Response . Headers [ "feature-policy" ] = featurePolicy ;
193- }
194-
195- if ( context . Context . Response . Headers [ "X-Content-Security-Policy" ] . Count == 0 )
196- {
197- var csp = "script-src 'self';style-src 'self';img-src 'self' data:;font-src 'self';form-action 'self';frame-ancestors 'self';block-all-mixed-content" ;
198- // IE
199- context . Context . Response . Headers [ "X-Content-Security-Policy" ] = csp ;
200- }
201- }
202- } ) ;
172+ app . UseStaticFiles ( ) ;
203173
204174 app . UseRouting ( ) ;
205175
0 commit comments