Skip to content
Merged
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
5 changes: 5 additions & 0 deletions modules/xml-rpc/class-xml-rpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public static function disable_xml_rpc() {

// TODO: Figure how to disable XML-RPC without returning a value.
add_filter('wp_xmlrpc_server_class', function ( $server_class ) {
/**
* Filters the HTTP status code returned when XML-RPC is disabled.
*/
status_header( (int) apply_filters( 'vip_security_boost_xml_rpc_disabled_status_code', 403 ) );

exit( 'Access to XML-RPC is disabled on this site.' );
// phpcs:ignore Squiz.PHP.NonExecutableCode.Unreachable
return $server_class;
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/specs/generic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test.describe( 'Generic Checks', () => {
data: xmlPayload,
} );

expect( response.status() ).toBe( 200 );
expect( response.status() ).toBe( 403 );
const responseText = await response.text();
expect( responseText ).toContain( 'Access to XML-RPC is disabled on this site.' );
} );
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/XmlRpcTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public function testXmlRpcReturns403WhenDisabled(): void {
}

/**
* Test that accessing XML-RPC endpoint returns 200 OK when module is disabled.
* Test that accessing XML-RPC endpoint returns 403 Forbidden when module is disabled.
*
* @return void
*/
public function testXmlRpcReturns200WhenModuleDisabled(): void {
public function testXmlRpcReturns403WhenModuleDisabled(): void {
global $client;
$url = '/xmlrpc.php';

Expand All @@ -73,9 +73,9 @@ public function testXmlRpcReturns200WhenModuleDisabled(): void {
]);

$this->assertEquals(
200,
403,
$response->getStatusCode(),
"Expected HTTP status code 200 OK, but received {$response->getStatusCode()}."
"Expected HTTP status code 403 Forbidden, but received {$response->getStatusCode()}."
);
}

Expand Down
Loading