Skip to content

Commit

Permalink
Merge pull request #27012 from nextcloud/backport/27000/stable21
Browse files Browse the repository at this point in the history
[stable21] Harden apptoken check
  • Loading branch information
rullzer authored May 19, 2021
2 parents f5e5b07 + e309013 commit 51e2799
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions apps/settings/lib/Controller/AuthSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ public function __construct(string $appName,
* @return JSONResponse
*/
public function create($name) {
if ($this->checkAppToken()) {
return $this->getServiceNotAvailableResponse();
}

try {
$sessionId = $this->session->getId();
} catch (SessionNotAvailableException $ex) {
Expand Down Expand Up @@ -181,6 +185,10 @@ private function generateRandomDeviceToken() {
return implode('-', $groups);
}

private function checkAppToken(): bool {
return $this->session->exists('app_password');
}

/**
* @NoAdminRequired
* @NoSubAdminRequired
Expand All @@ -189,6 +197,10 @@ private function generateRandomDeviceToken() {
* @return array|JSONResponse
*/
public function destroy($id) {
if ($this->checkAppToken()) {
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
}

try {
$token = $this->findTokenByIdAndUser($id);
} catch (WipeTokenException $e) {
Expand All @@ -213,6 +225,10 @@ public function destroy($id) {
* @return array|JSONResponse
*/
public function update($id, array $scope, string $name) {
if ($this->checkAppToken()) {
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
}

try {
$token = $this->findTokenByIdAndUser($id);
} catch (InvalidTokenException $e) {
Expand Down Expand Up @@ -287,6 +303,10 @@ private function findTokenByIdAndUser(int $id): IToken {
* @throws \OC\Authentication\Exceptions\ExpiredTokenException
*/
public function wipe(int $id): JSONResponse {
if ($this->checkAppToken()) {
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
}

try {
$token = $this->findTokenByIdAndUser($id);
} catch (InvalidTokenException $e) {
Expand Down

0 comments on commit 51e2799

Please sign in to comment.