@@ -281,3 +281,35 @@ function twentyeleven_body_classes( $classes ) {
281
281
return $ classes ;
282
282
}
283
283
add_filter ( 'body_class ' , 'twentyeleven_body_classes ' );
284
+
285
+ /**
286
+ * Content Security Policy
287
+ */
288
+ function twentyeleven_content_security_policy () {
289
+ $ report_url = 'https://csp-report-api.openjs-foundation.workers.dev/ ' ;
290
+ $ policy = array (
291
+ 'default-src ' => "'self' " ,
292
+ 'script-src ' => "'self' code.jquery.com " ,
293
+ 'style-src ' => "'self' code.jquery.com " ,
294
+ 'img-src ' => "'self' code.jquery.com " ,
295
+ 'object-src ' => "'none' " ,
296
+ 'frame-ancestors ' => "'none' " ,
297
+ 'block-all-mixed-content ' => '' ,
298
+ 'report-to ' => 'csp-endpoint ' ,
299
+ // Add report-uri for Firefox, which
300
+ // does not yet support report-to
301
+ 'report-uri ' => $ report_url ,
302
+ );
303
+
304
+ $ policy = apply_filters ( 'twentyeleven_content_security_policy ' , $ policy );
305
+
306
+ $ policy_string = '' ;
307
+ foreach ( $ policy as $ key => $ value ) {
308
+ $ policy_string .= $ key . ' ' . $ value . '; ' ;
309
+ }
310
+
311
+ header ( 'Reporting-Endpoints: csp-endpoint=" ' . $ report_url . '" ' );
312
+ header ( 'Content-Security-Policy-Report-Only: ' . $ policy_string );
313
+ }
314
+
315
+ add_action ( 'send_headers ' , 'twentyeleven_content_security_policy ' );
0 commit comments