Skip to content

Commit

Permalink
Harden apptoken check
Browse files Browse the repository at this point in the history
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
  • Loading branch information
rullzer authored and backportbot[bot] committed May 18, 2021
1 parent c6af693 commit e309013
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 e309013

Please sign in to comment.