Skip to content

Enforce membership permission when creating users - #51458

Open
pedroigor wants to merge 1 commit into
keycloak:mainfrom
pedroigor:issue-51378
Open

Enforce membership permission when creating users#51458
pedroigor wants to merge 1 commit into
keycloak:mainfrom
pedroigor:issue-51378

Conversation

@pedroigor

Copy link
Copy Markdown
Contributor

Closes #51378

Copilot AI balanced review requested due to automatic review settings August 5, 2026 13:24
@pedroigor
pedroigor requested a review from a team as a code owner August 5, 2026 13:24

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.

Pull request overview

Enforces FGAP V2 group membership permissions during user creation, addressing CVE-2026-18571.

Changes:

  • Validates MANAGE_MEMBERSHIP before assigning each requested group.
  • Adds a customizable group membership handler.
  • Adds integration coverage for permitted, unpermitted, and mixed assignments.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
UsersResource.java Enforces group membership authorization.
RepresentationToModel.java Adds the membership-handler overload.
UserResourceTypeEvaluationTest.java Tests authorization during user creation.

Closes keycloak#51378

Signed-off-by: Pedro Igor <pigor.craveiro@gmail.com>
Copilot AI review requested due to automatic review settings August 6, 2026 18:57

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (3)

tests/base/src/test/java/org/keycloak/tests/admin/authz/fgap/UserResourceTypeEvaluationTest.java:526

  • search(\"myadmin\").get(0) assumes the first hit is the intended user and that ordering is stable. To avoid nondeterministic failures, select the exact match (e.g., filter by getUsername().equals(\"myadmin\")) and assert it exists uniquely before using getId().
        UserRepresentation myadmin = realm.admin().users().search("myadmin").get(0);
        UserPolicyRepresentation allowMyAdminPermission = createUserPolicy(realm, adminPermissionsClient, "Only My Admin User Policy", myadmin.getId());

tests/base/src/test/java/org/keycloak/tests/admin/authz/fgap/UserResourceTypeEvaluationTest.java:534

  • The test creates two groups but doesn’t register cleanup for them, which can leak state across test runs and make failures harder to debug. Add cleanup entries to delete permittedGroup / unpermittedGroup at the end of the test (similar to the user deletions).
        GroupRepresentation permittedGroup = createGroup("permitted-group");
        GroupRepresentation unpermittedGroup = createGroup("unpermitted-group");

server-spi-private/src/main/java/org/keycloak/models/utils/RepresentationToModel.java:809

  • The new overload makes group assignment dependent on the provided membershipHandler, but this isn’t obvious from the signature and is easy to misuse (e.g., passing a permission-check-only consumer and unintentionally skipping joinGroup). Consider adding Javadoc that explicitly states the consumer must perform the membership operation, or adjust the API to separate 'authorize' from 'join' to prevent accidental no-op group assignment.
    public static void createGroups(KeycloakSession session, UserRepresentation userRep, RealmModel newRealm, UserModel user) {
        createGroups(session, userRep, newRealm, user, user::joinGroup);
    }

    public static void createGroups(KeycloakSession session, UserRepresentation userRep, RealmModel newRealm, UserModel user, Consumer<GroupModel> membershipHandler) {
        Objects.requireNonNull(membershipHandler, "membershipHandler must not be null");

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-18571] FGAP V2: Group assignment bypass during user creation (POST /users) allows adding unpermitted groups

3 participants