Skip to content

Commit 4310145

Browse files
committed
fix: Check that password matches in occ user:auth-tokens:add
Otherwise you could create tokens containing an invalid password, which was confusing. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 930576f commit 4310145

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

  • core/Command/User/AuthTokens

core/Command/User/AuthTokens/Add.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
use OC\Authentication\Events\AppPasswordCreatedEvent;
1212
use OC\Authentication\Token\IProvider;
1313
use OC\Authentication\Token\IToken;
14+
use OC\User\Manager as UserManager;
1415
use OCP\EventDispatcher\IEventDispatcher;
15-
use OCP\IUserManager;
1616
use OCP\Security\ISecureRandom;
1717
use Symfony\Component\Console\Command\Command;
1818
use Symfony\Component\Console\Helper\QuestionHelper;
@@ -24,8 +24,8 @@
2424

2525
class Add extends Command {
2626
public function __construct(
27-
protected IUserManager $userManager,
28-
protected IProvider $tokenProvider,
27+
private UserManager $userManager,
28+
private IProvider $tokenProvider,
2929
private ISecureRandom $random,
3030
private IEventDispatcher $eventDispatcher,
3131
) {
@@ -83,8 +83,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8383
$password = $helper->ask($input, $output, $question);
8484
}
8585

86+
$loginName = $input->getOption('login-name') ?? $user->getUID();
87+
8688
if ($password === null) {
8789
$output->writeln('<info>No password provided. The generated app password will therefore have limited capabilities. Any operation that requires the login password will fail.</info>');
90+
} else {
91+
$loggedInUser = $this->userManager->checkPasswordNoLogging($loginName, $password);
92+
if ($loggedInUser === false) {
93+
$output->writeln('<error>The given password is invalid for login ' . $loginName . '</error>');
94+
return self::FAILURE;
95+
} elseif ($loggedInUser->getUID() !== $user->getUID()) {
96+
$output->writeln('<error>The user ' . $username . ' does not match the given login ' . $loginName . '</error>');
97+
return self::FAILURE;
98+
}
8899
}
89100

90101
$tokenName = $input->getOption('name') ?: 'cli';

0 commit comments

Comments
 (0)