Skip to content

Commit c466d2e

Browse files
authored
Merge pull request #27028 from nextcloud/backport/26852/stable21
[stable21] fix error when using CORS with no auth credentials
2 parents 6a40ed4 + 7b8d4b2 commit c466d2e

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

lib/private/AppFramework/Middleware/Security/CORSMiddleware.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,13 @@ public function __construct(IRequest $request,
8383
public function beforeController($controller, $methodName) {
8484
// ensure that @CORS annotated API routes are not used in conjunction
8585
// with session authentication since this enables CSRF attack vectors
86-
if ($this->reflector->hasAnnotation('CORS') &&
87-
!$this->reflector->hasAnnotation('PublicPage')) {
88-
$user = $this->request->server['PHP_AUTH_USER'];
89-
$pass = $this->request->server['PHP_AUTH_PW'];
86+
if ($this->reflector->hasAnnotation('CORS') && !$this->reflector->hasAnnotation('PublicPage')) {
87+
$user = array_key_exists('PHP_AUTH_USER', $this->request->server) ? $this->request->server['PHP_AUTH_USER'] : null;
88+
$pass = array_key_exists('PHP_AUTH_PW', $this->request->server) ? $this->request->server['PHP_AUTH_PW'] : null;
9089

9190
$this->session->logout();
9291
try {
93-
if (!$this->session->logClientIn($user, $pass, $this->request, $this->throttler)) {
92+
if ($user === null || $pass === null || !$this->session->logClientIn($user, $pass, $this->request, $this->throttler)) {
9493
throw new SecurityException('CORS requires basic auth', Http::STATUS_UNAUTHORIZED);
9594
}
9695
} catch (PasswordLoginForbiddenException $ex) {

0 commit comments

Comments
 (0)