Skip to content

Commit

Permalink
fix(Wipe): Better handle missing tokens
Browse files Browse the repository at this point in the history
Check for non-empty token string to avoid 500/internal server error due to `Argument #1 ($token) must be of type string, null given`

- Refactor slightly to streamline code
- Fix noted bug in both checkWipe() and wipeDone()

(initially reported in the community forum then reproduced)

Signed-off-by: Josh <josh.t.richards@gmail.com>
  • Loading branch information
joshtrichards authored Jul 1, 2024
1 parent beececf commit 1635ad1
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions core/Controller/WipeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ public function __construct(
* 404: Device should not be wiped
*/
#[FrontpageRoute(verb: 'POST', url: '/core/wipe/check')]
public function checkWipe(string $token): JSONResponse {
try {
if ($this->remoteWipe->start($token)) {
return new JSONResponse([
'wipe' => true
]);
public function checkWipe(string $token = ''): JSONResponse {
if ($token !== '') {
try {
if ($this->remoteWipe->start($token)) {
return new JSONResponse([
'wipe' => true
]);
}
} catch (InvalidTokenException $e) {
// do nothing special, handled below
}

return new JSONResponse([], Http::STATUS_NOT_FOUND);
} catch (InvalidTokenException $e) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}

return new JSONResponse([], Http::STATUS_NOT_FOUND);
}


Expand All @@ -74,15 +76,17 @@ public function checkWipe(string $token): JSONResponse {
* 404: Device should not be wiped
*/
#[FrontpageRoute(verb: 'POST', url: '/core/wipe/success')]
public function wipeDone(string $token): JSONResponse {
try {
if ($this->remoteWipe->finish($token)) {
return new JSONResponse([]);
public function wipeDone(string $token = ''): JSONResponse {
if ($token !== '') {
try {
if ($this->remoteWipe->finish($token)) {
return new JSONResponse([]);
}
} catch (InvalidTokenException $e) {
// do nothing special, handled below
}

return new JSONResponse([], Http::STATUS_NOT_FOUND);
} catch (InvalidTokenException $e) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}

return new JSONResponse([], Http::STATUS_NOT_FOUND);
}
}

0 comments on commit 1635ad1

Please sign in to comment.