Fix NPE in OrganizationGroupMembershipMapper when no organization scope is requested#48835
Open
amountainram wants to merge 1 commit intokeycloak:mainfrom
Open
Fix NPE in OrganizationGroupMembershipMapper when no organization scope is requested#48835amountainram wants to merge 1 commit intokeycloak:mainfrom
amountainram wants to merge 1 commit intokeycloak:mainfrom
Conversation
…pe is requested OrganizationGroupMembershipMapper.resolveFromRequestedScopes() calls OrganizationScope.valueOfScope() which returns null when the request does not include an organization scope. The method then calls resolveOrganizations() on the null reference, causing a NullPointerException. This mirrors the null guard already present in OrganizationMembershipMapper. Closes keycloak#48834 Signed-off-by: Umberto Toniolo <amountainram@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #48834
Problem
OrganizationGroupMembershipMapper.resolveFromRequestedScopes() throws a NullPointerException when the authorization request does not include an organization:* scope. This is a regression introduced in 26.6.0 via #45511.
OrganizationScope.valueOfScope() returns null when no organization-related scope is present in the request. resolveFromRequestedScopes() then calls .resolveOrganizations() on the null reference, causing:
java.lang.NullPointerException: Cannot invoke "...OrganizationScope.resolveOrganizations(...)" because "scope" is null at ...OrganizationGroupMembershipMapper.resolveFromRequestedScopes(OrganizationGroupMembershipMapper.java:129)
This breaks any auth code flow on realms with Organizations enabled when the client does not request an organization: scope and the user has no existing session (HTTP 500, {"error":"unknown_error"}).
Fix
Add a null guard for the return value of OrganizationScope.valueOfScope(), returning Stream.empty() when null. This mirrors the existing null check in OrganizationMembershipMapper.resolveFromRequestedScopes().
A regression test (testNoNpeWhenOrganizationScopeNotRequested) is added to OrganizationGroupMembershipOIDCMapperTest.
AI disclosure
AI tools (GitHub Copilot) were used to assist with locating the bug, drafting the issue, and reviewing the fix. The contributor understands the change and all code submitted.