8000 Deferred password re-hash overwrites a credential that changed after it was validated · Issue #55028 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Deferred password re-hash overwrites a credential that changed after it was validated #55028

Closed

Description

@ahus1

Before reporting an issue

  • I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

Area

authentication

Describe the bug

This is a follow-up to #53633, which covers several problems around the deferred password re-hash. This issue only covers the update of a credential that has become stale between the password validation and the re-hash.

Since Keycloak 26.3 (and 26.2.6), PasswordCredentialProvider.isValid() no longer re-hashes an outdated password inline. It queues a job with enlistAfterCompletion. After the request's transaction has committed, that job re-hashes the validated password in a new transaction and writes it to the same credential id (refreshPassword). The job does not check whether the stored credential changed in the meantime, and it writes the full credential, so every change made after the validation is lost.

If the user's password is changed while the re-hash is pending, the job writes the old password back. The change reports success, the old password keeps working, and the new one is rejected. This happens when the change comes from another request committing between the login's password check and the end of its commit, or from code that calls isValid(current) followed by updateCredential(new) in the same transaction (in that case the overwrite happens every time).

The re-hash also overwrites other changes to the stored credential, for example its user label or created date.

When the credential is changed concurrently, the write may also fail with a Hibernate StaleStateException. A failed admin password reset then returns HTTP 500.

Federated user credentials have the same problem. FederatedUserCredentialEntity has no @Version, so it is not possible to detect that the credential changed after the job read it.

Version

26.8.0, 26.6.0

Regression

  • The issue is a regression

Expected behavior

  • A password set by an admin reset (or any other password update) stays in effect when a login for the same user is running at the same time.
  • A password checked and then updated in the same transaction (isValid(current) followed by updateCredential(new)) keeps the new password after commit.
  • The re-hash does not overwrite other changes to the credential, like the user label or the created date.
  • If the credential changed after it was validated, the re-hash is skipped, or fails without affecting the request that validated the password.

Actual behavior

  • The admin reset returns 204, but afterwards the previous password is valid again and the new one is rejected.
  • A password updated in the same transaction after isValid(current) is replaced by the old password after commit.
  • Metadata changes to the credential made in between are lost.

How to Reproduce?

  1. Create a user with a password hashed with outdated parameters, for example by creating the password with the realm password policy hashIterations(1) and then changing the policy to hashIterations(2).
  2. In a custom authenticator or extension, call user.credentialManager().isValid(UserCredentialModel.password(currentPassword)) and then user.credentialManager().updateCredential(UserCredentialModel.password(newPassword)) in the same transaction.
  3. After the transaction has committed, validate the new password.

Expected: the new password is valid. Actual: the old password is valid again.

The same happens without custom code when an admin resets the password while a login with the old password is running. See #53633 for a reproducer script and results.

Anything else?

The first part of #53742 fixes the Argon2 policyCheck that caused a re-hash on every login. This issue is the part that remains for the re-hash itself.

#53742 proposes to compute the hash first, then read the credential from local storage (not through the user cache), skip the update if the credential is gone or its secret data changed, and rely on the @Version of CredentialEntity for changes between the read and the write. For federated credentials this needs a VERSION column on FED_USER_CREDENTIAL, which requires a database migration.

Activity

  1. added
    area/authenticationAuth flows, authenticators, required actions, OTP, password policies, brute force
    kind/bugCategorizes a PR related to a bug
    on Nov 11, 2026
  2. self-assigned this
    on Nov 11, 2026
  3. added theissue type on Nov 11, 2026
  4. added a commit that references this issue on Nov 11, 2026
    2506eb1
  5. 4 remaining items

  6. added a commit that references this issue on Nov 11, 2026
    e4bcd40
  7. added 2 commits that reference this issue on Nov 11, 2026
    2359f6b
    3df158a
  8. added 2 commits that reference this issue on Nov 12, 2026
    8173b8a
    3f05acb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Fields

No fields configured for bug.

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

0