8000 Validate owner-managed access and resource scopes when sharing via the Account API by ccsosd · Pull Request #55506 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Validate owner-managed access and resource scopes when sharing via the Account API - #55506

Open
ccsosd wants to merge 1 commit into
keycloak:mainfrom
ccsosd:fix/account-share-scope-check-55381
Open

ccsosd wants to merge 1 commit into
keycloak:mainfrom
ccsosd:fix/account-share-scope-check-55381

Conversation

@ccsosd
@ccsosd ccsosd commented Nov 25, 2026
Copy link
Copy Markdown

Closes #55381

Summary

The Account API sharing endpoint PUT /realms/{realm}/account/resources/{id}/permissions creates already-granted permission tickets without the two checks the Protection API applies to the same operation:

  1. The resource must have owner-managed access enabled.
  2. Each scope must be assigned to the resource, not just defined somewhere on the resource server.

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 requires manage-account and that the caller owns the resource. It resolves each scope with getScope(scopeId, resourceServer), which looks the scope up on the resource server, and passes it to ticketStore.create(...) with a granted timestamp. No check ties the scope to the resource, and isOwnerManagedAccess() 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

Role Location Code Why it matters
EP services/.../account/resources/ResourceService.java:144 public Response revoke(List<Permission> permissions) PUT /account/resources/{id}/permissions, used by the Account Console "Share" dialog
Trace ResourcesService.java:148 if (!resource.getOwner().equals(user.getId())) Ownership is the only resource-level check
Trace: root cause ResourceService.java:172, :230 getScope(scopeId, resourceServer) Any scope of the resource server is accepted; owner-managed access is not checked
CO ResourceService.java:231 ticketStore.create(resourceServer, resource, scope, user.getId()) + setGrantedTimestamp Granted ticket persisted for the requester
Reference authorization/protection/permission/PermissionTicketService.java:91, :116 resource.isOwnerManagedAccess(), resource.getScopes().contains(scope) Protection API enforces both for the same operation

How conditions change the outcome

Should be allowed Should be denied Observed
B1 Scope vs. resource Scope assigned to the resource → 204, ticket granted Scope only defined on the resource server (or unknown) → on main 204 and a granted ticket; after the fix 400 invalid_scope, no ticket Q1 / Q2
B2 Owner-managed access Enabled → sharing works Disabled → on main 204 and a granted ticket; after the fix 400 invalid_permissions, no ticket Q1 / Q2

Behaviour that must keep working

  • N1 Sharing a resource's own scopes with a user, and updating or revoking existing shares, behaves as before (existing ResourcesRestServiceTest cases).
  • N2 Invalid or ambiguous users still get the existing errors (failShareResourceInvalidPermissions, testShareResourceRejectsAmbiguousUsernameEmail).
  • N3 A request 8000 that mixes a valid and an invalid scope is rejected as a whole. Scopes are validated before any ticket changes, so no partial grant is left behind.

What was observed

  • Q1, before the fix: testShareResourceRejectsScopeNotOnResource and testShareResourceRejectsWhenOwnerManagedAccessDisabled fail with expected: <400> but was: <204>.
  • Q2, after the fix: all 27 tests in ResourcesRestServiceTest pass, including the two new ones, which also assert that no ticket exists after a rejected request.

The fix

In ResourceService (Account API):

  • revoke() throws BadRequestException("invalid_permissions") when !resource.isOwnerManagedAccess().
  • New getResourceScope(scopeId) resolves the scope as before and throws BadRequestException("invalid_scope") when it is null or not in resource.getScopes().
  • All requested scopes are resolved through getResourceScope before 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

  • New tests in tests/base/.../account/ResourcesRestServiceTest.java: testShareResourceRejectsScopeNotOnResource and testShareResourceRejectsWhenOwnerManagedAccessDisabled.
  • mvn -pl tests/base test -Dtest=ResourcesRestServiceTest: 27/27 ✅ with the fix; the 2 new tests fail on unmodified main (400 expected, 204 returned).

Not covered

  • The UMA grant itself still trusts granted tickets without re-checking them against the resource definition. Tickets created before this fix through the Account API remain, and cleaning them up is left to the maintainers.
  • Only ResourcesRestServiceTest was 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.

…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>
@ccsosd
ccsosd requested a review from a team as a code owner November 25, 2026 08:26
Copilot AI balanced review requested due to automatic review settings November 25, 2026 08:26
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.

🔵 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CVE-2026-133226] Account resource sharing grants scopes outside the resource definition

2 participants

0