Skip to content

Commit 47a96f7

Browse files
come-ncbackportbot[bot]
authored andcommitted
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 40cd9a7 commit 47a96f7

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
) {
@@ -85,8 +85,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8585
$password = $helper->ask($input, $output, $question);
8686
}
8787

88+
$loginName = $input->getOption('login-name') ?? $user->getUID();
89+
8890
if ($password === null) {
8991
$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>');
92+
} else {
93+
$loggedInUser = $this->userManager->checkPasswordNoLogging($loginName, $password);
94+
if ($loggedInUser === false) {
95+
$output->writeln('<error>The given password is invalid for login ' . $loginName . '</error>');
96+
return self::FAILURE;
97+
} elseif ($loggedInUser->getUID() !== $user->getUID()) {
98+
$output->writeln('<error>The user ' . $username . ' does not match the given login ' . $loginName . '</error>');
99+
return self::FAILURE;
100+
}
90101
}
91102

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

0 commit comments

Comments
 (0)