Skip to content

Commit bbfa5a6

Browse files
Merge pull request #63698 from nextcloud/backport/63555/stable35
[stable35] fix: Check that password matches in occ user:auth-tokens:add
2 parents f06f1d0 + 4ccf376 commit bbfa5a6

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

  • core/Command/User/AuthTokens

core/Command/User/AuthTokens/Add.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
use OC\Authentication\Events\AppPasswordCreatedEvent;
1313
use OC\Authentication\Token\IProvider;
1414
use OC\Authentication\Token\IToken;
15+
use OC\User\Manager as UserManager;
1516
use OCP\EventDispatcher\IEventDispatcher;
16-
use OCP\IUserManager;
1717
use OCP\Security\ISecureRandom;
1818
use Symfony\Component\Console\Command\Command;
1919
use Symfony\Component\Console\Helper\QuestionHelper;
@@ -25,8 +25,8 @@
2525

2626
class Add extends Command {
2727
public function __construct(
28-
protected IUserManager $userManager,
29-
protected IProvider $tokenProvider,
28+
private UserManager $userManager,
29+
private IProvider $tokenProvider,
3030
private ISecureRandom $random,
3131
private IEventDispatcher $eventDispatcher,
3232
) {
@@ -92,12 +92,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9292
$password = $helper->ask($input, $output, $question);
9393
}
9494

95+
$loginName = $input->getOption('login-name') ?? $user->getUID();
96+
9597
if ($password === null) {
9698
$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>');
99+
} else {
100+
$loggedInUser = $this->userManager->checkPasswordNoLogging($loginName, $password);
101+
if ($loggedInUser === false) {
102+
$output->writeln('<error>The given password is invalid for login ' . $loginName . '</error>');
103+
return self::FAILURE;
104+
} elseif ($loggedInUser->getUID() !== $user->getUID()) {
105+
$output->writeln('<error>The user ' . $username . ' does not match the given login ' . $loginName . '</error>');
106+
return self::FAILURE;
107+
}
97108
}
98109

99-
$loginName = $input->getOption('login-name') ?? $user->getUID();
100-
101110
$tokenName = $input->getOption('name') ?: 'cli';
102111

103112
$token = $this->random->generate(72, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);

0 commit comments

Comments
 (0)