@@ -251,3 +251,39 @@ function jq_image_posted_on() {
251
251
252
252
return $ classes ;
253
253
} );
254
+
255
+ /**
256
+ * Content Security Policy
257
+ */
258
+ function jq_content_security_policy () {
259
+ $ nonce = wp_create_nonce ( JQUERY_LIVE_SITE );
260
+ $ policy = array (
261
+ 'default-src ' => "'self' " ,
262
+ 'script-src ' => "'self' 'nonce- $ nonce' code.jquery.com " ,
263
+ // The SHA is for the inline style from typesense
264
+ // 'unsafe-hashes' is required in order to use hashes in style-src
265
+ 'style-src ' => "'self' 'nonce- $ nonce' 'sha256-biLFinpqYMtWHmXfkA1BPeCY0/fNt46SAZ+BBk5YUog=' 'unsafe-hashes' " ,
266
+ // data: SVG images are used in typesense
267
+ 'img-src ' => "'self' data: " ,
268
+ 'connect-src ' => "'self' typesense.jquery.com " ,
269
+ 'font-src ' => "'self' " ,
270
+ 'object-src ' => "'none' " ,
271
+ 'media-src ' => "'self' " ,
272
+ 'frame-src ' => "'self' " ,
273
+ 'child-src ' => "'self' " ,
274
+ 'form-action ' => "'self' " ,
275
+ 'frame-ancestors ' => "'none' " ,
276
+ 'base-uri ' => "'self' " ,
277
+ 'block-all-mixed-content ' => '' ,
278
+ 'report-uri ' => 'https://csp-report-api.openjs-foundation.workers.dev/ ' ,
279
+ );
280
+
281
+ $ policy = apply_filters ( 'jq_content_security_policy ' , $ policy );
282
+
283
+ $ policy_string = '' ;
284
+ foreach ( $ policy as $ key => $ value ) {
285
+ $ policy_string .= $ key . ' ' . $ value . '; ' ;
286
+ }
287
+
288
+ header ( 'Content-Security-Policy-Report-Only: ' . $ policy_string );
289
+ }
0 commit comments