Skip to content

Commit

Permalink
fixup! add Reporting-Endpoints header; add report-uri as well
Browse files Browse the repository at this point in the history
  • Loading branch information
timmywil committed Sep 11, 2024
1 parent 92228a4 commit 8cbee1f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion themes/jquery/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ function jq_content_security_policy() {
return;
}
$nonce = bin2hex( random_bytes( 8 ) );
$report_url = 'https://csp-report-api.openjs-foundation.workers.dev/';
$policy = array(
'default-src' => "'self'",
'script-src' => "'self' 'nonce-$nonce' code.jquery.com",
Expand All @@ -277,7 +278,10 @@ function jq_content_security_policy() {
'frame-ancestors' => "'none'",
'base-uri' => "'self'",
'block-all-mixed-content' => '',
'report-to' => 'https://csp-report-api.openjs-foundation.workers.dev/',
'report-to' => 'csp-endpoint',
// Add report-uri for Firefox, which
// does not yet support report-to
'report-uri' => $report_url,
);

$policy = apply_filters( 'jq_content_security_policy', $policy );
Expand All @@ -287,6 +291,7 @@ function jq_content_security_policy() {
$policy_string .= $key . ' ' . $value . '; ';
}

header( 'Reporting-Endpoints: csp-endpoint="' . $report_url . '"' );
header( 'Content-Security-Policy-Report-Only: ' . $policy_string );
}

Expand Down

0 comments on commit 8cbee1f

Please sign in to comment.