Claude Opus 5.5 · 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
5
Comments matching a bug
3
Comments not matching
2
Cost of this PR
$6.047

Published comments (5)

highsecurityservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:77-88

Per-client VIEW deny is bypassed by an all-clients VIEW grant — `canView()` checks only the all-clients `Clients` resource, so a NEGATIVE permission on one client can't override an all-clients VIEW grant, unlike users V2. Short-circuit only on `canViewClientDefault()` and let `hasPermission(client, VIEW)` decide.

highsecurityservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:224-234

Client permission check accepts scopes from permissions on other resources — A grant on another resource, such as the all-clients type resource, can satisfy this client's check and bypass a per-client deny. Skip any `Permission` whose `getResourceId()` differs from `resource.getId()`, as `UserPermissionsV2.hasPermission` does.

highbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:147-150

canExchangeTo throws in V2, so token exchange fails with HTTP 500 — Return a defined result such as `false`, or update that caller to handle V2.

mediumperformanceservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:77-83

canView(client) runs up to four separate policy evaluations per client — Client listing calls this per client, so each listing costs up to four `root.evaluatePermission` runs per client. Evaluate the client resource once and match the returned scopes against MANAGE, CONFIGURE and VIEW together.

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

Forbidden check for removing default client scope never reaches removal — `clientResource.getDefaultClientScopes()` already throws `ForbiddenException`, so `removeDefaultClientScope` is never reached and the test passes even if removal were allowed. Fetch the scope id via `realm.admin()`, then call `removeDefaultClientScope` through `realmAdminClient` and assert it's forbidden.

Gold bugs found (3)

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

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.
mediumClientPermissionsV2.canView() ignores a global MANAGE permission, so admins with only global manage take the unpaginated, per-client evaluated listing path.
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.