Skip to content

Commit 41b58b4

Browse files
committed
fixup! use wp_headers filter; use random bytes for nonce
1 parent c16a9ff commit 41b58b4

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

themes/jquery/functions.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ function jq_image_posted_on() {
255255
/**
256256
* Content Security Policy
257257
*/
258-
function jq_content_security_policy() {
259-
$nonce = wp_create_nonce( JQUERY_LIVE_SITE );
258+
function jq_content_security_policy( $headers ) {
259+
$nonce = bin2hex( random_bytes( 8 ) );
260260
$policy = array(
261261
'default-src' => "'self'",
262262
'script-src' => "'self' 'nonce-$nonce' code.jquery.com",
@@ -285,5 +285,9 @@ function jq_content_security_policy() {
285285
$policy_string .= $key . ' ' . $value . '; ';
286286
}
287287

288-
header( 'Content-Security-Policy-Report-Only: ' . $policy_string );
288+
$headers[] = 'Content-Security-Policy: ' . $policy_string;
289+
290+
return $headers;
289291
}
292+
293+
add_filter( 'wp_headers', 'jq_content_security_policy' );

themes/jquery/header.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?php jq_content_security_policy() ?>
21
<!doctype html>
32
<html class="no-js" <?php language_attributes(); ?>>
43
<head>

0 commit comments

Comments
 (0)