The analysis of the provided patch for Keycloak reveals a broken access control vulnerability within the UserManagedPermissionService. The vulnerability, as described, allows for horizontal privilege escalation when updating UMA policies that apply to multiple resources.
The root cause of the vulnerability is that the authorization check only validates the caller's ownership against the first resource listed in the policy. The getAssociatedResourceId(policyId) method retrieves only this first resource, and the subsequent checkRequest call uses it to authorize the entire operation. If a policy contains resources owned by different users, a user owning only the first resource can modify the policy for all associated resources.
The provided commit 96797bb125ea044b18f3e76bbfa364657f1186ef specifically addresses this issue within the update method of the UserManagedPermissionService.java file. The patch introduces a check that prevents the set of resources in a policy from being changed during an update. If the update attempts to add, remove, or change the resources, the request is rejected. This effectively prevents the exploitation of the vulnerability through the update operation.
Based on the evidence in the patch, the org.keycloak.authorization.protection.policy.UserManagedPermissionService.update function is identified as the vulnerable function. During exploitation, this function would be present in the runtime profile as it processes the malicious update request. While the vulnerability description also mentions the delete operation, the provided patch only contains changes for the update method, so the analysis is focused on the evidence present in the commit.