Skip to content

[CIMD] Stale resource audience mapper persists after allowlist tightening - #55212

Open
tnorimat wants to merge 1 commit into
keycloak:mainfrom
Hitachi:ISSUE-55131
Open

tnorimat wants to merge 1 commit into
keycloak:mainfrom
Hitachi:ISSUE-55131

Conversation

@tnorimat

Copy link
Copy Markdown
Contributor

closes #55131

@tnorimat
tnorimat requested a review from a team as a code owner November 16, 2026 02:21
Copilot AI balanced review requested due to automatic review settings November 16, 2026 02:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Revoked audiences can still appear in tokens from client-credentials and refresh-token grants, and authorization-time cleanup can roll back when later checks fail.

2 open issues
What changed in this PR

This PR addresses stale CIMD resource-audience mappers described in #55131 by reconciling them against the current allowlist during authorization requests.

Changes:

  • Removes stale mappers even when resource is omitted or a still-allowed resource is requested.
  • Removes CIMD-owned audience mappers when Resource Indicators are disabled.
  • Adds regression tests for omitted-resource and alternate-resource authorization requests.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​client/​policies/​ClientIdMetadataDocumentTest.java Tests mapper cleanup after allowlist tightening.
services/​src/​main/​java/​org/​keycloak/​protocol/​oauth2/​cimd/​clientpolicy/​executor/​AbstractClientIdMetadataDocumentExecutor.java Reconciles CIMD audience mappers during authorization.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 16, 2026 04:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot AI balanced review requested due to automatic review settings November 16, 2026 05:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot AI balanced review requested due to automatic review settings November 16, 2026 06:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

…ning

closes keycloak#55131

Signed-off-by: Takashi Norimatsu <takashi.norimatsu.ws@hitachi.com>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 08:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +104 to 120
if (configuration == null || clientId == null || configuration.getClientIdUriSchemes() == null || configuration.getClientIdUriSchemes().isEmpty()) {
return false;
}
final URI uri;
try {
uri = new URI(clientId);
} catch (URISyntaxException e) {
return false;
}
if (configuration.getClientIdUriSchemes().stream().noneMatch(i -> i.equals(uri.getScheme())) || uri.getHost() == null) {
return false;
}
return convertContentFilledList(configuration.getTrustedDomains()).stream().anyMatch(i -> checkTrustedDomain(uri.getHost(), i));
}

private boolean isUriSchemeMatched(URI uri) {
return configuration.getClientIdUriSchemes().stream().anyMatch(i->i.equals(uri.getScheme()));
Comment on lines +394 to +397
// before the current session loads the client, and before any check that might fail and roll back the current
// transaction, remove the audience mappers whose resource is no longer allow-listed, regardless of whether the
// request includes the resource parameter.
removeStaleResourceIndicatorAudienceMappersInNewTransaction(clientId);
Comment on lines +1122 to +1132
Map<String, List<List<String>>> allowListsByProfile = new HashMap<>();
Stream.concat(nullSafe(profiles.getProfiles()), nullSafe(profiles.getGlobalProfiles())).forEach(profile -> {
List<List<String>> allowLists = nullSafe(profile.getExecutors())
.filter(e -> executorProviderId.equals(e.getExecutorProviderId()))
.map(e -> (Configuration) JsonSerialization.mapper.convertValue(RawJsonValue.unwrap(JsonNode.class, e.getConfiguration()), configurationClass))
// an executor without configuration allows nothing.
.map(c -> c == null ? Collections.<String>emptyList() : nullSafe(c.getResourceIndicatorAllowList())
.filter(Objects::nonNull).filter(i -> !i.isBlank()).distinct().toList())
.toList();
allowListsByProfile.merge(profile.getName(), allowLists, (a, b) -> Stream.concat(a.stream(), b.stream()).toList());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CIMD] Stale resource audience mapper persists after allowlist tightening

2 participants