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

debug logging to the Proxy #365

Merged
merged 1 commit into from
Aug 22, 2024
Merged
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
39 changes: 31 additions & 8 deletions lib/Controller/ExAppProxyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OCP\Http\Client\IResponse;
use OCP\IGroupManager;
use OCP\IRequest;
use Psr\Log\LoggerInterface;

class ExAppProxyController extends Controller {

Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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) {
Expand Down
Loading