8000 fix: aligning the anti-phishing check with scim by shawkins · Pull Request #55546 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public BaseClientRepresentation getClient() {
@PUT
@Override
public Response createOrUpdateClient(BaseClientRepresentation client) {
assertSameClientIds(clientId, client.getClientId());

try {
var current = typeProvider.get(clientId);

assertSameClientIds(clientId, client.getClientId());

if (current == null) {
return Response.status(Response.Status.CREATED).entity(typeProvider.create(client)).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import jakarta.annotation.Nonnull;
import jakarta.validation.Valid;
import jakarta.ws.rs.ForbiddenException;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
Expand Down Expand Up @@ -141,23 +140,9 @@ public Response createClient(@Valid BaseClientRepresentation client) {
}
}

/**
* When the path {@code clientId} does not resolve, return 403 if the caller
* cannot list clients
* (anti client-ID phishing), matching {@code ClientsResource#getClient} for
* Admin API v1.
*/
private void enforceAntiPhishingIfClientMissing(String clientId) {
// TODO: align with the scim anti-phishing check once https://github.com/keycloak/keycloak/issues/52147 is addressed
if (realm.getClientByClientId(clientId) == null && !typeProvider.getPermissions().clients().canList()) {
throw new ForbiddenException();
}
}

@Path("{id}")
@Override
public ClientApi client(@PathParam("id") String clientId) {
enforceAntiPhishingIfClientMissing(clientId);
return new DefaultClientApi(session, clientId, typeProvider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,19 @@ public void updateClient() throws Exception {
try (var response = getClientApi(queryClientsAdminClient, getRealmName(), "test-update-view").createOrUpdateClient(viewRep)) {
assertEquals(403, response.getStatus(), "Expected 403 Forbidden when updating client without access");
}

try (var response = getClientApi(noAccessAdminClient, getRealmName(), "test-update-view").createOrUpdateClient(viewRep)) {
assertEquals(403, response.getStatus(), "Expected 403 Forbidden when updating client without access");
}

// having a mismatched or non-existing client id should not change the response code
try (var response = getClientApi(noAccessAdminClient, getRealmName(), "does not exist").createOrUpdateClient(viewRep)) {
assertEquals(403, response.getStatus(), "Expected 403 Forbidden when updating client without access");
}
viewRep.setClientId("does not exist");
try (var response = getClientApi(noAccessAdminClient, getRealmName(), "test-update-view").createOrUpdateClient(viewRep)) {
assertEquals(403, response.getStatus(), "Expected 403 Forbidden when updating client without access");
}
}

/**
Expand Down Expand Up @@ -538,7 +551,7 @@ public void fgapDeleteClient() throws Exception {
assertThat(response.readEntity(String.class), containsString("HTTP 403 Forbidden"));
}
}

private OIDCClientRepresentation createClientRep(String clientId, String... roles) {
OIDCClientRepresentation rep = new OIDCClientRepresentation();
rep.setClientId(clientId);
Expand Down
Loading
0