Repository navigation
Conversation
…e Account API
PUT /account/resources/{id}/permissions created granted permission
tickets without checking that the resource has owner-managed access
enabled, and accepted any scope of the resource server, including
scopes not assigned to the shared resource. The Protection API
permission ticket endpoint performs both checks.
Reject such requests with 400 before any ticket is changed.
Closes keycloak#55381
Signed-off-by: ccsosd <308679821+ccsosd@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Previously granted invalid tickets remain trusted by UMA, leaving existing deployments at risk and requiring security maintainers to assess remediation and rollout guidance before release.
No open issues 🎉
What changed in this PR
This PR hardens Account API resource sharing to match the Protection API’s owner-managed access and resource-scope checks, addressing #55381.
Changes:
- Rejects sharing when owner-managed access is disabled.
- Validates all requested scopes against the resource before changing permission tickets.
- Adds regression tests for invalid scopes and disabled owner-managed access, while checking that valid sharing still succeeds.
| File | Description |
|---|---|
tests/base/src/test/java/org/keycloak/tests/account/ResourcesRestServiceTest.java |
Adds sharing validation tests and verifies rejected requests leave no tickets. |
services/src/main/java/org/keycloak/services/resources/account/resources/ResourceService.java |
Enforces owner-managed access and validates resource scopes before ticket changes. |
Review effort: Balanced
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 #55381
Summary
The Account API sharing endpoint
PUT /realms/{realm}/account/resources/{id}/permissionscreates already-granted permission tickets without the two checks the Protection API applies to the same operation:This PR adds both checks to the Account API and validates every requested scope before any ticket is created or removed.
Vulnerability chain
Line numbers refer to
main@317dc60618. EP = entry point, CO = critical operation; B = condition contrasts, N = behaviour that must keep working, Q = what was actually observed.At a glance: 1 path · 2 condition contrasts · 3 normal behaviours · 2 observations
What goes wrong
ResourceService.revoke()(the PUT handler) only requiresmanage-accountand that the caller owns the resource. It resolves each scope withgetScope(scopeId, resourceServer), which looks the scope up on the resource server, and passes it toticketStore.create(...)with a granted timestamp. No check ties the scope to the resource, andisOwnerManagedAccess()is never consulted. A ticketless UMA request from the requesting party then treats the granted ticket as authoritative and can return an RPT with a resource/scope pair that the resource definition does not allow.Where it happens: EP → Trace → CO
services/.../account/resources/ResourceService.java:144public Response revoke(List<Permission> permissions)PUT /account/resources/{id}/permissions, used by the Account Console "Share" dialogResourcesService.java:148if (!resource.getOwner().equals(user.getId()))ResourceService.java:172,:230getScope(scopeId, resourceServer)ResourceService.java:231ticketStore.create(resourceServer, resource, scope, user.getId())+setGrantedTimestampauthorization/protection/permission/PermissionTicketService.java:91,:116resource.isOwnerManagedAccess(),resource.getScopes().contains(scope)How conditions change the outcome
main204 and a granted ticket; after the fix 400invalid_scope, no ticketmain204 and a granted ticket; after the fix 400invalid_permissions, no ticketBehaviour that must keep working
ResourcesRestServiceTestcases).failShareResourceInvalidPermissions,testShareResourceRejectsAmbiguousUsernameEmail).What was observed
testShareResourceRejectsScopeNotOnResourceandtestShareResourceRejectsWhenOwnerManagedAccessDisabledfail withexpected: <400> but was: <204>.ResourcesRestServiceTestpass, including the two new ones, which also assert that no ticket exists after a rejected request.The fix
In
ResourceService(Account API):revoke()throwsBadRequestException("invalid_permissions")when!resource.isOwnerManagedAccess().getResourceScope(scopeId)resolves the scope as before and throwsBadRequestException("invalid_scope")when it is null or not inresource.getScopes().getResourceScopebefore any ticket is created or deleted. The grant path (grantPermission) and the update loop use it too.Compatibility
Clients that shared resources without owner-managed access, or with scopes not assigned to the resource, now get 400 instead of 204. Both are cases the Account Console does not offer, and the Protection API already rejects them. Existing tickets are not touched.
Test Plan
tests/base/.../account/ResourcesRestServiceTest.java:testShareResourceRejectsScopeNotOnResourceandtestShareResourceRejectsWhenOwnerManagedAccessDisabled.mvn -pl tests/base test -Dtest=ResourcesRestServiceTest: 27/27 ✅ with the fix; the 2 new tests fail on unmodifiedmain(400 expected, 204 returned).Not covered
ResourcesRestServiceTestwas run, not the full test suite.If the "Vulnerability chain" section helped (or didn't) when reviewing this PR, a quick comment or 👍 / 👎 would mean a lot. I'm trying to make security fix descriptions more useful for maintainers.