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

fix error when using CORS with no auth credentials #26852

Merged
merged 1 commit into from
May 19, 2021

Conversation

korelstar
Copy link
Member

When using an ApiController with CORS annotation, basic authentication is required. However, currently the following exception occurs when a request does not contain any authentication:

Argument 1 passed to OCP\User\Events\BeforeUserLoggedInEvent::__construct() must be of the type string, null given, called in /home/owncloud/nextcloud/lib/private/Server.php on line 577

0.  /home/owncloud/nextcloud/lib/private/Server.php - line 577:
    OCP\User\Events\BeforeUserLoggedInEvent->__construct("*** sensiti ... *", "*** sensiti ... *")

1.  <<closure>>
    OC\Server->OC\{closure}("*** sensiti ... *")

2.  /home/owncloud/nextcloud/lib/private/Hooks/EmitterTrait.php - line 107:
    call_user_func_array(Closure {}, [ "*** sensi ... "])

3.  /home/owncloud/nextcloud/lib/private/Hooks/PublicEmitter.php - line 41:
    OC\Hooks\BasicEmitter->emit("\\OC\\User", "preLogin", [ "*** sensi ... "])

4.  /home/owncloud/nextcloud/lib/private/User/Session.php - line 444:
    OC\Hooks\PublicEmitter->emit("\\OC\\User", "preLogin", [ "*** sensi ... "])

5.  /home/owncloud/nextcloud/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php - line 93:
    OC\User\Session->logClientIn("*** sensiti ... *")

6.  /home/owncloud/nextcloud/lib/private/AppFramework/Middleware/MiddlewareDispatcher.php - line 98:
    OC\AppFramework\Middleware\Security\CORSMiddleware->beforeController(OCA\Notes\Co ... {}, "index")

7.  /home/owncloud/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 119:
    OC\AppFramework\Middleware\MiddlewareDispatcher->beforeController(OCA\Notes\Co ... {}, "index")

8.  /home/owncloud/nextcloud/lib/private/AppFramework/App.php - line 157:
    OC\AppFramework\Http\Dispatcher->dispatch(OCA\Notes\Co ... {}, "index")

9.  /home/owncloud/nextcloud/lib/private/Route/Router.php - line 302:
    OC\AppFramework\App::main("OCA\\Notes\ ... r", "index", OC\AppFramew ... {}, { apiVersion ... "})

10. /home/owncloud/nextcloud/lib/base.php - line 993:
    OC\Route\Router->match("/apps/notes/api/v1/notes")

11. /home/owncloud/nextcloud/index.php - line 37:
    OC::handleRequest()

In consultation with @nickvergessen , this PR fixes this by checking if $user and $pass are not null before trying to login.

Furthermore, I fixed an Undefined index error for PHP_AUTH_USER and PHP_AUTH_PW.

I suggest backporting this to the stable branches.

@gary-kim gary-kim added 3. to review Waiting for reviews bug labels May 1, 2021
@nickvergessen nickvergessen requested a review from kesselb May 3, 2021 08:00
@korelstar
Copy link
Member Author

ping for review @rullzer @ChristophWurst @LukasReschke @kesselb

@LukasReschke LukasReschke added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels May 18, 2021
@korelstar korelstar added this to the Nextcloud 22 milestone May 18, 2021
@nickvergessen nickvergessen merged commit 4a02726 into master May 19, 2021
@nickvergessen nickvergessen deleted the fix-noauth-cors branch May 19, 2021 07:51
@korelstar
Copy link
Member Author

I suggest to Backport this to stable20 and stable21. Can we do this?

@nickvergessen
Copy link
Member

/backport to stable21

@nickvergessen
Copy link
Member

/backport to stable20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants