Skip to content

Fix NPE in OrganizationGroupMembershipMapper when no organization scope is requested#48835

Open
amountainram wants to merge 1 commit intokeycloak:mainfrom
amountainram:fix/org-group-mapper-npe
Open

Fix NPE in OrganizationGroupMembershipMapper when no organization scope is requested#48835
amountainram wants to merge 1 commit intokeycloak:mainfrom
amountainram:fix/org-group-mapper-npe

Conversation

@amountainram
Copy link
Copy Markdown

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.

…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>
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.

NPE in OrganizationGroupMembershipMapper when no organization scope is requested

1 participant