Skip to content

Commit e7b5c5c

Browse files
authored
Merge pull request #5372 from nextcloud/we-shall-monkey-patch-auth-headers-for-clients-that-dont-follow-specs
Prevent sending second WWW-Authenticate header
2 parents eafaa2f + 6333960 commit e7b5c5c

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

apps/dav/lib/Connector/Sabre/BearerAuth.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
use OCP\ISession;
2626
use OCP\IUserSession;
2727
use Sabre\DAV\Auth\Backend\AbstractBearer;
28+
use Sabre\HTTP\RequestInterface;
29+
use Sabre\HTTP\ResponseInterface;
2830

2931
class BearerAuth extends AbstractBearer {
3032
/** @var IUserSession */
@@ -77,4 +79,16 @@ public function validateBearerToken($bearerToken) {
7779

7880
return false;
7981
}
82+
83+
/**
84+
* \Sabre\DAV\Auth\Backend\AbstractBearer::challenge sets an WWW-Authenticate
85+
* header which some DAV clients can't handle. Thus we override this function
86+
* and make it simply return a 401.
87+
*
88+
* @param RequestInterface $request
89+
* @param ResponseInterface $response
90+
*/
91+
public function challenge(RequestInterface $request, ResponseInterface $response) {
92+
$response->setStatus(401);
93+
}
8094
}

apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222
namespace OCA\DAV\Tests\unit\Connector\Sabre;
2323

24-
use OC\Authentication\TwoFactorAuth\Manager;
25-
use OC\Security\Bruteforce\Throttler;
26-
use OC\User\Session;
2724
use OCA\DAV\Connector\Sabre\BearerAuth;
2825
use OCP\IRequest;
2926
use OCP\ISession;
@@ -85,4 +82,13 @@ public function testValidateBearerToken() {
8582

8683
$this->assertSame('principals/users/admin', $this->bearerAuth->validateBearerToken('Token'));
8784
}
85+
86+
public function testChallenge() {
87+
/** @var \PHPUnit_Framework_MockObject_MockObject|RequestInterface $request */
88+
$request = $this->createMock(RequestInterface::class);
89+
/** @var \PHPUnit_Framework_MockObject_MockObject|ResponseInterface $response */
90+
$response = $this->createMock(ResponseInterface::class);
91+
$result = $this->bearerAuth->challenge($request, $response);
92+
$this->assertEmpty($result);
93+
}
8894
}

build/integration/features/webdav-related.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ Feature: webdav-related
88
Then the HTTP status code should be "401"
99
And there are no duplicate headers
1010
And The following headers should be set
11-
|WWW-Authenticate|Basic realm="Nextcloud", Bearer realm="Nextcloud"|
11+
|WWW-Authenticate|Basic realm="Nextcloud"|
1212

1313
Scenario: Unauthenticated call new dav path
1414
Given using new dav path
1515
When connecting to dav endpoint
1616
Then the HTTP status code should be "401"
1717
And there are no duplicate headers
1818
And The following headers should be set
19-
|WWW-Authenticate|Bearer realm="Nextcloud", Basic realm="Nextcloud"|
19+
|WWW-Authenticate|Basic realm="Nextcloud"|
2020

2121
Scenario: Moving a file
2222
Given using old dav path

0 commit comments

Comments
 (0)