marius-wieschollek / passwords

A simple, yet feature rich password manager for Nextcloud
GNU Affero General Public License v3.0
208 stars 42 forks source link

[BUG]: Failed to access Password site after update to Nextcloud 25.0.9 #601

Closed igh-ab closed 1 year ago

igh-ab commented 1 year ago

⚠️ This issue respects the following points: ⚠️

Server Information

{"reqId":"jSuE59w7NaTmaX3LN2Vy","level":4,"time":"2023-07-31T12:11:36+02:00","remoteAddr":"","user":"--","app":"passwords","method":"","url":"--","message":"Error during app service registration: syntax error, unexpected 'protected' (T_PROTECTED), expecting variable (T_VARIABLE)","userAgent":"--","version":"25.0.9.2","exception":{"Exception":"ParseError","Message":"syntax error, unexpected 'protected' (T_PROTECTED), expecting variable (T_VARIABLE)","Code":0,"Trace":[{"file":"/var/www/html/nextcloud/lib/composer/composer/ClassLoader.php","line":571,"function":"include"},{"file":"/var/www/html/nextcloud/lib/composer/composer/ClassLoader.php","line":428,"function":"Composer\\Autoload\\includeFile"},{"function":"loadClass","class":"Composer\\Autoload\\ClassLoader","type":"->"},{"function":"spl_autoload_call"},{"file":"/var/www/html/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php","line":126,"function":"class_exists"},{"file":"/var/www/html/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php","line":91,"function":"registerApps","class":"OC\\AppFramework\\Bootstrap\\Coordinator","type":"->"},{"file":"/var/www/html/nextcloud/lib/base.php","line":676,"function":"runInitialRegistration","class":"OC\\AppFramework\\Bootstrap\\Coordinator","type":"->"},{"file":"/var/www/html/nextcloud/lib/base.php","line":1150,"function":"init","class":"OC","type":"::"},{"file":"/var/www/html/nextcloud/console.php","line":48,"args":["/var/www/html/nextcloud/lib/base.php"],"function":"require_once"},{"file":"/var/www/html/nextcloud/occ","line":11,"args":["/var/www/html/nextcloud/console.php"],"function":"require_once"}],"File":"/var/www/html/nextcloud/apps/passwords/lib/.overrides/nc25/Middleware/ApiSessionMiddleware.php","Line":38,"message":"Error during app service registration: syntax error, unexpected 'protected' (T_PROTECTED), expecting variable (T_VARIABLE)","exception":{},"CustomMessage":"Error during app service registration: syntax error, unexpected 'protected' (T_PROTECTED), expecting variable (T_VARIABLE)"}}
{
    "version": {
        "server": "25.0.9.2",
        "app": "2023.8.10",
        "lsr": true,
        "php": "7.4.33",
        "cronPhp": "7.4.33"
    },
    "environment": {
        "os": "Linux",
        "architecture": "x86_64",
        "bits": 64,
        "database": "mysql",
        "cron": "cron",
        "proxy": false,
        "sslProxy": false,
        "subdirectory": false
    },
    "services": {
        "images": "imagick",
        "favicons": "default",
        "previews": "default",
        "security": "hibp",
        "words": "auto",
        "previewApi": false,
        "faviconApi": false
    },
    "status": {
        "autoBackupRestored": false
    },
    "settings": {
        "channel": "stable",
        "nightlies": false,
        "handbook": false,
        "performance": 5
    },
    "encryption": {
        "sse": {
            "SSEv1r1": false,
            "SSEv1r2": true,
            "SSEv2r1": false,
            "SSEv3r1": false,
            "none": true,
            "default": "none"
        },
        "cse": {
            "CSEv1r1": true,
            "none": true,
            "default": "CSEv1r1"
        }
    }
}

Client Information

Browser and Version: Firefox 102.13.0esr Client OS and Version: Debian Bulseye x86 64-Bit

Bug description

Try to acces the password site inside nextcloud causes a server error 500.

Updating the db indeces after update failes with an failure, too.

Seem to be an app registration problem.

Error Message:

php ./occ db:add-missing-indices {"reqId":"jvOxAlX01ulSMkBNzWhB","level":4,"time":"2023-07-31T11:57:46+02:00","remoteAddr":"","user":"--","app":"passwords","method":"","url":"--","message":"Error during app service registration: syntax error, unexpected 'protected' (T_PROTECTED), expecting variable (T_VARIABLE)","userAgent":"--","version":"25.0.9.2","exception":{"Exception":"ParseError","Message":"syntax error, unexpected 'protected' (T_PROTECTED), expecting variable (T_VARIABLE)","Code":0,"Trace":[{"file":"/var/www/html/nextcloud/lib/composer/composer/ClassLoader.php","line":571,"function":"include"},{"file":"/var/www/html/nextcloud/lib/composer/composer/ClassLoader.php","line":428,"function":"Composer\Autoload\includeFile"},{"function":"loadClass","class":"Composer\Autoload\ClassLoader","type":"->"},{"function":"spl_autoload_call"},{"file":"/var/www/html/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php","line":126,"function":"class_exists"},{"file":"/var/www/html/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php","line":91,"function":"registerApps","class":"OC\AppFramework\Bootstrap\Coordinator","type":"->"},{"file":"/var/www/html/nextcloud/lib/base.php","line":676,"function":"runInitialRegistration","class":"OC\AppFramework\Bootstrap\Coordinator","type":"->"},{"file":"/var/www/html/nextcloud/lib/base.php","line":1150,"function":"init","class":"OC","type":"::"},{"file":"/var/www/html/nextcloud/console.php","line":48,"args":["/var/www/html/nextcloud/lib/base.php"],"function":"require_once"},{"file":"/var/www/html/nextcloud/occ","line":11,"args":["/var/www/html/nextcloud/console.php"],"function":"require_once"}],"File":"/var/www/html/nextcloud/apps/passwords/lib/.overrides/nc25/Middleware/ApiSessionMiddleware.php","Line":38,"message":"Error during app service registration: syntax error, unexpected 'protected' (T_PROTECTED), expecting variable (T_VARIABLE)","exception":{},"CustomMessage":"Error during app service registration: syntax error, unexpected 'protected' (T_PROTECTED), expecting variable (T_VARIABLE)"}} Check indices of the share table. Check indices of the filecache table. Check indices of the twofactor_providers table. Check indices of the login_flow_v2 table. Check indices of the whats_new table. Check indices of the cards table. Check indices of the cards_properties table. Check indices of the calendarobjects_props table. Check indices of the schedulingobjects table. Check indices of the oc_properties table. Check indices of the oc_jobs table. Check indices of the oc_direct_edit table. Check indices of the oc_preferences table. Check indices of the oc_mounts table. Check indices of the oc_systemtag_object_mapping table. Done.

Steps to reproduce

  1. Try to ccess the password site

Expected behavior

The passord request site should be presentted

Nextcloud Logs

No response

Browser Logs

No response

marius-wieschollek commented 1 year ago

This seems to be an issue with the PHP 7.4 backwards compatibility.

Can you try applying this patch:

Subject: [PATCH] [#601] PHP Language Level Fix
---
Index: src/lib/.overrides/nc25/Middleware/ApiSessionMiddleware.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/lib/.overrides/nc25/Middleware/ApiSessionMiddleware.php b/src/lib/.overrides/nc25/Middleware/ApiSessionMiddleware.php
--- a/src/lib/.overrides/nc25/Middleware/ApiSessionMiddleware.php   (revision 715935b9bd90636415b3b68066fc21faa38fbdc2)
+++ b/src/lib/.overrides/nc25/Middleware/ApiSessionMiddleware.php   (date 1690821462113)
@@ -28,16 +28,24 @@
  */
 class ApiSessionMiddleware extends Middleware {

+    /**
+     * @var SessionService
+     */
+    protected SessionService $sessionService;
+    /**
+     * @var UserChallengeService
+     */
+    protected UserChallengeService $challengeService;
     /**
      * ApiSessionMiddleware constructor.
      *
      * @param SessionService       $sessionService
      * @param UserChallengeService $challengeService
      */
-    public function __construct(
-        protected SessionService $sessionService,
-        protected UserChallengeService $challengeService
-    ) {
+    public function __construct(SessionService $sessionService, UserChallengeService $challengeService)
+    {
+        $this->sessionService = $sessionService;
+        $this->challengeService = $challengeService;
     }

     /**

Or just simply replace the contents of the file lib/.overrides/nc25/Middleware/ApiSessionMiddleware.php in the folder of the passwords app with this:

<?php
/*
 * @copyright 2023 Passwords App
 *
 * @author Marius David Wieschollek
 * @license AGPL-3.0
 *
 * This file is part of the Passwords App
 * created by Marius David Wieschollek.
 */

namespace OCA\Passwords\Middleware;

use OCA\Passwords\Controller\Api\ServiceApiController;
use OCA\Passwords\Controller\Api\SessionApiController;
use OCA\Passwords\Controller\Api\SettingsApiController;
use OCA\Passwords\Exception\ApiException;
use OCA\Passwords\Services\SessionService;
use OCA\Passwords\Services\UserChallengeService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware;

/**
 * @TODO remove in 2024.1.0
 */
class ApiSessionMiddleware extends Middleware {

    /**
     * @var SessionService
     */
    protected SessionService $sessionService;
    /**
     * @var UserChallengeService
     */
    protected UserChallengeService $challengeService;
    /**
     * ApiSessionMiddleware constructor.
     *
     * @param SessionService       $sessionService
     * @param UserChallengeService $challengeService
     */
    public function __construct(SessionService $sessionService, UserChallengeService $challengeService)
    {
        $this->sessionService = $sessionService;
        $this->challengeService = $challengeService;
    }

    /**
     * @param Controller $controller
     * @param string     $methodName
     *
     * @throws ApiException
     */
    public function beforeController($controller, $methodName): void {
        if(!$this->isApiRequest($controller)) return;

        $this->sessionService->load();
        if(!$this->sessionService->isAuthorized() && $this->requiresAuthorization($controller, $methodName)) {
            throw new ApiException('Authorized session required', Http::STATUS_PRECONDITION_FAILED);
        }

        parent::beforeController($controller, $methodName);
    }

    /**
     * @param Controller $controller
     * @param string     $methodName
     * @param Response   $response
     *
     * @return Response
     */
    public function afterController($controller, $methodName, Response $response): Response {
        if(!$this->isApiRequest($controller) || $response instanceof FileDisplayResponse) return $response;

        $this->sessionService->save();
        $sessionId = $this->sessionService->getEncryptedId();
        if($sessionId) {
            $response->addHeader(SessionService::API_SESSION_HEADER, $sessionId);
            $response->addCookie(SessionService::API_SESSION_COOKIE, $sessionId);
        }

        return parent::afterController($controller, $methodName, $response);
    }

    /**
     * @param Controller $controller
     *
     * @return bool
     */
    protected function isApiRequest(Controller $controller): bool {
        $class = get_class($controller);

        return substr($class, 0, 28) === 'OCA\Passwords\Controller\Api';
    }

    /**
     * @param Controller $controller
     * @param string     $method
     *
     * @return bool
     */
    protected function requiresAuthorization(Controller $controller, string $method): bool {

        if(!$this->challengeService->hasChallenge()) {
            return false;
        }

        if($controller instanceof SessionApiController && in_array($method, ['open', 'request', 'requestToken', 'keepAlive'])) {
            return false;
        }

        if($controller instanceof ServiceApiController && in_array($method, ['getAvatar', 'getFavicon', 'getPreview'])) {
            return false;
        }

        if($controller instanceof SettingsApiController && in_array($method, ['get', 'list'])) {
            return false;
        }

        return true;
    }
}
igh-ab commented 1 year ago

The patch works. Thanks a lot for the fast feedback.