Skip to content
Open
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
11 changes: 11 additions & 0 deletions __tests__/unit-tests/test-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ public function test_run_event() {
$this->assertArrayHasKey( 'message', $data );
}

public function test_array_secret_is_rejected() {
$request = new WP_REST_Request( 'POST', '/' . REST_API::API_NAMESPACE . '/' . REST_API::ENDPOINT_LIST );
$request->set_body( wp_json_encode( [ 'secret' => [] ] ) );
$request->set_header( 'content-type', 'application/json' );

$response = $this->server->dispatch( $request );

$this->assertResponseStatus( 400, $response );
$this->assertEquals( 'no-secret', $response->get_data()['code'] );
}

/**
* Check response code
*
Expand Down
2 changes: 1 addition & 1 deletion includes/class-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function check_secret( $request ) {
$body = $request->get_json_params();

// For now, mimic original plugin's "authentication" method. This needs to be better.
if ( ! isset( $body['secret'] ) || ! hash_equals( \WP_CRON_CONTROL_SECRET, $body['secret'] ) ) {
if ( ! isset( $body['secret'] ) || ! is_string( \WP_CRON_CONTROL_SECRET ) || ! is_string( $body['secret'] ) || ! hash_equals( \WP_CRON_CONTROL_SECRET, $body['secret'] ) ) {
return new \WP_Error(
'no-secret',
__( 'Secret must be specified with all requests', 'automattic-cron-control' ),
Expand Down
Loading