Skip to content

Commit 5ef74e2

Browse files
authored
Merge pull request #13362 from nextcloud/backport/13354/master
[master] check anonymous OPTIONS requests file in root (not in subdir)
2 parents 14fcc64 + 4535cc5 commit 5ef74e2

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,19 @@ public function initialize(\Sabre\DAV\Server $server) {
4545
$this->server->on('beforeMethod', [$this, 'handleAnonymousOptions'], 9);
4646
}
4747

48+
/**
49+
* @return bool
50+
*/
51+
public function isRequestInRoot($path) {
52+
return $path === '' || (is_string($path) && strpos($path, '/') === FALSE);
53+
}
54+
4855
/**
4956
* @throws \Sabre\DAV\Exception\Forbidden
5057
* @return bool
5158
*/
5259
public function handleAnonymousOptions(RequestInterface $request, ResponseInterface $response) {
53-
if ($request->getHeader('Authorization') === null && $request->getMethod() === 'OPTIONS') {
60+
if ($request->getHeader('Authorization') === null && $request->getMethod() === 'OPTIONS' && $this->isRequestInRoot($request->getPath())) {
5461
/** @var CorePlugin $corePlugin */
5562
$corePlugin = $this->server->getPlugin('core');
5663
// setup a fake tree for anonymous access

apps/dav/tests/unit/DAV/AnonymousOptionsTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ public function testAnonymousOptionsNonRoot() {
5656

5757
$this->assertEquals(200, $response->getStatus());
5858
}
59+
60+
public function testAnonymousOptionsNonRootSubDir() {
61+
$response = $this->sendRequest('OPTIONS', 'foo/bar');
62+
63+
$this->assertEquals(401, $response->getStatus());
64+
}
5965
}
6066

6167
class SapiMock extends Sapi {

0 commit comments

Comments
 (0)