diff --git a/src/wp-includes/rest-api/class-wp-rest-server.php b/src/wp-includes/rest-api/class-wp-rest-server.php index d11318916e..acf23f4dda 100644 --- a/src/wp-includes/rest-api/class-wp-rest-server.php +++ b/src/wp-includes/rest-api/class-wp-rest-server.php @@ -1380,6 +1380,12 @@ class WP_REST_Server { foreach ( $server as $key => $value ) { if ( strpos( $key, 'HTTP_' ) === 0 ) { $headers[ substr( $key, 5 ) ] = $value; + } elseif ( 'REDIRECT_HTTP_AUTHORIZATION' === $key && empty( $server['HTTP_AUTHORIZATION'] ) ) { + /* + * In some server configurations, the authorization header is passed in this alternate location. + * Since it would not be passed in in both places we do not check for both headers and resolve. + */ + $headers['AUTHORIZATION'] = $value; } elseif ( isset( $additional[ $key ] ) ) { $headers[ $key ] = $value; } diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php index 4d450f7e17..abfdefcd0b 100644 --- a/tests/phpunit/tests/rest-api/rest-server.php +++ b/tests/phpunit/tests/rest-api/rest-server.php @@ -1373,6 +1373,64 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { $this->assertEquals( '', rest_get_server()->sent_body ); } + /** + * @ticket 47077 + */ + public function test_http_authorization_header_substitution() { + $headers = array( 'HTTP_AUTHORIZATION' => 'foo' ); + $parsed_headers = rest_get_server()->get_headers( $headers ); + + $this->assertSame( + array( 'AUTHORIZATION' => 'foo' ), + $parsed_headers + ); + } + + /** + * @ticket 47077 + */ + public function test_redirect_http_authorization_header_substitution() { + $headers = array( 'REDIRECT_HTTP_AUTHORIZATION' => 'foo' ); + $parsed_headers = rest_get_server()->get_headers( $headers ); + + $this->assertSame( + array( 'AUTHORIZATION' => 'foo' ), + $parsed_headers + ); + } + + /** + * @ticket 47077 + */ + public function test_redirect_http_authorization_with_http_authorization_header_substitution() { + $headers = array( + 'HTTP_AUTHORIZATION' => 'foo', + 'REDIRECT_HTTP_AUTHORIZATION' => 'bar', + ); + $parsed_headers = rest_get_server()->get_headers( $headers ); + + $this->assertSame( + array( 'AUTHORIZATION' => 'foo' ), + $parsed_headers + ); + } + + /** + * @ticket 47077 + */ + public function test_redirect_http_authorization_with_empty_http_authorization_header_substitution() { + $headers = array( + 'HTTP_AUTHORIZATION' => '', + 'REDIRECT_HTTP_AUTHORIZATION' => 'bar', + ); + $parsed_headers = rest_get_server()->get_headers( $headers ); + + $this->assertSame( + array( 'AUTHORIZATION' => 'bar' ), + $parsed_headers + ); + } + public function _validate_as_integer_123( $value, $request, $key ) { if ( ! is_int( $value ) ) { return new WP_Error( 'some-error', 'This is not valid!' );