Skip to content

Commit

Permalink
Confirm mails only per POST
Browse files Browse the repository at this point in the history
- this is to avoid automatic confirmation by certain softwares that open
  links

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Aug 30, 2021
1 parent 68b21f8 commit 38a7645
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion apps/provisioning_api/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
],
'routes' => [
// Verification
['name' => 'Verification#verifyMail', 'url' => '/mailVerification/{key}/{token}/{userId}', 'verb' => 'GET'],
['name' => 'Verification#showVerifyMail', 'url' => '/mailVerification/{key}/{token}/{userId}', 'verb' => 'GET'],
['name' => 'Verification#verifyMail', 'url' => '/mailVerification/{key}/{token}/{userId}', 'verb' => 'POST'],
]
];
21 changes: 21 additions & 0 deletions apps/provisioning_api/lib/Controller/VerificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ public function __construct(

/**
* @NoCSRFRequired
* @NoAdminRequired
* @NoSubAdminRequired
*/
public function showVerifyMail(string $token, string $userId, string $key) {
if ($this->userSession->getUser()->getUID() !== $userId) {
throw new InvalidArgumentException('Logged in user is not mail address owner');
}
$email = $this->crypto->decrypt($key);

return new TemplateResponse(
'core', 'confirmation', [
'title' => $this->l10n->t('Email confirmation'),
'message' => $this->l10n->t('To enable the email address %s please click the button below.', [$email]),
'action' => $this->l10n->t('Confirm'),
], 'guest');
}

/**
* @NoAdminRequired
* @NoSubAdminRequired
*/
public function verifyMail(string $token, string $userId, string $key) {
try {
Expand All @@ -95,6 +115,7 @@ public function verifyMail(string $token, string $userId, string $key) {
}
$emailProperty->setLocallyVerified(IAccountManager::VERIFIED);
$this->accountManager->updateAccount($userAccount);
$this->verificationToken->delete($token, $user, 'verifyMail' . $ref);
} catch (InvalidTokenException $e) {
$error = $e->getCode() === InvalidTokenException::TOKEN_EXPIRED
? $this->l10n->t('Could not verify mail because the token is expired.')
Expand Down
4 changes: 4 additions & 0 deletions lib/private/Security/VerificationToken/VerificationToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,8 @@ public function create(IUser $user, string $subject, string $passwordPrefix = ''

return $token;
}

public function delete(string $token, IUser $user, string $subject): void {
$this->config->deleteUserValue($user->getUID(), 'core', $subject);
}
}
7 changes: 7 additions & 0 deletions lib/public/Security/VerificationToken/IVerificationToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,11 @@ public function check(string $token, ?IUser $user, string $subject, string $pass
* @since 23.0.0
*/
public function create(IUser $user, string $subject, string $passwordPrefix = ''): string;

/**
* Deletes the token identified by the provided parameters
*
* @since 23.0.0
*/
public function delete(string $token, IUser $user, string $subject): void;
}

0 comments on commit 38a7645

Please sign in to comment.