Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep pw based auth tokens valid when pw-less login happens #27886

Conversation

7118path
Copy link
Contributor

@7118path 7118path commented Jul 9, 2021

Hi,

after publishing the eID-Login app for Nextcloud users reported about the problem, that after doing a passwordless login with an eID, all already existing password based authn tokens (browser sessions and app passwords) become invalidated. See eid-login/eid-login-nextcloud#2

When investigating the issue, I found the same happens when doing a WebAuthn (password ) login. The empty password from the login is used to update existing authn tokens, which invalidates them. They get removed on the next run of

private function checkTokenCredentials(IToken $dbToken, $token) {

To keep the existing authn tokens valid, this pull requests prevents the updating of the tokens, if the given password is an empty string.

Please note: This are the two places I found where token passwords are updated on an login attempt. I am not sure why this must happen twice? There may be more? I don`t know.

Also there is a little inconsistency in the function signatures for setting token passwords. When creating a session token a 'null' value as password can be set, which is also set it as 'null' in the database:

public function createSessionToken(IRequest $request, $uid, $loginName, $password = null, $remember = IToken::DO_NOT_REMEMBER) {

This is resulting in different handling of the token later on:
* @return string
*/
public function getPassword(IToken $savedToken, string $tokenId): string {
$password = $savedToken->getPassword();
if (is_null($password)) {
throw new PasswordlessTokenException();
}

$pwd = $this->tokenProvider->getPassword($dbToken, $token);
} catch (InvalidTokenException $ex) {
// An invalid token password was used -> log user out
return false;
} catch (PasswordlessTokenException $ex) {
// Token has no password
if (!is_null($this->activeUser) && !$this->activeUser->isEnabled()) {
$this->tokenProvider->invalidateToken($token);

In these functions 'null' is not allowed but an empty string must be used:

public function generateToken(string $token,

public function setPassword(IToken $token, string $tokenId, string $password) {

Maybe this APIs can be changed to handle the 'null' value more consistently?

TIA for looking into this and feedback about the issue!

Greetings!

@szaimen szaimen added the 3. to review Waiting for reviews label Jul 13, 2021
@szaimen szaimen added this to the Nextcloud 23 milestone Jul 13, 2021
Tobias Assmann added 2 commits July 16, 2021 13:32
…ss login

Signed-off-by: Tobias Assmann <tobias.assmann@ecsec.de>
Signed-off-by: Tobias Assmann <tobias.assmann@ecsec.de>
@7118path 7118path force-pushed the keep_pw_based_authntoken_alive_on_pwlesslogin branch from 421392c to 669bd4d Compare July 16, 2021 11:34
@nickvergessen
Copy link
Member

Conflicting files
lib/private/Authentication/Token/PublicKeyTokenProvider.php

You unluckily need to rebase on latest master

Tobias Assmann added 2 commits July 16, 2021 14:31
@juliusknorr
Copy link
Member

@ecsecta Could you do a rebase of the branch instead of a merge with master and maybe also squash your commits into one?

@juliusknorr juliusknorr added bug feature: authentication 3. to review Waiting for reviews and removed 3. to review Waiting for reviews labels Jul 26, 2021
@7118path
Copy link
Contributor Author

@juliushaertl The last commit should contain all changes based on the latest master. Merging this commit should be sufficient. I have no idea how to squash all commit, when not merging. If I am wrong, maybe you could point me to some docs how to do what is needed now?

@LukasReschke LukasReschke merged commit d4352aa into nextcloud:master Jul 27, 2021
@LukasReschke
Copy link
Member

/backport to stable22

@7118path 7118path deleted the keep_pw_based_authntoken_alive_on_pwlesslogin branch July 27, 2021 12:39
@7118path
Copy link
Contributor Author

Thank you!

@kesselb
Copy link
Contributor

kesselb commented Jul 27, 2021

/backport to stable22

1 similar comment
@kesselb
Copy link
Contributor

kesselb commented Jul 27, 2021

/backport to stable22

@backportbot-nextcloud
Copy link

The backport to stable22 failed. Please do this backport manually.

@szaimen
Copy link
Contributor

szaimen commented Aug 8, 2021

/backport to stable22

@szaimen
Copy link
Contributor

szaimen commented Aug 8, 2021

/backport to stable21

@szaimen
Copy link
Contributor

szaimen commented Aug 8, 2021

/backport to stable20

@backportbot-nextcloud
Copy link

The backport to stable20 failed. Please do this backport manually.

@backportbot-nextcloud
Copy link

The backport to stable21 failed. Please do this backport manually.

@backportbot-nextcloud
Copy link

The backport to stable22 failed. Please do this backport manually.

@ChristophWurst
Copy link
Member

ChristophWurst commented Aug 13, 2021

more luck on Friday 13th? let's fine out

@ChristophWurst
Copy link
Member

/backport to stable22

@backportbot-nextcloud
Copy link

The backport to stable22 failed. Please do this backport manually.

tsdicloud added a commit to nextmcloud/server that referenced this pull request Sep 13, 2021
We observer token invalidations random for OpenId Connect users and early apply the fix for
nextcloud#27886

Signed-off-by: Bernd.Rederlechner@t-systems.com <bernd.rederlechner@t-systems.com>
dokshukin pushed a commit to nextmcloud/server that referenced this pull request Oct 18, 2021
We observer token invalidations random for OpenId Connect users and early apply the fix for
nextcloud#27886

Signed-off-by: Bernd.Rederlechner@t-systems.com <bernd.rederlechner@t-systems.com>
dokshukin pushed a commit to nextmcloud/server that referenced this pull request Oct 18, 2021
We observer token invalidations random for OpenId Connect users and early apply the fix for
nextcloud#27886

Signed-off-by: Bernd.Rederlechner@t-systems.com <bernd.rederlechner@t-systems.com>
sgyuris pushed a commit to nextmcloud/server that referenced this pull request Oct 20, 2021
We observer token invalidations random for OpenId Connect users and early apply the fix for
nextcloud#27886

Signed-off-by: Bernd.Rederlechner@t-systems.com <bernd.rederlechner@t-systems.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants