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
8 changes: 8 additions & 0 deletions lib/Controller/ExAppProxyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ private function prepareProxy(
);
return null;
}
// As the ExApp may read it: cut at "?" or "#", decoded once, any case, surrounding slashes and newlines.
$target = rawurldecode(substr($other, 0, strcspn($other, '?#')));
if (in_array(strtolower(trim($target, "/\n")), ['heartbeat', 'init', 'enabled'], true)) {
$this->logger->debug(
sprintf('Returning status 404 for "%s": only AppAPI calls this ExApp endpoint.', $other)
);
return null;
}
$exApp = $this->exAppService->getExApp($appId);
if ($exApp === null) {
$this->logger->debug(
Expand Down
25 changes: 25 additions & 0 deletions tests/php/Controller/ExAppProxyControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,31 @@ public function testAccessDeniedDoesNotFallThroughToLaterRoutes(): void {
self::assertSame('^/.*', $this->routeFor('GET', 'other', $adminFirst, 'alice')['url']);
}

public static function internalEndpointProvider(): array {
return [
'heartbeat' => ['heartbeat'],
'init' => ['init'],
'enabled' => ['enabled'],
'trailing slash' => ['init/'],
'other case' => ['Enabled'],
'encoded leading slash' => ['%2Fheartbeat'],
'percent-encoded' => ['%65nabled'],
'followed by a decoded "?"' => ['enabled?enabled=0'],
'followed by a decoded "#"' => ['init#x'],
'followed by a newline' => ["heartbeat\n"],
];
}

#[DataProvider('internalEndpointProvider')]
public function testInternalEndpointIsRefused(string $path): void {
self::assertFalse($this->isForwarded($path));
}

public function testPathsNearInternalEndpointsAreForwarded(): void {
self::assertTrue($this->isForwarded('heartbeats'));
self::assertTrue($this->isForwarded('api/enabled'));
}

public function testHeadIsAcceptedWhereGetIs(): void {
// Nextcloud routes HEAD to the proxy's GET action, and HaRP accepts HEAD on GET routes too.
self::assertSame('GET', $this->routeFor('HEAD', 'settings', self::SAME_URL)['verb']);
Expand Down
Loading