Repository navigation
Description
Before reporting an issue
- I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.
Area
admin/api
Bug Description
DELETE /admin/realms/{realm}/clients/{client-uuid}/client-secret/rotated returns 500 Internal Server Error when the caller does not have permission to configure the client. Other admin endpoints return 403 Forbidden for the same caller. The permission check itself works: I checked that an existing rotated secret is still there after the failed call. Only the response status is wrong, and the server logs a NullPointerException.
Version
26.8.2 (the same code is on main as of 994ee7e)
Regression
- The issue is a regression
Expected behavior
403 Forbidden, as returned by the other admin endpoints for a caller without the required permission.
Actual behavior
500 Internal Server Error, with this in the server log:
ERROR [org.keycloak.services.error.KeycloakErrorHandler] Uncaught server error: java.lang.NullPointerException: Cannot invoke "java.lang.Throwable.getMessage()" because the return value of "java.lang.RuntimeException.getCause()" is null
at org.keycloak.services.resources.admin.ClientResource.invalidateRotatedSecret(ClientResource.java:843)
How to Reproduce?
- Start Keycloak 26.8.2 with
start-devand an admin user. - As admin, create a realm
test, a confidential client in it, and a usernopermwith a password and no admin roles. - Get a token for
nopermfrom the realm'sadmin-cliclient:
curl -s -X POST http://localhost:8080/realms/test/protocol/openid-connect/token -d grant_type=password -d client_id=admin-cli -d username=noperm -d password=<password> | jq -r .access_token
- Call the endpoint with that token:
curl -s -o /dev/null -w '%{http_code}\n' -X DELETE -H "Authorization: Bearer <token>" http://localhost:8080/admin/realms/test/clients/<client-uuid>/client-secret/rotated
The response is 500. With the same token, other admin write endpoints I tried (for example PUT /client-policies/policies, POST /components, DELETE /identity-provider/instances/{alias}) return 403.
Anything else?
The permission check auth.clients().requireConfigure(client) runs inside a try whose catch (RuntimeException rte) builds the error with rte.getCause().getMessage(). ForbiddenException has no cause, so the catch block throws a NullPointerException:
keycloak/services/src/main/java/org/keycloak/services/resources/admin/ClientResource.java
Lines 809 to 831 in 994ee7e
| public Response invalidateRotatedSecret() { | |
| try{ | |
| auth.clients().requireConfigure(client); | |
| logger.debug("delete rotated secret"); | |
| // Always remove rotated secret attributes even when the feature is disabled, | |
| // so stale secrets cannot become valid again if the feature is re-enabled. | |
| OIDCClientSecretConfigWrapper wrapper = OIDCClientSecretConfigWrapper.fromClientModel(client); | |
| CredentialRepresentation rep = new CredentialRepresentation(); | |
| rep.setType(CredentialRepresentation.SECRET); | |
| rep.setValue(wrapper.getClientRotatedSecret(session)); | |
| 8000 | adminEvent.operation(OperationType.DELETE).resourcePath(session.getContext().getUri()).representation(rep).success(); |
| wrapper.removeClientSecretRotated(); | |
| return Response.noContent().build(); | |
| } catch (RuntimeException rte) { | |
| throw new ErrorResponseException(rte.getCause().getMessage(), rte.getMessage(), | |
| Status.INTERNAL_SERVER_ERROR); | |
| } |
This pattern has been there since client secret rotation was added (#10603). regenerateSecret also calls requireConfigure inside a try, but only catches ClientPolicyException, and it returns 403 for the same caller as expected.
A possible fix is to call requireConfigure before the try, as most other methods in ClientResource do, and to stop relying on getCause() being non-null. I'd be happy to send a PR for this if that approach sounds right.
Metadata
Metadata
Assignees
Labels
Type
Fields
Projects
- StatusShow more project fieldsOpen
Activity
atishay-kasliwal commentedon Nov 20, 2026
@ksquare0608 Looks like the catch block in
invalidateRotatedSecretis the cause.requireConfigurethrows aForbiddenExceptionwith no cause, andrte.getCause().getMessage()then throws the NPE. Are you planning to send a fix? If not, I'd like to pick it up and let the forbidden exception pass through, with a test that expects 403.ksquare0608 commentedon Nov 22, 2026
@atishay-kasliwal Thanks for confirming the cause! Yes, I'm planning to send a fix: moving
requireConfigurebefore thetryso theForbiddenExceptionpasses through, and adding a test that expects 403. I'll open a PR in the next few days.