mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
REST API: Create the general wp_check_jsonp_callback() function for validating JSONP callback functions.
Move the REST API JSONP callback validation check into a separate function named `wp_check_jsonp_callback()`. This allows plugins to use the built-in validation when handling JSONP callbacks. Extremely Important Note: If you send JSONP in your custom response, make sure you prefix the response with `/**/`. This will mitigate the Rosetta Flash exploit. You should also send the `X-Content-Type-Options:nosniff` header, or even better, use the REST API infrastructure. Props rmccue. Fixes #28523. git-svn-id: https://develop.svn.wordpress.org/trunk@37646 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -3104,6 +3104,28 @@ function wp_send_json_error( $data = null ) {
|
||||
wp_send_json( $response );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a JSONP callback is a valid JavaScript callback.
|
||||
*
|
||||
* Only allows alphanumeric characters and the dot character in callback
|
||||
* function names. This helps to mitigate XSS attacks caused by directly
|
||||
* outputting user input.
|
||||
*
|
||||
* @since 4.6.0
|
||||
*
|
||||
* @param string $callback Supplied JSONP callback function.
|
||||
* @return bool True if valid callback, otherwise false.
|
||||
*/
|
||||
function wp_check_jsonp_callback( $callback ) {
|
||||
if ( ! is_string( $callback ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$jsonp_callback = preg_replace( '/[^\w\.]/', '', $callback, -1, $illegal_char_count );
|
||||
|
||||
return 0 === $illegal_char_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the WordPress home page URL.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user