Skip to content

Commit 024ed97

Browse files
authored
Merge pull request #26945 from nextcloud/enh/shareinfo/throttle
Add bruteforce protection to the shareinfo endpoint
2 parents 0599a80 + 7012945 commit 024ed97

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

apps/files_sharing/lib/Controller/ShareInfoController.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ShareInfoController extends ApiController {
4848
* @param IRequest $request
4949
* @param IManager $shareManager
5050
*/
51-
public function __construct($appName,
51+
public function __construct(string $appName,
5252
IRequest $request,
5353
IManager $shareManager) {
5454
parent::__construct($appName, $request);
@@ -59,26 +59,32 @@ public function __construct($appName,
5959
/**
6060
* @PublicPage
6161
* @NoCSRFRequired
62+
* @BruteForceProtection(action=shareinfo)
6263
*
6364
* @param string $t
6465
* @param null $password
6566
* @param null $dir
6667
* @return JSONResponse
67-
* @throws ShareNotFound
6868
*/
6969
public function info($t, $password = null, $dir = null) {
7070
try {
7171
$share = $this->shareManager->getShareByToken($t);
7272
} catch (ShareNotFound $e) {
73-
return new JSONResponse([], Http::STATUS_NOT_FOUND);
73+
$response = new JSONResponse([], Http::STATUS_NOT_FOUND);
74+
$response->throttle(['token' => $t]);
75+
return $response;
7476
}
7577

7678
if ($share->getPassword() && !$this->shareManager->checkPassword($share, $password)) {
77-
return new JSONResponse([], Http::STATUS_FORBIDDEN);
79+
$response = new JSONResponse([], Http::STATUS_FORBIDDEN);
80+
$response->throttle(['token' => $t]);
81+
return $response;
7882
}
7983

8084
if (!($share->getPermissions() & Constants::PERMISSION_READ)) {
81-
return new JSONResponse([], Http::STATUS_FORBIDDEN);
85+
$response = new JSONResponse([], Http::STATUS_FORBIDDEN);
86+
$response->throttle(['token' => $t]);
87+
return $response;
8288
}
8389

8490
$permissionMask = $share->getPermissions();

apps/files_sharing/tests/Controller/ShareInfoControllerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function testNoShare() {
6666
->willThrowException(new ShareNotFound());
6767

6868
$expected = new JSONResponse([], Http::STATUS_NOT_FOUND);
69+
$expected->throttle(['token' => 'token']);
6970
$this->assertEquals($expected, $this->controller->info('token'));
7071
}
7172

@@ -82,6 +83,7 @@ public function testWrongPassword() {
8283
->willReturn(false);
8384

8485
$expected = new JSONResponse([], Http::STATUS_FORBIDDEN);
86+
$expected->throttle(['token' => 'token']);
8587
$this->assertEquals($expected, $this->controller->info('token', 'pass'));
8688
}
8789

@@ -100,6 +102,7 @@ public function testNoReadPermissions() {
100102
->willReturn(true);
101103

102104
$expected = new JSONResponse([], Http::STATUS_FORBIDDEN);
105+
$expected->throttle(['token' => 'token']);
103106
$this->assertEquals($expected, $this->controller->info('token', 'pass'));
104107
}
105108

0 commit comments

Comments
 (0)