Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent usage of cloudflare_proxy action on /admin-ajax endpoint for non-Administrator users #529

Merged
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 src/Integration/IntegrationAPIInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ public function getDomainList($userId = null);
* @return mixed
*/
public function getUserId();

/**
* @return boolean
*/
public function isCurrentUserAdministrator();
}
1 change: 1 addition & 0 deletions src/Test/WordPress/HooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function testPluginActionLinksGetAdminUrl()

public function testInitProxyCallsProxyRun()
{
$this->mockWordPressAPI->method('isCurrentUserAdministrator')->willReturn(true);
$this->mockProxy->expects($this->once())->method('run');
$this->hooks->initProxy();
}
Expand Down
2 changes: 2 additions & 0 deletions src/Test/WordPress/ProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function testRunHandlesGet()
$_SERVER['REQUEST_METHOD'] = 'GET';
$_GET['proxyURL'] = 'proxyUrl';
$_GET['proxyURLType'] = 'proxyUrlType';
$this->mockWordPressAPI->method('isCurrentUserAdministrator')->willReturn(true);
$this->mockRequestRouter->expects($this->once())->method('route');
$mockWPDie = $this->getFunctionMock('CF\WordPress', 'wp_die');
$this->mockProxy->run();
Expand All @@ -72,6 +73,7 @@ public function testRunHandlesPost()
$mockFileGetContents->expects($this->any())->willReturn($jsonBody);
$mockWPVerifyNonce = $this->getFunctionMock('CF\WordPress', 'wp_verify_nonce');
$mockWPVerifyNonce->expects($this->once())->willReturn(true);
$this->mockWordPressAPI->method('isCurrentUserAdministrator')->willReturn(true);
$this->mockRequestRouter->expects($this->once())->method('route');
$mockWPDie = $this->getFunctionMock('CF\WordPress', 'wp_die');
$this->mockProxy->run();
Expand Down
4 changes: 4 additions & 0 deletions src/WordPress/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public function setRequestRouter(RequestRouter $requestRouter)

public function run()
{
if (!$this->wordpressAPI->isCurrentUserAdministrator()) {
return;
}

header('Content-Type: application/json');

$request = $this->createRequest();
Expand Down
8 changes: 8 additions & 0 deletions src/WordPress/WordPressAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,12 @@ public function checkIfValidCloudflareSubdomain($response, $domainName)

return false;
}

/**
* @return boolean
*/
public function isCurrentUserAdministrator()
{
return $this->wordPressWrapper->currentUserCan('administrator');
}
}
5 changes: 5 additions & 0 deletions src/WordPress/WordPressWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ public function getSiteURL()

return strtolower($site_url);
}

public function currentUserCan($capabilities)
{
return current_user_can($capabilities);
}
}
Loading