GPT-6.1 Sol · Heavy

add-client-resource-type-and-scopes-to-authorization-schema-keycloak

Keycloak · Java · L · 300–799 lines · 5 files

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Haiku 5.5.

Gold bugs found
3 of 8
Comments published
3
Comments matching a bug
3
Comments not matching
0
Cost of this PR
$2.630

Published comments (3)

highbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:86-87

All-clients manage permission does not grant coarse visibility — Callers with only all-clients `manage` can manage client scopes but cannot list them because `canListClientScopes()` and `canViewClientScopes()` inherit the `view`-only check in `canView()`; client listing also returns 403 without `query-clients`. Include all-clients `manage` in coarse visibility checks while preserving resource-specific checks for individual clients.

highsecurityservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:86-87

All-clients view grants bypass resource-specific denials — Administrators can read explicitly denied clients because `canView(ClientModel)` returns early and `ClientsResource.getClients` skips individual checks when `canView()` accepts all-clients `view`. Keep the admin-role shortcut separate from fine-grained grants, and evaluate client-specific policies before falling back to all-clients permissions, including during list filtering. **Also found in:** - `services/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:78-82` - `services/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:77-82`

mediumbugtests/base/src/test/java/org/keycloak/tests/admin/authz/fgap/PermissionClientTest.java:148-152

Removal-denial test can pass when only the scope lookup is forbidden — The test stays green even if removal authorization breaks because `getDefaultClientScopes()` can throw the accepted `ForbiddenException` before `removeDefaultClientScope()` runs. Fetch the scope ID through the privileged `realm.admin()` client before the try block, then assert `ForbiddenException` only around the restricted client's `removeDefaultClientScope()` call.

Gold bugs found (3)

mediumClientPermissionsV2.canView() ignores a global MANAGE permission, so admins with only global manage take the unpaginated, per-client evaluated listing path.
highcanView(client) short-circuits on the global all-clients VIEW permission, so a client-specific permission denying an admin is never evaluated and the client is still viewable.
mediumThe negative check for removing a default client scope expects ForbiddenException, but it can come from the preceding getDefaultClientScopes() call, so the test passes even without a permission check on removal.

Gold bugs missed (5)

mediumClaims the removal-cleanup listener is guarded by the V1 fine-grained flag, so client/role/group permissions are orphaned when V1 is disabled or only V2 is enabled.
highgetClientsWithPermission in ClientPermissionsV2 only finds the type-level 'Clients' resource and returns its name, never actual client ids, so callers that resolve the returned values as client ids get wrong results or null clients.
mediumClaims getResourceTypeResource can return null in ClientPermissionsV2.hasPermission, causing a NullPointerException in findByResource.
highIn ClientPermissionsV2.hasPermission, an admin granted a permission on all clients is denied on any client that also has its own per-client permission resource, because only the per-client resource is evaluated.
highClientPermissionsV2.canExchangeTo throws UnsupportedOperationException, but AbstractTokenExchangeProvider still calls clients().canExchangeTo for client-to-client exchange, so with token exchange and FGAP V2 enabled the request fails with a server error instead of a permission decision.