From a506e02edd068748cf2a1d42be946f8c67807ec2 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Tue, 2 Feb 2021 20:55:05 +0000 Subject: [PATCH] Security: add Content-Security-Policy script loaders. Add new functions `wp_get_script_tag`, `wp_print_script_tag`, `wp_print_inline_script_tag` and `wp_get_inline_script_tag` that support script attributes. Enables passing attributes such as `async` or `nonce`, creating a path forward for enabling a Content-Security-Policy in core, plugins and themes. Props tomdxw, johnbillion, jadeddragoon, jrchamp, mallorydxw, epicfaace, alinod, enricocarraro, ocean90. Fixes #39941. Built from https://develop.svn.wordpress.org/trunk@50167 git-svn-id: http://core.svn.wordpress.org/trunk@49846 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 120 ++++++++++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 121 insertions(+), 1 deletion(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 5935f781fb..56f50ce2de 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -7866,3 +7866,123 @@ function is_php_version_compatible( $required ) { function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) { return abs( (float) $expected - (float) $actual ) <= $precision; } + +/** + * Sanitizes an attributes array into an attributes string to be placed inside a `\n", wp_sanitize_script_attributes( $attributes ) ); +} + +/** + * Prints formatted `\n", wp_sanitize_script_attributes( $attributes ), $javascript ); +} + +/** + * Prints inline JavaScript wrapped in `