Skip to content

Commit f57be20

Browse files
committed
REST API: Remove _wpnonce value from being used in hashed oEmbed proxy cache key.
Amends [40628]. Props r-a-y, westonruter. See #40450. Fixes #41048. git-svn-id: https://develop.svn.wordpress.org/trunk@41035 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f628aaa commit f57be20

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/wp-includes/class-wp-oembed-controller.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public function get_proxy_item( $request ) {
159159
$args = $request->get_params();
160160

161161
// Serve oEmbed data from cache if set.
162+
unset( $args['_wpnonce'] );
162163
$cache_key = 'oembed_' . md5( serialize( $args ) );
163164
$data = get_transient( $cache_key );
164165
if ( ! empty( $data ) ) {

tests/phpunit/tests/oembed/controller.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Test_oEmbed_Controller extends WP_UnitTestCase {
1010
*/
1111
protected $server;
1212
protected static $editor;
13+
protected static $administrator;
1314
protected static $subscriber;
1415
const YOUTUBE_VIDEO_ID = 'OQSNhk5ICTI';
1516
const INVALID_OEMBED_URL = 'https://www.notreallyanoembedprovider.com/watch?v=awesome-cat-video';
@@ -22,6 +23,10 @@ public static function wpSetUpBeforeClass( $factory ) {
2223
'role' => 'editor',
2324
'user_email' => 'editor@example.com',
2425
) );
26+
self::$administrator = $factory->user->create( array(
27+
'role' => 'administrator',
28+
'user_email' => 'administrator@example.com',
29+
) );
2530
}
2631

2732
public static function wpTearDownAfterClass() {
@@ -477,14 +482,22 @@ public function test_proxy_with_invalid_type() {
477482

478483
public function test_proxy_with_valid_oembed_provider() {
479484
wp_set_current_user( self::$editor );
480-
481485
$request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' );
482486
$request->set_param( 'url', 'https://www.youtube.com/watch?v=' . self::YOUTUBE_VIDEO_ID );
487+
$request->set_param( '_wpnonce', wp_create_nonce( 'wp_rest' ) );
483488
$response = $this->server->dispatch( $request );
484489
$this->assertEquals( 200, $response->get_status() );
485490
$this->assertEquals( 1, $this->request_count );
486491

487492
// Subsequent request is cached and so it should not cause a request.
493+
$this->server->dispatch( $request );
494+
$this->assertEquals( 1, $this->request_count );
495+
496+
// Rest with another user should also be cached.
497+
wp_set_current_user( self::$administrator );
498+
$request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' );
499+
$request->set_param( 'url', 'https://www.youtube.com/watch?v=' . self::YOUTUBE_VIDEO_ID );
500+
$request->set_param( '_wpnonce', wp_create_nonce( 'wp_rest' ) );
488501
$response = $this->server->dispatch( $request );
489502
$this->assertEquals( 1, $this->request_count );
490503

0 commit comments

Comments
 (0)