From c2820e676118931c025b352f7c3bbcc35c700fe3 Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:17:58 +0300 Subject: [PATCH] added debug logging to the Proxy Signed-off-by: Alexander Piskun --- lib/Controller/ExAppProxyController.php | 39 ++++++++++++++++++++----- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/Controller/ExAppProxyController.php b/lib/Controller/ExAppProxyController.php index 6aceda99..23646f4d 100644 --- a/lib/Controller/ExAppProxyController.php +++ b/lib/Controller/ExAppProxyController.php @@ -24,6 +24,7 @@ use OCP\Http\Client\IResponse; use OCP\IGroupManager; use OCP\IRequest; +use Psr\Log\LoggerInterface; class ExAppProxyController extends Controller { @@ -35,6 +36,7 @@ public function __construct( private readonly ContentSecurityPolicyNonceManager $nonceManager, private readonly ?string $userId, private readonly IGroupManager $groupManager, + private readonly LoggerInterface $logger, ) { parent::__construct(Application::APP_ID, $request); } @@ -82,8 +84,8 @@ private function createProxyResponse(string $path, IResponse $response, $cache = #[NoAdminRequired] #[NoCSRFRequired] public function ExAppGet(string $appId, string $other): Response { - $exApp = $this->exAppService->getExApp($appId); - if ($exApp === null || !$exApp->getEnabled() || !$this->passesExAppProxyRoutesChecks($exApp, $other)) { + $exApp = $this->checkAccess($appId, $other); + if ($exApp === null) { return new NotFoundResponse(); } @@ -105,8 +107,8 @@ public function ExAppGet(string $appId, string $other): Response { #[NoAdminRequired] #[NoCSRFRequired] public function ExAppPost(string $appId, string $other): Response { - $exApp = $this->exAppService->getExApp($appId); - if ($exApp === null || !$exApp->getEnabled() || !$this->passesExAppProxyRoutesChecks($exApp, $other)) { + $exApp = $this->checkAccess($appId, $other); + if ($exApp === null) { return new NotFoundResponse(); } @@ -141,8 +143,8 @@ public function ExAppPost(string $appId, string $other): Response { #[NoAdminRequired] #[NoCSRFRequired] public function ExAppPut(string $appId, string $other): Response { - $exApp = $this->exAppService->getExApp($appId); - if ($exApp === null || !$exApp->getEnabled() || !$this->passesExAppProxyRoutesChecks($exApp, $other)) { + $exApp = $this->checkAccess($appId, $other); + if ($exApp === null) { return new NotFoundResponse(); } @@ -168,8 +170,8 @@ public function ExAppPut(string $appId, string $other): Response { #[NoAdminRequired] #[NoCSRFRequired] public function ExAppDelete(string $appId, string $other): Response { - $exApp = $this->exAppService->getExApp($appId); - if ($exApp === null || !$exApp->getEnabled() || !$this->passesExAppProxyRoutesChecks($exApp, $other)) { + $exApp = $this->checkAccess($appId, $other); + if ($exApp === null) { return new NotFoundResponse(); } @@ -191,6 +193,27 @@ public function ExAppDelete(string $appId, string $other): Response { return $this->createProxyResponse($other, $response); } + private function checkAccess(string $appId, string $other): ?ExApp { + $exApp = $this->exAppService->getExApp($appId); + if ($exApp === null) { + $this->logger->debug( + sprintf('Returning status 404 for "%s": ExApp is not found.', $other) + ); + return null; + } elseif (!$exApp->getEnabled()) { + $this->logger->debug( + sprintf('Returning status 404 for "%s": ExApp is not enabled.', $other) + ); + return null; + } elseif (!$this->passesExAppProxyRoutesChecks($exApp, $other)) { + $this->logger->debug( + sprintf('Returning status 404 for "%s": route does not pass the access check.', $other) + ); + return null; + } + return $exApp; + } + private function buildProxyCookiesJar(array $cookies, string $domain): CookieJar { $cookieJar = new CookieJar(); foreach ($cookies as $name => $value) {