Skip to content

Commit a8d144a

Browse files
authored
Merge pull request #27014 from nextcloud/backport/27000/stable20
[stable20] Harden apptoken check
2 parents 99788d3 + 998bcd9 commit a8d144a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

apps/settings/lib/Controller/AuthSettingsController.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ public function __construct(string $appName,
121121
* @return JSONResponse
122122
*/
123123
public function create($name) {
124+
if ($this->checkAppToken()) {
125+
return $this->getServiceNotAvailableResponse();
126+
}
127+
124128
try {
125129
$sessionId = $this->session->getId();
126130
} catch (SessionNotAvailableException $ex) {
@@ -181,6 +185,10 @@ private function generateRandomDeviceToken() {
181185
return implode('-', $groups);
182186
}
183187

188+
private function checkAppToken(): bool {
189+
return $this->session->exists('app_password');
190+
}
191+
184192
/**
185193
* @NoAdminRequired
186194
* @NoSubAdminRequired
@@ -189,6 +197,10 @@ private function generateRandomDeviceToken() {
189197
* @return array|JSONResponse
190198
*/
191199
public function destroy($id) {
200+
if ($this->checkAppToken()) {
201+
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
202+
}
203+
192204
try {
193205
$token = $this->findTokenByIdAndUser($id);
194206
} catch (WipeTokenException $e) {
@@ -213,6 +225,10 @@ public function destroy($id) {
213225
* @return array|JSONResponse
214226
*/
215227
public function update($id, array $scope, string $name) {
228+
if ($this->checkAppToken()) {
229+
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
230+
}
231+
216232
try {
217233
$token = $this->findTokenByIdAndUser($id);
218234
} catch (InvalidTokenException $e) {
@@ -287,6 +303,10 @@ private function findTokenByIdAndUser(int $id): IToken {
287303
* @throws \OC\Authentication\Exceptions\ExpiredTokenException
288304
*/
289305
public function wipe(int $id): JSONResponse {
306+
if ($this->checkAppToken()) {
307+
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
308+
}
309+
290310
try {
291311
$token = $this->findTokenByIdAndUser($id);
292312
} catch (InvalidTokenException $e) {

0 commit comments

Comments
 (0)