Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions themes/api.jquery.com/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

// Allow inline scripts and styles in API demos
add_filter( 'jq_content_security_policy', function ( $policy ) {
$policy[ 'script-src' ] = "'self' 'unsafe-inline' code.jquery.com";
$policy[ 'style-src' ] = "'self' 'unsafe-inline'";
return $policy;
} );
7 changes: 7 additions & 0 deletions themes/api.jquerymobile.com/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ function jq_mobile_api_version_current() {
$thisVersion[ 1 ] :
jq_mobile_api_version_latest();
}

// Allow inline scripts and styles in API demos
add_filter( 'jq_content_security_policy', function ( $policy ) {
$policy[ 'script-src' ] = "'self' 'unsafe-inline' code.jquery.com";
$policy[ 'style-src' ] = "'self' 'unsafe-inline'";
return $policy;
} );
7 changes: 7 additions & 0 deletions themes/api.jqueryui.com/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ function jq_ui_api_version_current() {
$thisVersion[ 1 ] :
jq_ui_api_version_latest();
}

// Allow inline scripts and styles in API demos
add_filter( 'jq_content_security_policy', function ( $policy ) {
$policy[ 'script-src' ] = "'self' 'unsafe-inline' code.jquery.com";
$policy[ 'style-src' ] = "'self' 'unsafe-inline'";
return $policy;
} );
45 changes: 45 additions & 0 deletions themes/jquery/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,48 @@ function jq_image_posted_on() {

return $classes;
} );

/**
* Content Security Policy
*/
function jq_content_security_policy() {
if ( !JQUERY_STAGING ) {
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",
// The nonce is here so inline scripts can be used in the theme
'style-src' => "'self' 'nonce-$nonce'",
// data: SVG images are used in typesense
'img-src' => "'self' data:",
'connect-src' => "'self' typesense.jquery.com",
'font-src' => "'self'",
'object-src' => "'none'",
'media-src' => "'self'",
'frame-src' => "'self'",
'child-src' => "'self'",
'form-action' => "'self'",
'frame-ancestors' => "'none'",
'base-uri' => "'self'",
'block-all-mixed-content' => '',
'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 );

$policy_string = '';
foreach ( $policy as $key => $value ) {
$policy_string .= $key . ' ' . $value . '; ';
}

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

add_action( 'send_headers', 'jq_content_security_policy' );
1 change: 0 additions & 1 deletion themes/jquery/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">

<title><?php
global $page, $paged;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a carryover from the default Wordpress header.php, but these variables are not used.

wp_title( '|', true, 'right' );
bloginfo( 'name' );
$site_description = get_bloginfo( 'description', 'display' );
Expand Down