The vulnerability lies in Keycloak's Fine-Grained Admin Permissions (FGAPv2) feature, where an administrator with limited client management permissions could escalate their privileges. The root cause was the failure to enforce MAP_ROLE_CLIENT_SCOPE permission checks when adding or removing role scope mappings for clients or realms.
The analysis of the security patch in commit 8894c02 reveals the exact locations of the vulnerability. The patch modifies two main classes: org.keycloak.services.resources.admin.ScopeMappedClientResource and org.keycloak.services.resources.admin.ScopeMappedResource.
In both classes, the methods responsible for adding and deleting scope mappings (addClientScopeMapping, deleteClientScopeMapping, addRealmScopeMappings, deleteRealmScopeMappings) were missing a crucial permission check. The patch rectifies this by inserting the auth.roles().requireMapClientScope(roleModel); call. This call ensures that the administrator performing the action has the necessary permission to map the specific role to a client's scope.
Before the patch, an attacker with fine-grained manage permission on a single client could call these API endpoints to add highly privileged roles (like realm-admin) to that client's scope. When a user with that privileged role authenticated through the compromised client, the role would be included in their access token, leading to privilege escalation.
The identified vulnerable functions are the exact methods that were modified to include these missing security checks. During exploitation, these functions would be present in the runtime profile as they are directly responsible for processing the malicious scope mapping request.