Repository navigation
Conversation
closes keycloak#47128 Signed-off-by: Takashi Norimatsu <takashi.norimatsu.ws@hitachi.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Several resource-handling paths can bypass audience restrictions and allow-list checks, potentially issuing unrestricted tokens.
11 open issues
Match PAR URI prefixes case-insensitively in resource checks · New Apply resource policy to verified request-object values · New Persist and enforce resources for device authorization requests · New Reject oversized resource sets instead of dropping audience restrictions · New Restrict repeated resources to grants that validate them · New Reject oversized multivalued resources instead of silently dropping them · New Enforce requested resources when building implicit and hybrid tokens · New Preserve resource constraints when rebuilding offline refresh context · New Bound the total serialized size of resource parameters · New Validate narrowed refresh resources against effective scopes · New Allow refresh tokens containing multiple resource URIs · New
What changed in this PR
Extends Keycloak’s experimental Resource Indicators support to accept multiple resource parameters, addressing #47128.
Changes:
- Parses multiple resource values and supports requesting subsets of previously granted resources.
- Extends Client ID Metadata Document allow-list checks and audience-mapper management.
- Adds integration coverage, test helpers, and documentation.
| File | Description |
|---|---|
tests/utils-shared/src/main/java/org/keycloak/testsuite/util/oauth/ParRequest.java |
Adds a resource parameter helper for pushed requests. |
tests/utils-shared/src/main/java/org/keycloak/testsuite/util/oauth/LoginUrlBuilder.java |
Builds login URLs with repeated resource parameters. |
tests/base/src/test/java/org/keycloak/tests/oauth/ResourceIndicatorsTest.java |
Covers multiple resources, subsets, refreshes, and pushed requests. |
tests/base/src/test/java/org/keycloak/tests/client/policies/ClientIdMetadataDocumentTest.java |
Tests multi-resource allow lists and audience-mapper updates. |
services/src/main/java/org/keycloak/protocol/oidc/resourceindicators/ResourceIndicatorsPostProcessor.java |
Resolves resource sets and restricts token audiences. |
services/src/main/java/org/keycloak/protocol/oidc/resourceindicators/ResourceIndicators.java |
Adds shared resource-set serialization and parsing. |
services/src/main/java/org/keycloak/protocol/oidc/par/endpoints/ParEndpoint.java |
Validates and preserves multiple pushed resource values. |
services/src/main/java/org/keycloak/protocol/oidc/grants/ResourceOwnerPasswordCredentialsGrantType.java |
Passes all requested resources into password-grant processing. |
services/src/main/java/org/keycloak/protocol/oidc/grants/RefreshTokenGrantType.java |
Collects multiple resources from refresh requests. |
services/src/main/java/org/keycloak/protocol/oidc/grants/OAuth2GrantTypeBase.java |
Allows repeated resources and propagates them during token issuance. |
services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthzEndpointRequestParser.java |
Applies parameter-length checks to individual resource values. |
services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthzEndpointRequestObjectParser.java |
Parses resource arrays from request objects. |
services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthzEndpointQueryStringParser.java |
Accepts repeated resources when the feature is enabled. |
services/src/main/java/org/keycloak/protocol/oidc/endpoints/AuthorizationEndpointChecker.java |
Validates every resource indicator. |
services/src/main/java/org/keycloak/protocol/oauth2/cimd/clientpolicy/executor/AbstractClientIdMetadataDocumentExecutor.java |
Checks resource sets and synchronizes managed audience mappers. |
docs/guides/securing-apps/mcp-authz-server.adoc |
Documents multiple resources, subsets, and allow-list behavior. |
docs/documentation/release_notes/topics/27_0_0.adoc |
Announces experimental multi-resource support. |
Review effort: Balanced
| } | ||
|
|
||
| String requestUri = preAuthorizationRequestContext.getRequestParameters().getFirst(OIDCLoginProtocol.REQUEST_URI_PARAM); | ||
| if (requestUri != null && requestUri.startsWith(ParEndpoint.REQUEST_URI_PREFIX)) { |
Comment on lines
+1004
to
+1006
| Map<String, String> pushedAuthorizationRequest = AuthzEndpointParParser.getRequestObject(session, requestUri); | ||
| Set<String> pushedResources = pushedAuthorizationRequest == null ? null | ||
| : ResourceIndicators.parse(pushedAuthorizationRequest.get(OAuth2Constants.RESOURCE)); |
Comment on lines
+67
to
+70
| if (!Profile.isFeatureEnabled(Profile.Feature.RESOURCE_INDICATORS)) { | ||
| checkDuplicated(requestParams, paramName); | ||
| } | ||
| return ResourceIndicators.join(requestParams.get(paramName)); |
Comment on lines
+238
to
+241
| int paramLength = OIDCLoginProtocol.RESOURCE_PARAM.equals(paramName) | ||
| ? ResourceIndicators.parse(paramValue).stream().mapToInt(String::length).max().orElse(0) | ||
| : paramValue.length(); | ||
| if (paramLength > maxLength) { |
Comment on lines
+107
to
+109
| public Set<String> getSupportedMultivaluedRequestParameters() { | ||
| // the resource parameter can be sent multiple times | ||
| return Profile.isFeatureEnabled(Profile.Feature.RESOURCE_INDICATORS) ? Set.of(OAuth2Constants.RESOURCE) : Collections.emptySet(); |
| public void process(TokenPostProcessorContext context) { | ||
| String requestedResource = context.clientSessionCtx().getAttribute(OAuth2Constants.RESOURCE, String.class); | ||
| if (requestedResource != null && !ResourceIndicatorValidation.isValidResourceIndicator(requestedResource)) { | ||
| Set<String> requestedResources = ResourceIndicators.parse(context.clientSessionCtx().getAttribute(OAuth2Constants.RESOURCE, String.class)); |
| originalResourceParamRequired = true; | ||
| } else if (OAuth2Constants.REFRESH_TOKEN.equals(grantType)) { | ||
| originalResourceParam = (String) context.requestRefreshToken().getOtherClaims().get(OAuth2Constants.RESOURCE); | ||
| originalResources = ResourceIndicators.parse((String) context.requestRefreshToken().getOtherClaims().get(OAuth2Constants.RESOURCE)); |
Comment on lines
+237
to
+240
| // the resource parameter can have multiple values, so the length of each value is checked | ||
| int paramLength = OIDCLoginProtocol.RESOURCE_PARAM.equals(paramName) | ||
| ? ResourceIndicators.parse(paramValue).stream().mapToInt(String::length).max().orElse(0) | ||
| : paramValue.length(); |
Comment on lines
+64
to
+67
| for (String grantedResource : grantedResources) { | ||
| String resolvedAudience = resolveAudience(grantedResource, audience); | ||
| if (resolvedAudience == null) { | ||
| throw new TokenInterceptorException(OAuthErrorException.INVALID_TARGET, ResourceIndicatorConstants.ERROR_INVALID_RESOURCE); |
Comment on lines
+74
to
+75
| if (context.refreshToken() != null) { | ||
| context.refreshToken().getOtherClaims().put(OAuth2Constants.RESOURCE, ResourceIndicators.join(grantedResources)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #47128