diff options
author | korelstar <korelstar@users.noreply.github.com> | 2021-06-24 01:05:12 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-24 01:05:12 +0300 |
commit | c466d2ecd4cff1069ebc2eaf2be4be3255b1e71a (patch) | |
tree | 277d78f33899df860ae4860d905d336c805228ed | |
parent | 6a40ed4765a98164b58905134402e038821a54dd (diff) | |
parent | 7b8d4b2d3796c4daf3549946bc276d96511b7a4b (diff) |
Merge pull request #27028 from nextcloud/backport/26852/stable21
[stable21] fix error when using CORS with no auth credentials
-rw-r--r-- | lib/private/AppFramework/Middleware/Security/CORSMiddleware.php | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php b/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php index 765311858de..392259fd20f 100644 --- a/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php @@ -83,14 +83,13 @@ class CORSMiddleware extends Middleware { public function beforeController($controller, $methodName) { // ensure that @CORS annotated API routes are not used in conjunction // with session authentication since this enables CSRF attack vectors - if ($this->reflector->hasAnnotation('CORS') && - !$this->reflector->hasAnnotation('PublicPage')) { - $user = $this->request->server['PHP_AUTH_USER']; - $pass = $this->request->server['PHP_AUTH_PW']; + if ($this->reflector->hasAnnotation('CORS') && !$this->reflector->hasAnnotation('PublicPage')) { + $user = array_key_exists('PHP_AUTH_USER', $this->request->server) ? $this->request->server['PHP_AUTH_USER'] : null; + $pass = array_key_exists('PHP_AUTH_PW', $this->request->server) ? $this->request->server['PHP_AUTH_PW'] : null; $this->session->logout(); try { - if (!$this->session->logClientIn($user, $pass, $this->request, $this->throttler)) { + if ($user === null || $pass === null || !$this->session->logClientIn($user, $pass, $this->request, $this->throttler)) { throw new SecurityException('CORS requires basic auth', Http::STATUS_UNAUTHORIZED); } } catch (PasswordLoginForbiddenException $ex) { |