8000 Username/email cache lookup can return a managed user from a different realm · Issue #55554 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Username/email cache lookup can return a managed user from a different realm #55554

In review

Description

@sguilhen

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

infinispan

Bug Description

UserCacheSession.getUserById() only returns a session-managed user for a given id if that managed user actually belongs to the requested realm; otherwise it falls back to a fresh lookup.
getUserByUsername() and getUserByEmail() check the same realm.getId().equals(managed.realmId()) condition, but only use it to decide whether to also cache the username/email query. The managed user itself is returned unconditionally, even when it belongs to a different realm than the one passed to the method.

Version

nightly

Regression

  • The issue is a regression

Expected behavior

If a managed user in the session has the same id as the user resolved by the username/email lookup but belongs to a different realm, the managed user must not be returned, mirroring the behavior of getUserById().

Actual behavior

getUserByUsername()/getUserByEmail() return the managed user even when its realm does not match the realm passed to the method.

How to Reproduce?

  1. Within a single KeycloakSession, cause a user with id X to become session-managed for realm A (for example through getUserById(realmA, X)).
  2. In the same session, call getUserByUsername(realmB, username) (or getUserByEmail) such that the underlying store resolves the username to a user that also has id X, but belongs to realm B.
  3. The managed user from realm A is returned instead of realm B's user, or instead of falling back to a fresh lookup.

Anything else?

Follow-up to #54645. Introduced in #54646, which added the managed-user fast path for getUserByUsername/getUserByEmail but did not reuse the realm check from getUserById to gate the returned user, only the query caching.

Activity

  1. added
    kind/bug
    on Nov 25, 2026
  2. added theissue type on Nov 25, 2026
  3. added
    area/infinispan
    on Nov 25, 2026
  4. self-assigned this
    on Nov 25, 2026
  5. added a commit that references this issue on Nov 25, 2026
    1672685
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/infinispankind/bugpriority/normalteam/core-iam

Type

Fields

No fields configured for bug.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    0