Skip to content

Commit 80715f1

Browse files
authored
All: add CSP report only header for all blog sites
- allow scripts, styles, and images from code.jquery.com Ref jquery/infrastructure-puppet#54 Closes gh-8
1 parent 6710984 commit 80715f1

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

jquery/functions.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,35 @@ function twentyeleven_body_classes( $classes ) {
281281
return $classes;
282282
}
283283
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

Comments
 (0)