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
13 changes: 9 additions & 4 deletions matomo-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@
$filerequest = isset($_POST['file']) ? $_POST['file'] : null;
}

if (
!(isset($filerequest) && in_array($filerequest, $VALID_FILES))
&& !(isset($module) && isset($action) && in_array("$module.$action", $SUPPORTED_METHODS))
) {
$hasFileRequest = !empty($filerequest);
$hasSupportedMethod = !empty($module) && !empty($action) && in_array("$module.$action", $SUPPORTED_METHODS, true);

if ($hasFileRequest) {
if (!in_array($filerequest, $VALID_FILES, true)) {
http_response_code(404);
exit;
}
} elseif (!$hasSupportedMethod) {
http_response_code(404);
exit;
}
Expand Down
25 changes: 25 additions & 0 deletions tests/ProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,31 @@ public function test_indexphp_blocked_post_requests_are_not_proxied()
$this->assertEquals(404, $response->getStatusCode());
}

public function test_indexphp_requests_with_invalid_file_are_not_proxied_even_if_method_is_allowed()
{
$response = $this->send(
'module=CoreAdminHome&action=optOut&file=plugins/CoreAdminHome/javascripts/notAllowed.js',
null,
null,
null,
'/matomo-proxy.php'
);
$this->assertEquals(404, $response->getStatusCode());
}

public function test_indexphp_post_requests_with_invalid_file_are_not_proxied_even_if_method_is_allowed()
{
$response = $this->send(
'module=CoreAdminHome&action=optOut&file=plugins/CoreAdminHome/javascripts/notAllowed.js',
null,
null,
null,
'/matomo-proxy.php',
'POST'
);
$this->assertEquals(404, $response->getStatusCode());
}

public function test_indexphp_empty_requests_are_not_proxied()
{
$response = $this->send('', null, null, null, '/matomo-proxy.php');
Expand Down
Loading